summaryrefslogtreecommitdiff
path: root/internal/cryptocore
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-05-04 19:51:58 +0200
committerJakob Unterwurzacher2016-05-04 19:56:07 +0200
commit1bb907b38e1fefdfb4ad66f1d423a607477deb3c (patch)
tree2656ae4d20b881e943726fd4fc841fe82255a0ec /internal/cryptocore
parentbb16f2d565674153bd7c3781e23048586c73e0a8 (diff)
cryptocore: add API tests
Diffstat (limited to 'internal/cryptocore')
-rw-r--r--internal/cryptocore/cryptocore.go (renamed from internal/cryptocore/crypto_api.go)1
-rw-r--r--internal/cryptocore/cryptocore_test.go35
2 files changed, 36 insertions, 0 deletions
diff --git a/internal/cryptocore/crypto_api.go b/internal/cryptocore/cryptocore.go
index 0db9bbb..f286896 100644
--- a/internal/cryptocore/crypto_api.go
+++ b/internal/cryptocore/cryptocore.go
@@ -18,6 +18,7 @@ type CryptoCore struct {
IVLen int
}
+// "New" returns a new CryptoCore object or panics.
func New(key []byte, useOpenssl bool, GCMIV128 bool) *CryptoCore {
if len(key) != KeyLen {
diff --git a/internal/cryptocore/cryptocore_test.go b/internal/cryptocore/cryptocore_test.go
new file mode 100644
index 0000000..fd6a300
--- /dev/null
+++ b/internal/cryptocore/cryptocore_test.go
@@ -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)
+}