cryptocore: add API tests
This commit is contained in:
parent
bb16f2d565
commit
1bb907b38e
|
@ -18,6 +18,7 @@ type CryptoCore struct {
|
||||||
IVLen int
|
IVLen int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "New" returns a new CryptoCore object or panics.
|
||||||
func New(key []byte, useOpenssl bool, GCMIV128 bool) *CryptoCore {
|
func New(key []byte, useOpenssl bool, GCMIV128 bool) *CryptoCore {
|
||||||
|
|
||||||
if len(key) != KeyLen {
|
if len(key) != KeyLen {
|
|
@ -0,0 +1,35 @@
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
c = New(key, false, true)
|
||||||
|
if c.IVLen != 16 {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// "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)
|
||||||
|
}
|
Loading…
Reference in New Issue