From 83b7eb65b0c8ea3d07fe3e69f6a15f11e554485c Mon Sep 17 00:00:00 2001 From: Kim Tore Jensen Date: Fri, 20 Aug 2021 13:09:29 +0200 Subject: [PATCH] fix crypt tests --- pkg/cryptutil/encrypt_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/cryptutil/encrypt_test.go b/pkg/cryptutil/encrypt_test.go index 64d2520..3986d7c 100644 --- a/pkg/cryptutil/encrypt_test.go +++ b/pkg/cryptutil/encrypt_test.go @@ -2,7 +2,7 @@ package cryptutil_test import ( "crypto/rand" - "github.com/nais/naisplater/pkg/cryptutil" + "github.com/nais/wonderwall/pkg/cryptutil" "testing" "github.com/stretchr/testify/assert" @@ -32,8 +32,10 @@ func TestEncrypt(t *testing.T) { var cur, prev []byte var err error + crypter := cryptutil.New(key) + for i := ivIterations; i != 0; i-- { - cur, err = cryptutil.Encrypt(plaintext, key) + cur, err = crypter.Encrypt(plaintext) assert.Nil(t, err) assert.NotNil(t, cur) assert.NotEqual(t, prev, cur, "IV re-used") @@ -44,16 +46,20 @@ func TestEncrypt(t *testing.T) { // Test that encrypted messages can be decrypted. func TestDecrypt(t *testing.T) { - ciphertext, err := cryptutil.Encrypt(plaintext, key) + crypter := cryptutil.New(key) + + ciphertext, err := crypter.Encrypt(plaintext) assert.Nil(t, err) - decrypted, err := cryptutil.Decrypt(ciphertext, key) + decrypted, err := crypter.Decrypt(ciphertext) assert.Nil(t, err) assert.Equal(t, plaintext, decrypted) } func BenchmarkEncrypt(b *testing.B) { + crypter := cryptutil.New(key) + for n := 0; n < b.N; n++ { - cryptutil.Encrypt(plaintext, key) + crypter.Encrypt(plaintext) } }