crypto: Expose with_decryption_trust_requirement for ClientBuilder

This commit is contained in:
Valere
2024-09-30 09:13:07 +02:00
parent dc055c632c
commit 3fd2f5794e
4 changed files with 31 additions and 6 deletions

View File

@@ -117,6 +117,10 @@ pub struct BaseClient {
/// encrypted message.
#[cfg(feature = "e2e-encryption")]
pub room_key_recipient_strategy: CollectStrategy,
/// The trust requirement to use for decrypting events.
#[cfg(feature = "e2e-encryption")]
pub decryption_trust_requirement: TrustRequirement,
}
#[cfg(not(tarpaulin_include))]
@@ -156,6 +160,8 @@ impl BaseClient {
room_info_notable_update_sender,
#[cfg(feature = "e2e-encryption")]
room_key_recipient_strategy: Default::default(),
#[cfg(feature = "e2e-encryption")]
decryption_trust_requirement: TrustRequirement::Untrusted,
}
}
@@ -180,6 +186,7 @@ impl BaseClient {
ignore_user_list_changes: Default::default(),
room_info_notable_update_sender: self.room_info_notable_update_sender.clone(),
room_key_recipient_strategy: self.room_key_recipient_strategy.clone(),
decryption_trust_requirement: self.decryption_trust_requirement,
};
if let Some(session_meta) = self.session_meta().cloned() {
@@ -345,8 +352,9 @@ impl BaseClient {
let olm = self.olm_machine().await;
let Some(olm) = olm.as_ref() else { return Ok(None) };
let decryption_settings =
DecryptionSettings { sender_device_trust_requirement: TrustRequirement::Untrusted };
let decryption_settings = DecryptionSettings {
sender_device_trust_requirement: self.decryption_trust_requirement,
};
let event: SyncTimelineEvent =
olm.decrypt_room_event(event.cast_ref(), room_id, &decryption_settings).await?.into();

View File

@@ -27,6 +27,7 @@ Breaking changes:
Additions:
- new `ClientBuilder::with_decryption_trust_requirement` method.
- new `ClientBuilder::with_room_key_recipient_strategy` method
- new `Room.set_account_data` and `Room.set_account_data_raw` RoomAccountData setters, analogous to the GlobalAccountData
- new `RequestConfig.max_concurrent_requests` which allows to limit the maximum number of concurrent requests the internal HTTP client issues (all others have to wait until the number drops below that threshold again)

View File

@@ -29,7 +29,7 @@ use tracing::{debug, field::debug, instrument, Span};
use super::{Client, ClientInner};
#[cfg(feature = "e2e-encryption")]
use crate::crypto::CollectStrategy;
use crate::crypto::{CollectStrategy, TrustRequirement};
#[cfg(feature = "e2e-encryption")]
use crate::encryption::EncryptionSettings;
#[cfg(not(target_arch = "wasm32"))]
@@ -99,6 +99,8 @@ pub struct ClientBuilder {
encryption_settings: EncryptionSettings,
#[cfg(feature = "e2e-encryption")]
room_key_recipient_strategy: CollectStrategy,
#[cfg(feature = "e2e-encryption")]
decryption_trust_requirement: TrustRequirement,
}
impl ClientBuilder {
@@ -118,6 +120,8 @@ impl ClientBuilder {
encryption_settings: Default::default(),
#[cfg(feature = "e2e-encryption")]
room_key_recipient_strategy: Default::default(),
#[cfg(feature = "e2e-encryption")]
decryption_trust_requirement: TrustRequirement::Untrusted,
}
}
@@ -407,6 +411,16 @@ impl ClientBuilder {
self
}
/// Set the trust requirement to be used when decrypting events.
#[cfg(feature = "e2e-encryption")]
pub fn with_decryption_trust_requirement(
mut self,
trust_requirement: TrustRequirement,
) -> Self {
self.decryption_trust_requirement = trust_requirement;
self
}
/// Create a [`Client`] with the options set on this builder.
///
/// # Errors
@@ -445,6 +459,7 @@ impl ClientBuilder {
#[cfg(feature = "e2e-encryption")]
{
client.room_key_recipient_strategy = self.room_key_recipient_strategy;
client.decryption_trust_requirement = self.decryption_trust_requirement;
}
client
};

View File

@@ -15,7 +15,7 @@ use futures_util::{
stream::FuturesUnordered,
};
#[cfg(feature = "e2e-encryption")]
use matrix_sdk_base::crypto::{DecryptionSettings, TrustRequirement};
use matrix_sdk_base::crypto::DecryptionSettings;
use matrix_sdk_base::{
deserialized_responses::{
RawAnySyncOrStrippedState, RawSyncOrStrippedState, SyncOrStrippedState, TimelineEvent,
@@ -1183,8 +1183,9 @@ impl Room {
let machine = self.client.olm_machine().await;
let machine = machine.as_ref().ok_or(Error::NoOlmMachine)?;
let decryption_settings =
DecryptionSettings { sender_device_trust_requirement: TrustRequirement::Untrusted };
let decryption_settings = DecryptionSettings {
sender_device_trust_requirement: self.client.base_client().decryption_trust_requirement,
};
let mut event = match machine
.decrypt_room_event(event.cast_ref(), self.inner.room_id(), &decryption_settings)
.await