2016-05-04 19:51:58 +02:00
|
|
|
package cryptocore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2017-07-14 23:22:15 +02:00
|
|
|
|
|
|
|
"github.com/rfjakob/gocryptfs/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)
|
2017-03-05 21:59:55 +01:00
|
|
|
for _, useHKDF := range []bool{true, false} {
|
2017-07-14 23:22:15 +02:00
|
|
|
c := New(key, BackendGoGCM, 96, useHKDF, false)
|
2017-03-05 21:59:55 +01:00
|
|
|
if c.IVLen != 12 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
2017-04-08 02:09:28 +02:00
|
|
|
c = New(key, BackendGoGCM, 128, useHKDF, false)
|
2017-03-05 21:59:55 +01:00
|
|
|
if c.IVLen != 16 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
2017-07-14 23:22:15 +02:00
|
|
|
if stupidgcm.BuiltWithoutOpenssl {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
c = New(key, BackendOpenSSL, 128, useHKDF, false)
|
|
|
|
if c.IVLen != 16 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
2017-03-05 17:44:14 +01:00
|
|
|
}
|
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)
|
2017-04-08 02:09:28 +02:00
|
|
|
New(key, BackendOpenSSL, 128, true, false)
|
2016-05-04 19:51:58 +02:00
|
|
|
}
|