From a1835845413e47590ae9c6211ac0cb5d732be5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 18 Sep 2020 17:49:44 +0200 Subject: [PATCH] crypto: Test that we correctly check the hash when decrypting attachments. --- matrix_sdk_crypto/src/file_encryption/attachments.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/matrix_sdk_crypto/src/file_encryption/attachments.rs b/matrix_sdk_crypto/src/file_encryption/attachments.rs index b6636d68..9fbaa6ff 100644 --- a/matrix_sdk_crypto/src/file_encryption/attachments.rs +++ b/matrix_sdk_crypto/src/file_encryption/attachments.rs @@ -333,4 +333,15 @@ mod test { assert_eq!("It's a secret to everybody", decrypted); } + + #[test] + fn decrypt_invalid_hash() { + let mut cursor = Cursor::new("fake message"); + let key = example_key(); + + let mut decryptor = AttachmentDecryptor::new(&mut cursor, key).unwrap(); + let mut decrypted_data = Vec::new(); + + assert!(decryptor.read_to_end(&mut decrypted_data).is_err()) + } }