diff --git a/bindings/matrix-sdk-crypto-ffi/Cargo.toml b/bindings/matrix-sdk-crypto-ffi/Cargo.toml index 8b3b5252b..ba673ae39 100644 --- a/bindings/matrix-sdk-crypto-ffi/Cargo.toml +++ b/bindings/matrix-sdk-crypto-ffi/Cargo.toml @@ -65,3 +65,4 @@ uniffi = { workspace = true, features = ["build"] } [dev-dependencies] tempfile = "3.3.0" +assert_matches = { workspace = true } diff --git a/bindings/matrix-sdk-crypto-ffi/src/error.rs b/bindings/matrix-sdk-crypto-ffi/src/error.rs index aaaf1cbf2..d4215fa03 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/error.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/error.rs @@ -69,7 +69,7 @@ impl From for DecryptionError { match value { MegolmError::MissingRoomKey(withheld_code) => Self::MissingRoomKey { error: "Withheld Inbound group session".to_owned(), - withheld_code: withheld_code.map(|w| w.to_string()), + withheld_code: withheld_code.map(|w| w.as_str().to_owned()), }, _ => Self::Megolm { error: value.to_string() }, } @@ -93,3 +93,26 @@ impl From for DecryptionError { Self::Store { error: err.to_string() } } } + +#[cfg(test)] +mod tests { + + use assert_matches::assert_matches; + + use super::*; + + #[test] + fn test_withheld_error_mapping() { + use matrix_sdk_crypto::types::events::room_key_withheld::WithheldCode; + + let inner_error = MegolmError::MissingRoomKey(Some(WithheldCode::Unverified)); + + let binding_error: DecryptionError = inner_error.into(); + + let code = assert_matches!( + binding_error, + DecryptionError::MissingRoomKey { error: _, withheld_code: Some(withheld_code) } => withheld_code + ); + assert_eq!("m.unverified", code) + } +}