diff --git a/crypto/src/encryption/chacha20poly1305.rs b/crypto/src/encryption/chacha20poly1305.rs index 7ee0905eb71..5def1a5932a 100644 --- a/crypto/src/encryption/chacha20poly1305.rs +++ b/crypto/src/encryption/chacha20poly1305.rs @@ -68,12 +68,9 @@ mod tests { let cipher = ChaCha20Poly1305::new(&ChaCha20Poly1305::key_gen().unwrap()); let aad = Vec::new(); let message = b"Hello and Goodbye!".to_vec(); - let res = cipher.encrypt_easy(&aad, &message); - assert!(res.is_ok()); - let ciphertext = res.unwrap(); - let res = cipher.decrypt_easy(&aad, &ciphertext); - assert!(res.is_ok()); - assert_eq!(message, res.unwrap()); + let ciphertext = cipher.encrypt_easy(&aad, &message).unwrap(); + let decrypted_message = cipher.decrypt_easy(&aad, &ciphertext).unwrap(); + assert_eq!(message, decrypted_message); } #[test] @@ -86,16 +83,13 @@ mod tests { msg: message.as_slice(), aad: aad.as_slice(), }; - let res = cipher.encrypt(&nonce, payload); - assert!(res.is_ok()); - let ciphertext = res.unwrap(); + let ciphertext = cipher.encrypt(&nonce, payload).unwrap(); let payload = Payload { msg: ciphertext.as_slice(), aad: aad.as_slice(), }; - let res = cipher.decrypt(&nonce, payload); - assert!(res.is_ok()); - assert_eq!(message, res.unwrap()); + let decrypted_message = cipher.decrypt(&nonce, payload).unwrap(); + assert_eq!(message, decrypted_message); } #[test] @@ -104,17 +98,14 @@ mod tests { let aad = b"decrypt should fail".to_vec(); let message = b"Hello and Goodbye!".to_vec(); let res = cipher.encrypt_easy(&aad, &message); - assert!(res.is_ok()); let mut ciphertext = res.unwrap(); let aad = b"decrypt should succeed".to_vec(); - let res = cipher.decrypt_easy(&aad, &ciphertext); - assert!(res.is_err()); + cipher.decrypt_easy(&aad, &ciphertext).unwrap_err(); let aad = b"decrypt should fail".to_vec(); ciphertext[0] ^= ciphertext[1]; - let res = cipher.decrypt_easy(&aad, &ciphertext); - assert!(res.is_err()); + cipher.decrypt_easy(&aad, &ciphertext).unwrap_err(); } // TODO: this should be tested for, but only after we integrate with secrecy/zeroize diff --git a/crypto/src/encryption/mod.rs b/crypto/src/encryption/mod.rs index efe17062662..d72deacc7fb 100644 --- a/crypto/src/encryption/mod.rs +++ b/crypto/src/encryption/mod.rs @@ -73,7 +73,6 @@ fn random_bytes>() -> Result, Error> { /// /// let ciphertext = res.unwrap(); /// let res = encryptor.decrypt_easy(aad.as_ref(), ciphertext.as_slice()); -/// assert!(res.is_ok()); /// assert_eq!(res.unwrap().as_slice(), message); /// ``` #[derive(Debug, Clone)] diff --git a/crypto/src/kex/x25519.rs b/crypto/src/kex/x25519.rs index ee6b9ca98cd..63e5c7f6325 100644 --- a/crypto/src/kex/x25519.rs +++ b/crypto/src/kex/x25519.rs @@ -81,18 +81,16 @@ mod tests { #[test] fn key_exchange() { let scheme = X25519Sha256::new(); - let res = scheme.keypair(None); - assert!(res.is_ok()); - let (public_key1, secret_key1) = res.unwrap(); + let (public_key1, secret_key1) = scheme.keypair(None).unwrap(); let _res = scheme.compute_shared_secret(&secret_key1, &public_key1); let res = scheme.keypair(None); let (public_key2, secret_key2) = res.unwrap(); let _res = scheme.compute_shared_secret(&secret_key2, &public_key1); let _res = scheme.compute_shared_secret(&secret_key1, &public_key2); - let res = scheme.keypair(Some(KeyGenOption::FromPrivateKey(secret_key1))); - assert!(res.is_ok()); - let (public_key2, secret_key1) = res.unwrap(); + let (public_key2, secret_key1) = scheme + .keypair(Some(KeyGenOption::FromPrivateKey(secret_key1))) + .unwrap(); assert_eq!(public_key2, public_key1); assert_eq!(secret_key1, secret_key1); } diff --git a/p2p/tests/integration/p2p.rs b/p2p/tests/integration/p2p.rs index 33e7f6952d9..07b567b94b0 100644 --- a/p2p/tests/integration/p2p.rs +++ b/p2p/tests/integration/p2p.rs @@ -364,11 +364,11 @@ fn test_encryption() { let encryptor = SymmetricEncryptor::::new_with_key(TEST_KEY); let message = b"Some ciphertext"; let aad = b"Iroha2 AAD"; - let res = encryptor.encrypt_easy(aad.as_ref(), message.as_ref()); - assert!(res.is_ok()); - - let ciphertext = res.unwrap(); - let res_cipher = encryptor.decrypt_easy(aad.as_ref(), ciphertext.as_slice()); - assert!(res_cipher.is_ok()); - assert_eq!(res_cipher.unwrap().as_slice(), message); + let ciphertext = encryptor + .encrypt_easy(aad.as_ref(), message.as_ref()) + .unwrap(); + let decrypted = encryptor + .decrypt_easy(aad.as_ref(), ciphertext.as_slice()) + .unwrap(); + assert_eq!(decrypted.as_slice(), message); }