From c97f7e9ed06d5782fd8da126db2062276cb121aa Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 25 Feb 2022 15:19:57 +0100 Subject: [PATCH] clippy --- crates/matrix-sdk-crypto/src/olm/session.rs | 9 +++++ .../matrix-sdk-crypto/src/olm/signing/mod.rs | 2 ++ crates/matrix-sdk-crypto/src/store/mod.rs | 15 ++++++++ crates/matrix-sdk-sled/src/state_store.rs | 36 ++++++++----------- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/olm/session.rs b/crates/matrix-sdk-crypto/src/olm/session.rs index 7f481ccb9..45d85e343 100644 --- a/crates/matrix-sdk-crypto/src/olm/session.rs +++ b/crates/matrix-sdk-crypto/src/olm/session.rs @@ -43,14 +43,23 @@ use crate::{ /// `Account`s #[derive(Clone)] pub struct Session { + /// The `UserId` associated with this session pub user_id: Arc, + /// The specific `DeviceId` associated with this session pub device_id: Arc, + /// The `IdentityKeys` associated with this session pub our_identity_keys: Arc, + /// The OlmSession pub inner: Arc>, + /// Our sessionId pub session_id: Arc, + /// The Key of the sender pub sender_key: Arc, + /// Has this been creaed using the fallback key pub created_using_fallback_key: bool, + /// When the session was created pub creation_time: Arc, + /// When the session was last used pub last_use_time: Arc, } diff --git a/crates/matrix-sdk-crypto/src/olm/signing/mod.rs b/crates/matrix-sdk-crypto/src/olm/signing/mod.rs index a8594a467..b25ba5970 100644 --- a/crates/matrix-sdk-crypto/src/olm/signing/mod.rs +++ b/crates/matrix-sdk-crypto/src/olm/signing/mod.rs @@ -544,6 +544,8 @@ impl PrivateCrossSigningIdentity { #[cfg(any(test, feature = "testing"))] #[allow(dead_code)] + /// Testing helper to reset this CrossSigning with a fresh one using the + /// local ideniy pub async fn reset(&mut self) { let new = Self::new(self.user_id().to_owned()).await; *self = new diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index 9527c6f26..1c6f9912b 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -233,6 +233,7 @@ pub enum SecretImportError { } impl Store { + /// Create a new Store pub fn new( user_id: Arc, identity: Arc>, @@ -242,27 +243,33 @@ impl Store { Self { user_id, identity, inner: store, verification_machine } } + /// UserId associated with this store pub fn user_id(&self) -> &UserId { &self.user_id } + /// DeviceId associated with this store pub fn device_id(&self) -> &DeviceId { self.verification_machine.own_device_id() } + /// The Account associated with this store pub fn account(&self) -> &ReadOnlyAccount { &self.verification_machine.store.account } #[cfg(test)] + /// test helper to reset the cross signing identity pub async fn reset_cross_signing_identity(&self) { self.identity.lock().await.reset().await; } + /// PrivateCrossSigningIdentity associated with this store pub fn private_identity(&self) -> Arc> { self.identity.clone() } + /// Save the given Sessions to the store pub async fn save_sessions(&self, sessions: &[Session]) -> Result<()> { let changes = Changes { sessions: sessions.to_vec(), ..Default::default() }; @@ -270,6 +277,7 @@ impl Store { } #[cfg(test)] + /// Testing helper to allo to save only a set of devices pub async fn save_devices(&self, devices: &[ReadOnlyDevice]) -> Result<()> { let changes = Changes { devices: DeviceChanges { changed: devices.to_vec(), ..Default::default() }, @@ -280,6 +288,7 @@ impl Store { } #[cfg(test)] + /// Testing helper to allo to save only a set of InboundGroupSession pub async fn save_inbound_group_sessions( &self, sessions: &[InboundGroupSession], @@ -298,6 +307,7 @@ impl Store { .and_then(|d| d.display_name().map(|d| d.to_string()))) } + /// Get the read-only device associated with `device_id` for `user_id` pub async fn get_readonly_device( &self, user_id: &UserId, @@ -346,6 +356,7 @@ impl Store { }) } + /// Get all devices associated with the given `user_id` pub async fn get_user_devices(&self, user_id: &UserId) -> Result { let devices = self.inner.get_user_devices(user_id).await?; @@ -361,6 +372,7 @@ impl Store { }) } + /// Get a Device copy associated with `device_id` for `user_id` pub async fn get_device( &self, user_id: &UserId, @@ -378,6 +390,7 @@ impl Store { })) } + /// Get the Identity of `user_id` pub async fn get_identity(&self, user_id: &UserId) -> Result> { // let own_identity = // self.inner.get_user_identity(self.user_id()).await?.and_then(|i| i.own()); @@ -444,6 +457,7 @@ impl Store { } } + /// Import the Cross Signing Keys pub async fn import_cross_signing_keys( &self, export: CrossSigningKeyExport, @@ -473,6 +487,7 @@ impl Store { Ok(self.identity.lock().await.status().await) } + /// Import the given `secret` named `secret_name` into the keystore. pub async fn import_secret( &self, secret_name: &SecretName, diff --git a/crates/matrix-sdk-sled/src/state_store.rs b/crates/matrix-sdk-sled/src/state_store.rs index ffff7b5c3..c550ba0f4 100644 --- a/crates/matrix-sdk-sled/src/state_store.rs +++ b/crates/matrix-sdk-sled/src/state_store.rs @@ -87,6 +87,7 @@ impl From> for SledStoreError { } } +#[allow(clippy::from_over_into)] impl Into for SledStoreError { fn into(self) -> StoreError { match self { @@ -639,10 +640,8 @@ impl SledStore { pub async fn get_presence_event(&self, user_id: &UserId) -> Result>> { let db = self.clone(); let key = user_id.encode(); - spawn_blocking(move || { - Ok(db.presence.get(key)?.map(|e| db.deserialize_event(&e)).transpose()?) - }) - .await? + spawn_blocking(move || db.presence.get(key)?.map(|e| db.deserialize_event(&e)).transpose()) + .await? } pub async fn get_state_event( @@ -654,7 +653,7 @@ impl SledStore { let db = self.clone(); let key = (room_id.as_str(), event_type.as_str(), state_key).encode(); spawn_blocking(move || { - Ok(db.room_state.get(key)?.map(|e| db.deserialize_event(&e)).transpose()?) + db.room_state.get(key)?.map(|e| db.deserialize_event(&e)).transpose() }) .await? } @@ -667,11 +666,10 @@ impl SledStore { let db = self.clone(); let key = (room_id.as_str(), event_type.as_str()).encode(); spawn_blocking(move || { - Ok(db - .room_state + db.room_state .scan_prefix(key) .flat_map(|e| e.map(|(_, e)| db.deserialize_event(&e))) - .collect::>()?) + .collect::>() }) .await? } @@ -683,10 +681,8 @@ impl SledStore { ) -> Result> { let db = self.clone(); let key = (room_id.as_str(), user_id.as_str()).encode(); - spawn_blocking(move || { - Ok(db.profiles.get(key)?.map(|p| db.deserialize_event(&p)).transpose()?) - }) - .await? + spawn_blocking(move || db.profiles.get(key)?.map(|p| db.deserialize_event(&p)).transpose()) + .await? } pub async fn get_member_event( @@ -696,10 +692,8 @@ impl SledStore { ) -> Result> { let db = self.clone(); let key = (room_id.as_str(), state_key.as_str()).encode(); - spawn_blocking(move || { - Ok(db.members.get(key)?.map(|v| db.deserialize_event(&v)).transpose()?) - }) - .await? + spawn_blocking(move || db.members.get(key)?.map(|v| db.deserialize_event(&v)).transpose()) + .await? } pub async fn get_user_ids_stream( @@ -773,7 +767,7 @@ impl SledStore { let db = self.clone(); spawn_blocking(move || { stream::iter( - db.room_info.iter().map(move |r| db.deserialize_event(&r?.1).map_err(|e| e.into())), + db.room_info.iter().map(move |r| db.deserialize_event(&r?.1).map_err(|e| e)), ) }) .await @@ -786,7 +780,7 @@ impl SledStore { stream::iter( db.stripped_room_infos .iter() - .map(move |r| db.deserialize_event(&r?.1).map_err(|e| e.into())), + .map(move |r| db.deserialize_event(&r?.1).map_err(|e| e)), ) }) .await @@ -818,7 +812,7 @@ impl SledStore { let db = self.clone(); let key = event_type.encode(); spawn_blocking(move || { - Ok(db.account_data.get(key)?.map(|m| db.deserialize_event(&m)).transpose()?) + db.account_data.get(key)?.map(|m| db.deserialize_event(&m)).transpose() }) .await? } @@ -831,7 +825,7 @@ impl SledStore { let db = self.clone(); let key = (room_id.as_str(), event_type.as_str()).encode(); spawn_blocking(move || { - Ok(db.room_account_data.get(key)?.map(|m| db.deserialize_event(&m)).transpose()?) + db.room_account_data.get(key)?.map(|m| db.deserialize_event(&m)).transpose() }) .await? } @@ -845,7 +839,7 @@ impl SledStore { let db = self.clone(); let key = (room_id.as_str(), receipt_type.as_ref(), user_id.as_str()).encode(); spawn_blocking(move || { - Ok(db.room_user_receipts.get(key)?.map(|m| db.deserialize_event(&m)).transpose()?) + db.room_user_receipts.get(key)?.map(|m| db.deserialize_event(&m)).transpose() }) .await? }