(t *testing.T)
| 48 | } |
| 49 | |
| 50 | func TestEncryptAndDecrypt(t *testing.T) { |
| 51 | // Test our 2 cipher types |
| 52 | cipherInits := map[string]func([]byte) (Cipher, error){ |
| 53 | "CFB": NewCFBCipher, |
| 54 | "GCM": NewGCMCipher, |
| 55 | } |
| 56 | for name, initCipher := range cipherInits { |
| 57 | t.Run(name, func(t *testing.T) { |
| 58 | // Test all 3 valid AES sizes |
| 59 | for _, secretSize := range []int{16, 24, 32} { |
| 60 | t.Run(fmt.Sprintf("%d", secretSize), func(t *testing.T) { |
| 61 | secret := make([]byte, secretSize) |
| 62 | _, err := io.ReadFull(rand.Reader, secret) |
| 63 | assert.Equal(t, nil, err) |
| 64 | |
| 65 | // Test Standard & Base64 wrapped |
| 66 | cstd, err := initCipher(secret) |
| 67 | assert.Equal(t, nil, err) |
| 68 | |
| 69 | cb64 := NewBase64Cipher(cstd) |
| 70 | |
| 71 | ciphers := map[string]Cipher{ |
| 72 | "Standard": cstd, |
| 73 | "Base64": cb64, |
| 74 | } |
| 75 | |
| 76 | for cName, c := range ciphers { |
| 77 | t.Run(cName, func(t *testing.T) { |
| 78 | // Test various sizes sessions might be |
| 79 | for _, dataSize := range []int{10, 100, 1000, 5000, 10000} { |
| 80 | t.Run(fmt.Sprintf("%d", dataSize), func(t *testing.T) { |
| 81 | runEncryptAndDecrypt(t, c, dataSize) |
| 82 | }) |
| 83 | } |
| 84 | }) |
| 85 | } |
| 86 | }) |
| 87 | } |
| 88 | }) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | func runEncryptAndDecrypt(t *testing.T, c Cipher, dataSize int) { |
| 93 | data := make([]byte, dataSize) |
nothing calls this directly
no test coverage detected