crypto: Implement a better debug trait for sessions.

master
Damir Jelić 2020-04-15 13:46:43 +02:00
parent 33a1b8b791
commit 53a2b8eb7c
1 changed files with 16 additions and 2 deletions

View File

@ -232,7 +232,7 @@ impl PartialEq for Account {
///
/// Sessions are used to exchange encrypted messages between two
/// accounts/devices.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Session {
inner: Arc<Mutex<OlmSession>>,
session_id: Arc<String>,
@ -241,6 +241,15 @@ pub struct Session {
pub(crate) last_use_time: Arc<Instant>,
}
impl fmt::Debug for Session {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Session")
.field("session_id", &self.session_id())
.field("sender_key", &self.sender_key)
.finish()
}
}
impl Session {
/// Decrypt the given Olm message.
///
@ -688,10 +697,15 @@ mod test {
let bob_keys = bob.identity_keys();
let mut alice_session = alice
.create_inbound_session(bob_keys.curve25519(), prekey_message)
.create_inbound_session(bob_keys.curve25519(), prekey_message.clone())
.await
.unwrap();
assert!(alice_session
.matches(bob_keys.curve25519(), prekey_message)
.await
.unwrap());
assert_eq!(bob_session.session_id(), alice_session.session_id());
let decyrpted = alice_session.decrypt(message).await.unwrap();