Skip to content

Commit

Permalink
fixup! apply changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Jan 17, 2025
1 parent 8c15db1 commit f1f130f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/olm/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ mod dehydrated_device {

#[derive(Encode, Decode, Zeroize, ZeroizeOnDrop)]
pub(crate) struct OneTimeKey {
#[secret]
pub(crate) private_key: Box<[u8; 32]>,
}

Expand Down Expand Up @@ -872,7 +873,9 @@ mod dehydrated_device {
/// [MSC3814](https://github.com/matrix-org/matrix-spec-proposals/pull/3814).
pub(super) struct Pickle {
version: u32,
#[secret]
private_curve25519_key: Box<[u8; 32]>,
#[secret]
private_ed25519_key: Box<[u8; 32]>,
one_time_keys: Vec<OneTimeKey>,
opt_fallback_key: OptFallbackKey,
Expand Down Expand Up @@ -1459,7 +1462,7 @@ mod test {
}

#[test]
fn decrypt_with_dehydrated_device() -> Result<()> {
fn decrypt_with_dehydrated_device() {
let mut alice = Account::new();
let bob = Account::new();
let carol = Account::new();
Expand All @@ -1478,7 +1481,7 @@ mod test {
.one_time_keys()
.iter()
.next()
.context("Failed getting alice's OTK, which should never happen here.")?
.expect("Failed getting alice's OTK, which should never happen here.")
.1,
);

Expand All @@ -1490,7 +1493,7 @@ mod test {
.fallback_key()
.iter()
.next()
.context("Failed getting alice's fallback key, which should never happen here.")?
.expect("Failed getting alice's fallback key, which should never happen here.")
.1,
);

Expand All @@ -1507,30 +1510,33 @@ mod test {

// make sure we can decrypt both messages
let prekey_message = assert_matches!(bob_olm_message, OlmMessage::PreKey(m) => m);
let InboundCreationResult { session: alice_session, plaintext } =
alice_rehydrated.create_inbound_session(bob.curve25519_key(), &prekey_message)?;
let InboundCreationResult { session: alice_session, plaintext } = alice_rehydrated
.create_inbound_session(bob.curve25519_key(), &prekey_message)
.expect("Alice should be able to create an inbound session from Bob's pre-key message");
assert_eq!(alice_session.session_id(), bob_session.session_id());
assert_eq!(message.as_bytes(), plaintext);

let prekey_message = assert_matches!(carol_olm_message, OlmMessage::PreKey(m) => m);
let InboundCreationResult { session: alice_session, plaintext } =
alice_rehydrated.create_inbound_session(carol.curve25519_key(), &prekey_message)?;
let InboundCreationResult { session: alice_session, plaintext } = alice_rehydrated
.create_inbound_session(carol.curve25519_key(), &prekey_message)
.expect(
"Alice should be able to create an inbound session from Carol's pre-key message",
);

assert_eq!(alice_session.session_id(), carol_session.session_id());
assert_eq!(message.as_bytes(), plaintext);

Ok(())
}

#[test]
fn fails_to_rehydrate_with_wrong_key() -> Result<()> {
fn fails_to_rehydrate_with_wrong_key() {
let mut alice = Account::new();

alice.generate_one_time_keys(alice.max_number_of_one_time_keys());
alice.generate_fallback_key();

let alice_dehydrated_result =
alice.to_dehydrated_device(&PICKLE_KEY).expect("Should be able to dehydrate device");

assert!(Account::from_dehydrated_device(
&alice_dehydrated_result.ciphertext,
&alice_dehydrated_result.nonce,
Expand All @@ -1544,8 +1550,6 @@ mod test {
&PICKLE_KEY,
)
.is_err());

Ok(())
}

#[derive(Encode, Decode)]
Expand All @@ -1555,7 +1559,7 @@ mod test {
}

#[test]
fn encodes_optional_fallback_key() -> Result<()> {
fn encodes_optional_fallback_key() {
use std::io::Cursor;

let data_to_pickle = OptFallbackPickleTest {
Expand All @@ -1578,8 +1582,6 @@ mod test {

assert!(unpickled_data.fallback1.fallback_key.is_some());
assert!(unpickled_data.fallback2.fallback_key.is_none());

Ok(())
}

#[test]
Expand Down

0 comments on commit f1f130f

Please sign in to comment.