From 6cc03d1c199fd07e46bb7551daa0f4b25e07df20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 17 Feb 2021 15:23:26 +0100 Subject: [PATCH] crypto: Improve the logging for deserialization failures --- matrix_sdk_crypto/src/machine.rs | 21 ++++++++++++++------- matrix_sdk_crypto/src/olm/account.rs | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index f54ce932..c580f745 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -809,12 +809,16 @@ impl OlmMachine { let mut events = Vec::new(); for event_result in &to_device_events.events { - let mut event = if let Ok(e) = event_result.deserialize() { - e - } else { - // Skip invalid events. - warn!("Received an invalid to-device event {:?}", event_result); - continue; + let mut event = match event_result.deserialize() { + Ok(e) => e, + Err(e) => { + // Skip invalid events. + warn!( + "Received an invalid to-device event {:?} {:?}", + e, event_result + ); + continue; + } }; info!("Received a to-device event {:?}", event); @@ -931,7 +935,10 @@ impl OlmMachine { // TODO check if this is from a verified device. let (decrypted_event, _) = session.decrypt(event).await?; - trace!("Successfully decrypted Megolm event {:?}", decrypted_event); + trace!( + "Successfully decrypted a Megolm event {:?}", + decrypted_event + ); // TODO set the encryption info on the event (is it verified, was it // decrypted, sender key...) diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index a5ed77e0..1da6f01c 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -349,7 +349,7 @@ impl Account { (SessionType::New(session), plaintext) }; - trace!("Successfully decrypted a Olm message: {}", plaintext); + trace!("Successfully decrypted an Olm message: {}", plaintext); let (event, signing_key) = match self.parse_decrypted_to_device_event(sender, &plaintext) { Ok(r) => r,