diff options
author | Jakob Unterwurzacher | 2021-09-02 10:04:38 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2021-09-02 10:04:38 +0200 |
commit | 961b8ca438361b01f2f232d8735c236ef94b4d03 (patch) | |
tree | 12dff6f5da4846838974d85a4b6dc1fe7af6fbf7 /internal/stupidgcm/common_test.go | |
parent | 676a4ceb87e8c8e0811b4312ce4b3b74f53b4368 (diff) |
stupidgcm: deduplicate tests 2/2
Deduplicate the cipher setup that was identical
for all tests for each cipher.
Diffstat (limited to 'internal/stupidgcm/common_test.go')
-rw-r--r-- | internal/stupidgcm/common_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/stupidgcm/common_test.go b/internal/stupidgcm/common_test.go index 28f3308..27ca7cc 100644 --- a/internal/stupidgcm/common_test.go +++ b/internal/stupidgcm/common_test.go @@ -3,10 +3,20 @@ package stupidgcm import ( "bytes" "crypto/cipher" + "crypto/rand" "encoding/hex" + "log" "testing" ) +func testCiphers(t *testing.T, c1 cipher.AEAD, c2 cipher.AEAD) { + t.Run("testEncryptDecrypt", func(t *testing.T) { testEncryptDecrypt(t, c1, c2) }) + t.Run("testInplaceSeal", func(t *testing.T) { testInplaceSeal(t, c1, c2) }) + t.Run("testInplaceOpen", func(t *testing.T) { testInplaceOpen(t, c1, c2) }) + t.Run("testCorruption_c1", func(t *testing.T) { testCorruption(t, c1) }) + t.Run("testCorruption_c2", func(t *testing.T) { testCorruption(t, c2) }) +} + // testEncryptDecrypt encrypts and decrypts using both stupidgcm and Go's built-in // GCM implementation and verifies that the results are identical. func testEncryptDecrypt(t *testing.T, c1 cipher.AEAD, c2 cipher.AEAD) { @@ -150,3 +160,13 @@ func testCorruption(t *testing.T, c cipher.AEAD) { t.Fatalf("Should have gotten error") } } + +// Get "n" random bytes from /dev/urandom or panic +func randBytes(n int) []byte { + b := make([]byte, n) + _, err := rand.Read(b) + if err != nil { + log.Panic("Failed to read random bytes: " + err.Error()) + } + return b +} |