Debian Codegraph @

debian/missing-sources/ecb/tests/aes.rs

raw
1 #[cfg(feature = "block-padding")]
2 #[cfg(test)]
3 mod tests {
4
5 #[test]
6 fn ecb_aes128() {
7 use aes::cipher::{block_padding::NoPadding, BlockDecryptMut, BlockEncryptMut, KeyInit};
8 use ecb::{Decryptor, Encryptor};
9
10 let key = include_bytes!("data/aes128.key.bin");
11 let plaintext = include_bytes!("data/aes128.plaintext.bin");
12 let ciphertext = include_bytes!("data/ecb-aes128.ciphertext.bin");
13
14 type Aes128EcbEnc = Encryptor<aes::Aes128>;
15 type Aes128EcbDec = Decryptor<aes::Aes128>;
16
17 let mut buf = *plaintext;
18 let pt_len = buf.len();
19
20 let mode = Aes128EcbEnc::new(key.into());
21
22 assert_eq!(
23 mode.encrypt_padded_mut::<NoPadding>(&mut buf, pt_len)
24 .unwrap(),
25 &ciphertext[..]
26 );
27
28 let mut buf = *ciphertext;
29 let mode = Aes128EcbDec::new(key.into());
30
31 assert_eq!(
32 mode.decrypt_padded_mut::<NoPadding>(&mut buf).unwrap(),
33 &plaintext[..]
34 );
35 }
36 }