Skip to content

Commit

Permalink
Add a test case for empty data in CBC (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
keepsimple1 committed May 27, 2023
1 parent 107d093 commit 7fe7208
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ fn nist_verify_aes_256_cfb_128() {
assert_eq!(decrypted[..], plaintext[..]);
}

#[test]
fn empty_data() {
// Encrypt an input that is empty, i.e. zero bytes.
let key_128 = b"This is the key!"; // key is 16 bytes
let cipher = Cipher::new_128(key_128);
let plaintext = b""; // less than 16 bytes
let iv = b"This is 16 bytes";
let encrypted_128 = cipher.cbc_encrypt(iv, plaintext);
assert_eq!(encrypted_128.len(), 16); // Verify padding
let decrypted_128 = cipher.cbc_decrypt(iv, &encrypted_128[..]);
assert_eq!(decrypted_128, plaintext);
}

#[test]
fn small_data() {
// Encrypt and decrypt data that is smaller than 1 AES block size.
Expand Down

0 comments on commit 7fe7208

Please sign in to comment.