-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: expose new method OlmMachine::try_decrypt_room_event
#4116
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4116 +/- ##
==========================================
- Coverage 84.69% 84.57% -0.13%
==========================================
Files 269 269
Lines 28816 28825 +9
==========================================
- Hits 24405 24378 -27
- Misses 4411 4447 +36 ☔ View full report in Codecov by Sentry. |
7420e03
to
33f5dd9
Compare
33f5dd9
to
61f3cec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
/// that session for some reason (e.g. incorrect MAC). | ||
/// | ||
/// This represents all `vodozemac::megolm::DecryptionError`s, with the | ||
/// exception of `UnknownMessageIndex`, which is represented as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this difficult to parse because of the special meaning of "exception" in my head. Would "with the exception of" -> "except" be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for breaking it into simple changes :)
fn unknown_utd_reason() -> UnableToDecryptReason { | ||
UnableToDecryptReason::Unknown | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, you can instead derive(Default)
to UnableToDecryptReason
, and then mark one variant as the default:
#[default]
#[doc(hidden)]
Unknown,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wanted to explicitly avoid implementing Default
for UnableToDecryptReason
, because then people might start using it outside the deserialization case.
MegolmDecryptionFailure, | ||
|
||
/// The event could not be deserialized after decryption. | ||
PayloadDeserializationFailure, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double nit: since those are errors, i'd say "failure" in the variant's name is redundant, and would lightly encourage to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really agree. If I compare with something like MissingMegolmSession
: a missing megolm session is a sensible reason for being unable to decrypt an event. So is a "megolm decryption failure". But just MegolmDecryption
on its own doesn't really make sense to me.
I'm prepared to believe there could be better names for these things (UnableToDecryptMegolmMessage
? VodozemacDecryptionError
?), but I don't think MegolmDecryption
would be a good one.
@@ -2540,6 +2536,38 @@ pub struct EncryptionSyncChanges<'a> { | |||
pub next_batch_token: Option<String>, | |||
} | |||
|
|||
fn megolm_error_to_utd_info( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write a tiny doc comment for this, please? (It wasn't clear at a first glance at the call-site why this could return an error...)
Some(UnsignedDecryptionResult::UnableToDecrypt(UnableToDecryptInfo { | ||
session_id, | ||
})) | ||
Err(e) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you name this variable err
, if not error
, please? One-letter variables are bleh.
) -> Result<RoomEventDecryptionResult, CryptoStoreError> { | ||
match self.decrypt_room_event_inner(raw_event, room_id, true, decryption_settings).await { | ||
Ok(decrypted) => Ok(RoomEventDecryptionResult::Decrypted(decrypted)), | ||
Err(e) => Ok(RoomEventDecryptionResult::UnableToDecrypt(megolm_error_to_utd_info( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: e => err too here please
let decrypt_result = | ||
bob.try_decrypt_room_event(&room_event, room_id, &decryption_settings).await.unwrap(); | ||
assert_let!(RoomEventDecryptionResult::UnableToDecrypt(utd_info) = decrypt_result); | ||
assert!(utd_info.session_id.is_some()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we assert the reason too?
Add a field to store the reason that the decryption failed
390f187
to
f003f6b
Compare
... which returns an enum which encodes decryption failure information, rather than returning
MegolmError
To make this work, we also extend the existing
UnableToDecryptInfo
to include a reason code for the failure.Part of #4048