(t *testing.T, masterKey, contentID, payload []byte, samples map[string]string)
| 131 | } |
| 132 | |
| 133 | func verifyCiphertextSamples(t *testing.T, masterKey, contentID, payload []byte, samples map[string]string) { |
| 134 | t.Helper() |
| 135 | |
| 136 | for _, encryptionAlgo := range encryption.SupportedAlgorithms(true) { |
| 137 | enc, err := encryption.CreateEncryptor(parameters{encryptionAlgo, masterKey}) |
| 138 | if err != nil { |
| 139 | t.Fatal(err) |
| 140 | } |
| 141 | |
| 142 | ct := samples[encryptionAlgo] |
| 143 | if ct == "" { |
| 144 | func() { |
| 145 | var v gather.WriteBuffer |
| 146 | defer v.Close() |
| 147 | |
| 148 | require.NoError(t, enc.Encrypt(gather.FromSlice(payload), contentID, &v)) |
| 149 | |
| 150 | t.Errorf("missing ciphertext sample for %q: %q,", encryptionAlgo, hex.EncodeToString(payload)) |
| 151 | }() |
| 152 | } else { |
| 153 | b, err := hex.DecodeString(ct) |
| 154 | if err != nil { |
| 155 | t.Errorf("invalid ciphertext for %v: %v", encryptionAlgo, err) |
| 156 | continue |
| 157 | } |
| 158 | |
| 159 | func() { |
| 160 | var plainText gather.WriteBuffer |
| 161 | defer plainText.Close() |
| 162 | |
| 163 | require.NoError(t, enc.Decrypt(gather.FromSlice(b), contentID, &plainText)) |
| 164 | |
| 165 | if v := plainText.ToByteSlice(); !bytes.Equal(v, payload) { |
| 166 | t.Errorf("invalid plaintext after decryption %x, want %x", v, payload) |
| 167 | } |
| 168 | }() |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | func BenchmarkEncryption(b *testing.B) { |
| 174 | masterKey := make([]byte, 32) |
no test coverage detected