From 961b8ca438361b01f2f232d8735c236ef94b4d03 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 2 Sep 2021 10:04:38 +0200 Subject: stupidgcm: deduplicate tests 2/2 Deduplicate the cipher setup that was identical for all tests for each cipher. --- internal/stupidgcm/stupidchacha_test.go | 43 ++------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) (limited to 'internal/stupidgcm/stupidchacha_test.go') diff --git a/internal/stupidgcm/stupidchacha_test.go b/internal/stupidgcm/stupidchacha_test.go index c1086d1..2690f85 100644 --- a/internal/stupidgcm/stupidchacha_test.go +++ b/internal/stupidgcm/stupidchacha_test.go @@ -11,9 +11,7 @@ import ( "golang.org/x/crypto/chacha20poly1305" ) -// TestEncryptDecrypt encrypts and decrypts using both stupidgcm and Go's built-in -// GCM implementation and verifies that the results are identical. -func TestEncryptDecryptChacha(t *testing.T) { +func TestStupidChacha20poly1305(t *testing.T) { key := randBytes(32) c := newChacha20poly1305(key) ref, err := chacha20poly1305.New(key) @@ -21,42 +19,5 @@ func TestEncryptDecryptChacha(t *testing.T) { t.Fatal(err) } - testEncryptDecrypt(t, c, ref) -} - -// Seal re-uses the "dst" buffer it is large enough. -// Check that this works correctly by testing different "dst" capacities from -// 5000 to 16 and "in" lengths from 1 to 5000. -func TestInplaceSealChacha(t *testing.T) { - key := randBytes(32) - c := newChacha20poly1305(key) - ref, err := chacha20poly1305.New(key) - if err != nil { - t.Fatal(err) - } - - testInplaceSeal(t, c, ref) -} - -// Open re-uses the "dst" buffer it is large enough. -// Check that this works correctly by testing different "dst" capacities from -// 5000 to 16 and "in" lengths from 1 to 5000. -func TestInplaceOpenChacha(t *testing.T) { - key := randBytes(32) - c := newChacha20poly1305(key) - ref, err := chacha20poly1305.New(key) - if err != nil { - t.Fatal(err) - } - - testInplaceOpen(t, c, ref) -} - -// TestCorruption verifies that changes in the ciphertext result in a decryption -// error -func TestCorruptionChacha(t *testing.T) { - key := randBytes(32) - c := newChacha20poly1305(key) - - testCorruption(t, c) + testCiphers(t, c, ref) } -- cgit v1.2.3