Skip to content

Commit

Permalink
add a test and improve a test
Browse files Browse the repository at this point in the history
  • Loading branch information
uhoreg committed Jan 15, 2025
1 parent 26f79ad commit f421d84
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/olm/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl Account {
pickle.try_into()
}

#[cfg(fuzzing)]
#[cfg(any(fuzzing, test))]
#[doc(hidden)]
pub fn from_decrypted_dehydrated_device(
pickle: &[u8],
Expand Down Expand Up @@ -1459,6 +1459,7 @@ mod test {
fn decrypt_with_dehydrated_device() -> Result<()> {
let mut alice = Account::new();
let bob = Account::new();
let carol = Account::new();

alice.generate_one_time_keys(alice.max_number_of_one_time_keys());
alice.generate_fallback_key();
Expand Down Expand Up @@ -1487,7 +1488,7 @@ mod test {
)
.expect("Should be able to rehydrate device");

if let OlmMessage::PreKey(m) = olm_message {
if let OlmMessage::PreKey(m) = bob_olm_message {
let InboundCreationResult { session: alice_session, plaintext } =
alice_rehydrated.create_inbound_session(bob.curve25519_key(), &m)?;

Expand All @@ -1497,6 +1498,16 @@ mod test {
panic!("Expected a pre-key message");
}

if let OlmMessage::PreKey(m) = carol_olm_message {
let InboundCreationResult { session: alice_session, plaintext } =
alice_rehydrated.create_inbound_session(carol.curve25519_key(), &m)?;

assert_eq!(alice_session.session_id(), carol_session.session_id());
assert_eq!(message.as_bytes(), plaintext);
} else {
panic!("Expected a pre-key message");
}

Ok(())
}

Expand Down Expand Up @@ -1559,4 +1570,21 @@ mod test {

Ok(())
}

#[test]
fn decrypted_dehydration_cycle() {
use dehydrated_device::Pickle;

let alice = Account::new();

let mut encoded = Vec::<u8>::new();
let pickle = Pickle::from(&alice);
let size = pickle.encode(&mut encoded).expect("Should dehydrate");
assert_eq!(size, encoded.len());

let account =
Account::from_decrypted_dehydrated_device(&encoded).expect("Should rehydrate account");

assert_eq!(alice.identity_keys(), account.identity_keys());
}
}

0 comments on commit f421d84

Please sign in to comment.