in src/lib.rs [172:208]
fn test_e2e_with_different_record_sizes_and_padding() {
let (local_key, remote_key) = generate_keys().unwrap();
let plaintext = b"When I grow up, I want to be a watermelon";
let mut auth_secret = vec![0u8; 16];
let cryptographer = crypto::holder::get_cryptographer();
cryptographer.random_bytes(&mut auth_secret).unwrap();
let remote_public = cryptographer
.import_public_key(&remote_key.pub_as_raw().unwrap())
.unwrap();
let plen = plaintext.len();
// Try a variety of different record sizes. The numbers here aren't particularly deeply
// considered, just a selection of numbers that might be interesting. (Although they did
// trigger a bunch of interesting edge-cases during development, which is re-assuring).
for plaintext_rs in &[2, 3, 7, 8, plen - 1, plen, plen + 1, 1024, 8192] {
let rs = (*plaintext_rs + ECE_TAG_LENGTH) as u32;
// Try a variety of padding lengths. Again, not deeply considered numbers.
for pad_length in &[0, 1, 2, 8, 37, 127, 128] {
let pad_length = *pad_length;
let params = WebPushParams {
rs,
pad_length,
..WebPushParams::default()
};
let ciphertext = aes128gcm::encrypt(
&*local_key,
&*remote_public,
&auth_secret,
plaintext,
params,
)
.unwrap();
let decrypted =
aes128gcm::decrypt(&*remote_key, &auth_secret, &ciphertext).unwrap();
assert_eq!(decrypted, plaintext.to_vec());
}
}
}