feat: v0.2.3, supports nonce is not 12 bytes
This commit is contained in:
21
src/lib.rs
21
src/lib.rs
@@ -446,3 +446,24 @@ fn test256_stream_and_array() {
|
||||
assert_eq!(ciphertext, encrypted);
|
||||
assert_eq!(plaintext, decrypted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test125_ab_nonce() {
|
||||
let key = hex::decode("faf6a891866fac550ef548b4e5f6fbc98fccc6827cd943cc8d7539747f1d87bd").unwrap();
|
||||
let key: [u8; 32] = key.try_into().map_err(|_| format!("Bad key length")).unwrap();
|
||||
let nonce = hex::decode("cea500817694e16e734f07df422f6f52582d844e623746a96c5fbb4be2a38a6e").unwrap();
|
||||
let ciphertext = hex::decode("c52dadf683c02e81d842f6563b").unwrap();
|
||||
let tag = hex::decode("cc9062944525de37d3aa588c6a5676a2").unwrap();
|
||||
let aad = b"firstName:";
|
||||
|
||||
let mut gcm_stream = Aes256GcmStreamDecryptor::new(key, &nonce);
|
||||
gcm_stream.init_adata(&aad[..]);
|
||||
let mut first_block = gcm_stream.update(&ciphertext);
|
||||
let second_block = gcm_stream.update(&tag);
|
||||
let final_block = gcm_stream.finalize().unwrap();
|
||||
|
||||
first_block.extend_from_slice(&second_block);
|
||||
first_block.extend_from_slice(&final_block);
|
||||
|
||||
assert_eq!("John --- TEST", String::from_utf8(first_block).unwrap());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user