croc/src/crypt/crypt_test.go

33 lines
696 B
Go
Raw Normal View History

2018-09-24 15:13:43 +02:00
package crypt
import (
"testing"
2018-09-24 15:13:43 +02:00
"github.com/stretchr/testify/assert"
)
func BenchmarkEncryptionNew(b *testing.B) {
2018-09-24 15:13:43 +02:00
for i := 0; i < b.N; i++ {
bob, _ := New([]byte("password"), nil)
bob.Encrypt([]byte("hello, world"))
}
}
2018-09-24 15:13:43 +02:00
func BenchmarkEncryption(b *testing.B) {
bob, _ := New([]byte("password"), nil)
for i := 0; i < b.N; i++ {
bob.Encrypt([]byte("hello, world"))
2018-09-24 15:13:43 +02:00
}
}
func TestEncryption(t *testing.T) {
bob, err := New([]byte("password"), nil)
assert.Nil(t, err)
jane, err := New([]byte("password"), bob.Salt)
assert.Nil(t, err)
enc := bob.Encrypt([]byte("hello, world"))
dec, err := jane.Decrypt(enc)
assert.Nil(t, err)
assert.Equal(t, dec, []byte("hello, world"))
}