Skip to content

Commit

Permalink
return finer-grained errors for sender-not-trusted
Browse files Browse the repository at this point in the history
  • Loading branch information
uhoreg committed Sep 16, 2024
1 parent c8da41c commit cc411f0
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Errors related to room event decryption.

use js_sys::JsString;
use matrix_sdk_common::deserialized_responses::VerificationLevel;
use matrix_sdk_crypto::{vodozemac, MegolmError};
use wasm_bindgen::prelude::wasm_bindgen;

Expand All @@ -16,8 +17,12 @@ pub enum DecryptionErrorCode {
/// device we received the room key from and the identity keys recorded in
/// the plaintext of the room key to-device message.
MismatchedIdentityKeys,
/// The sender does not satisfy the requested trust requirement.
SenderIdentityNotTrusted,
/// We weren't able to link the message back to any known device.
UnknownSenderDevice,
/// The sender device is not cross-signed.
UnsignedSenderDevice,
/// The sender's identity is unverified, but was previously verified.
SenderIdentityPreviouslyVerified,
/// Other failure.
UnableToDecrypt,
}
Expand Down Expand Up @@ -70,8 +75,18 @@ impl From<MegolmError> for MegolmDecryptionError {
description: value.to_string().into(),
maybe_withheld: None,
},
MegolmError::SenderIdentityNotTrusted(..) => MegolmDecryptionError {
code: DecryptionErrorCode::SenderIdentityNotTrusted,
MegolmError::SenderIdentityNotTrusted(VerificationLevel::PreviouslyVerified) => MegolmDecryptionError {
code: DecryptionErrorCode::SenderIdentityPreviouslyVerified,
description: value.to_string().into(),
maybe_withheld: None,
},
MegolmError::SenderIdentityNotTrusted(VerificationLevel::UnsignedDevice) => MegolmDecryptionError {
code: DecryptionErrorCode::UnsignedSenderDevice,
description: value.to_string().into(),
maybe_withheld: None,
},
MegolmError::SenderIdentityNotTrusted(VerificationLevel::None(..)) => MegolmDecryptionError {
code: DecryptionErrorCode::UnknownSenderDevice,
description: value.to_string().into(),
maybe_withheld: None,
},
Expand Down

0 comments on commit cc411f0

Please sign in to comment.