libgocryptfs/internal/cryptocore/cryptocore_test.go

42 lines
812 B
Go
Raw Normal View History

2016-05-04 19:51:58 +02:00
package cryptocore
import (
"testing"
"github.com/rfjakob/gocryptfs/v2/internal/stupidgcm"
2016-05-04 19:51:58 +02:00
)
2016-09-20 21:58:04 +02:00
// "New" should accept at least these param combinations
2016-05-04 19:51:58 +02:00
func TestCryptoCoreNew(t *testing.T) {
key := make([]byte, 32)
for _, useHKDF := range []bool{true, false} {
c := New(key, BackendGoGCM, 96, useHKDF)
if c.IVLen != 12 {
t.Fail()
}
c = New(key, BackendGoGCM, 128, useHKDF)
if c.IVLen != 16 {
t.Fail()
}
if stupidgcm.BuiltWithoutOpenssl {
continue
}
c = New(key, BackendOpenSSL, 128, useHKDF)
if c.IVLen != 16 {
t.Fail()
}
}
2016-05-04 19:51:58 +02:00
}
// "New" should panic on any key not 32 bytes long
func TestNewPanic(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
key := make([]byte, 16)
New(key, BackendOpenSSL, 128, true)
2016-05-04 19:51:58 +02:00
}