2016-05-04 19:51:58 +02:00
|
|
|
package cryptocore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// "New" should accept all param combinations
|
|
|
|
func TestCryptoCoreNew(t *testing.T) {
|
|
|
|
key := make([]byte, 32)
|
|
|
|
|
|
|
|
c := New(key, true, true)
|
|
|
|
if c.IVLen != 16 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
c = New(key, true, false)
|
|
|
|
if c.IVLen != 12 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
2016-05-04 22:10:06 +02:00
|
|
|
c = New(key, false, false)
|
|
|
|
if c.IVLen != 12 {
|
2016-05-04 19:51:58 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
2016-05-04 22:10:06 +02:00
|
|
|
// "New(key, false, true)" is tested for Go 1.4 and 1.5+ seperately
|
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, true, true)
|
|
|
|
}
|