From fec84c763cb5fdd0c2829f22e9f1690721cdb783 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 30 Sep 2024 09:17:55 +0200 Subject: [PATCH] ffi: Expose `room_decryption_trust_requirement` for ClientBuilder --- bindings/matrix-sdk-crypto-ffi/src/machine.rs | 3 +-- bindings/matrix-sdk-ffi/src/client_builder.rs | 17 +++++++++++++++-- crates/matrix-sdk-crypto/src/lib.rs | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index b8920f6dd9..b51345cb47 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -867,6 +867,7 @@ impl OlmMachine { room_id: String, handle_verification_events: bool, strict_shields: bool, + decryption_settings: DecryptionSettings, ) -> Result { // Element Android wants only the content and the type and will create a // decrypted event with those two itself, this struct makes sure we @@ -882,8 +883,6 @@ impl OlmMachine { let event: Raw<_> = serde_json::from_str(&event)?; let room_id = RoomId::parse(room_id)?; - let decryption_settings = - DecryptionSettings { sender_device_trust_requirement: TrustRequirement::Untrusted }; let decrypted = self.runtime.block_on(self.inner.decrypt_room_event( &event, &room_id, diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index f619daedf1..ec0522fafd 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -5,7 +5,7 @@ use matrix_sdk::{ authentication::qrcode::{self, DeviceCodeErrorResponseType, LoginFailureReason}, crypto::{ types::qr_login::{LoginQrCodeDecodeError, QrCodeModeData}, - CollectStrategy, + CollectStrategy, TrustRequirement, }, encryption::{BackupDownloadStrategy, EncryptionSettings}, reqwest::Certificate, @@ -266,6 +266,7 @@ pub struct ClientBuilder { disable_built_in_root_certificates: bool, encryption_settings: EncryptionSettings, room_key_recipient_strategy: CollectStrategy, + decryption_trust_requirement: TrustRequirement, request_config: Option, } @@ -294,6 +295,7 @@ impl ClientBuilder { auto_enable_backups: false, }, room_key_recipient_strategy: Default::default(), + decryption_trust_requirement: TrustRequirement::Untrusted, request_config: Default::default(), }) } @@ -449,6 +451,16 @@ impl ClientBuilder { Arc::new(builder) } + /// Set the trust requirement to be used when decrypting events. + pub fn room_decryption_trust_requirement( + self: Arc, + trust_requirement: TrustRequirement, + ) -> Arc { + let mut builder = unwrap_or_clone_arc(self); + builder.decryption_trust_requirement = trust_requirement; + Arc::new(builder) + } + /// Add a default request config to this client. pub fn request_config(self: Arc, config: RequestConfig) -> Arc { let mut builder = unwrap_or_clone_arc(self); @@ -548,7 +560,8 @@ impl ClientBuilder { inner_builder = inner_builder .with_encryption_settings(builder.encryption_settings) - .with_room_key_recipient_strategy(builder.room_key_recipient_strategy); + .with_room_key_recipient_strategy(builder.room_key_recipient_strategy) + .with_decryption_trust_requirement(builder.decryption_trust_requirement); match builder.sliding_sync_version_builder { SlidingSyncVersionBuilder::None => { diff --git a/crates/matrix-sdk-crypto/src/lib.rs b/crates/matrix-sdk-crypto/src/lib.rs index 41c110a3b6..9b1dbac643 100644 --- a/crates/matrix-sdk-crypto/src/lib.rs +++ b/crates/matrix-sdk-crypto/src/lib.rs @@ -117,6 +117,7 @@ uniffi::setup_scaffolding!(); /// The trust level in the sender's device that is required to decrypt an /// event. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] pub enum TrustRequirement { /// Decrypt events from everyone regardless of trust. Untrusted,