(t *testing.T, c Cipher, dataSize int)
| 90 | } |
| 91 | |
| 92 | func runEncryptAndDecrypt(t *testing.T, c Cipher, dataSize int) { |
| 93 | data := make([]byte, dataSize) |
| 94 | _, err := io.ReadFull(rand.Reader, data) |
| 95 | assert.Equal(t, nil, err) |
| 96 | |
| 97 | // Ensure our Encrypt function doesn't encrypt in place |
| 98 | immutableData := make([]byte, len(data)) |
| 99 | copy(immutableData, data) |
| 100 | |
| 101 | encrypted, err := c.Encrypt(data) |
| 102 | assert.Equal(t, nil, err) |
| 103 | assert.NotEqual(t, encrypted, data) |
| 104 | // Encrypt didn't operate in-place on []byte |
| 105 | assert.Equal(t, data, immutableData) |
| 106 | |
| 107 | // Ensure our Decrypt function doesn't decrypt in place |
| 108 | immutableEnc := make([]byte, len(encrypted)) |
| 109 | copy(immutableEnc, encrypted) |
| 110 | |
| 111 | decrypted, err := c.Decrypt(encrypted) |
| 112 | assert.Equal(t, nil, err) |
| 113 | // Original data back |
| 114 | assert.Equal(t, data, decrypted) |
| 115 | // Decrypt didn't operate in-place on []byte |
| 116 | assert.Equal(t, encrypted, immutableEnc) |
| 117 | // Encrypt/Decrypt actually did something |
| 118 | assert.NotEqual(t, encrypted, decrypted) |
| 119 | } |
| 120 | |
| 121 | func TestDecryptCFBWrongSecret(t *testing.T) { |
| 122 | secret1 := []byte("0123456789abcdefghijklmnopqrstuv") |
no test coverage detected