From cf048dd4e430b5640e9e77ee88a1c1e149bbbca9 Mon Sep 17 00:00:00 2001 From: Danny McClanahan <1305167+cosmicexplorer@users.noreply.github.com> Date: Mon, 4 Oct 2021 15:23:33 -0400 Subject: [PATCH] final review comments --- rust/protocol/src/sealed_sender.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/rust/protocol/src/sealed_sender.rs b/rust/protocol/src/sealed_sender.rs index b7bb79f404..782672de77 100644 --- a/rust/protocol/src/sealed_sender.rs +++ b/rust/protocol/src/sealed_sender.rs @@ -754,8 +754,7 @@ mod sealed_sender_v1 { &recipient_eph_keys.cipher_key, &recipient_eph_keys.mac_key, )?; - let sender_public_key: PublicKey = - PublicKey::try_from(recipient_message_key_bytes.as_ref())?; + let sender_public_key: PublicKey = PublicKey::try_from(&recipient_message_key_bytes[..])?; assert_eq!(sender_identity.public_key(), &sender_public_key); let recipient_static_keys = StaticKeys::calculate( @@ -970,11 +969,11 @@ mod sealed_sender_v2 { } .concat(); - let boxed_result = - HKDF::new(3)?.derive_secrets(&agreement_key_input, LABEL_DH, MESSAGE_KEY_LEN)?; - let mut result: [u8; MESSAGE_KEY_LEN] = boxed_result.as_ref().try_into().map_err(|_| { - SignalProtocolError::BadKeyLength(curve::KeyType::Djb, boxed_result.len()) - })?; + let mut result: [u8; MESSAGE_KEY_LEN] = HKDF::new(3)? + .derive_secrets(&agreement_key_input, LABEL_DH, MESSAGE_KEY_LEN)? + .as_ref() + .try_into() + .expect("requested correct key size from HKDF"); result .iter_mut() @@ -1015,12 +1014,11 @@ mod sealed_sender_v2 { } } - let boxed_result = - HKDF::new(3)?.derive_secrets(&agreement_key_input, LABEL_DH_S, AUTH_TAG_LEN)?; - boxed_result + Ok(HKDF::new(3)? + .derive_secrets(&agreement_key_input, LABEL_DH_S, AUTH_TAG_LEN)? .as_ref() .try_into() - .map_err(|_| SignalProtocolError::BadKeyLength(curve::KeyType::Djb, boxed_result.len())) + .expect("requested correct key size from HKDF")) } #[test]