|
@@ -70,8 +70,9 @@ fn decrypt_in_place(_ciphertext: &mut [u8], _key: &Key) -> Result<()> {
|
|
|
unimplemented!();
|
|
|
}
|
|
|
|
|
|
+/// Tests that validate the dependencies of this module.
|
|
|
#[cfg(test)]
|
|
|
-mod tests {
|
|
|
+mod dependency_tests {
|
|
|
use super::*;
|
|
|
|
|
|
static KEY: [u8; 32] = [
|
|
@@ -80,31 +81,44 @@ mod tests {
|
|
|
0x85, 0x48,
|
|
|
];
|
|
|
|
|
|
+ static IV: [u8; 16] = [
|
|
|
+ 0x60, 0xE0, 0xBE, 0x45, 0xA9, 0xAB, 0x5D, 0x99, 0x3B, 0x3A, 0x1E, 0x54, 0x18, 0xE0, 0x46,
|
|
|
+ 0xDE,
|
|
|
+ ];
|
|
|
+
|
|
|
+ /// This test validates that data decrypted with the `Crypter` API matches data that was
|
|
|
+ /// previously encrypted using it.
|
|
|
#[test]
|
|
|
fn cryptor() {
|
|
|
- let expected = b"We attack at the crack of noon.";
|
|
|
+ let expected = b"We attack at the crack of noon!";
|
|
|
|
|
|
let cipher = Cipher::aes_256_cbc();
|
|
|
let mut encrypter = Crypter::new(
|
|
|
cipher,
|
|
|
Mode::Encrypt,
|
|
|
&KEY,
|
|
|
- Some(&KEY)).unwrap();
|
|
|
+ Some(&IV)).unwrap();
|
|
|
let mut ciphertext = vec![0; expected.len() + cipher.block_size()];
|
|
|
let mut written = encrypter.update(expected.as_slice(), &mut ciphertext).unwrap();
|
|
|
written += encrypter.finalize(&mut ciphertext[written..]).unwrap();
|
|
|
ciphertext.truncate(written);
|
|
|
|
|
|
- let mut actual = vec![0u8; expected.len() + cipher.block_size()];
|
|
|
+ let mut actual = vec![0u8; ciphertext.len() + cipher.block_size()];
|
|
|
let mut decrypter = Crypter::new(
|
|
|
cipher,
|
|
|
Mode::Decrypt,
|
|
|
&KEY,
|
|
|
- Some(&KEY)).unwrap();
|
|
|
+ Some(&IV)).unwrap();
|
|
|
let mut written = decrypter.update(&ciphertext, &mut actual).unwrap();
|
|
|
written += decrypter.finalize(&mut actual[written..]).unwrap();
|
|
|
actual.truncate(written);
|
|
|
|
|
|
assert_eq!(expected, actual.as_slice());
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+/// Tests for the code that is actually in this module.
|
|
|
+#[cfg(test)]
|
|
|
+mod tests {
|
|
|
+
|
|
|
}
|