From 6b685b671de3b2a1d299e7334c8c9e09c66ac9d5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 6 Jun 2021 18:16:25 +0200 Subject: [PATCH] Replace Arc> by Arc --- matrix_sdk_base/src/rooms/normal.rs | 6 +++--- matrix_sdk_base/src/store/mod.rs | 6 +++--- matrix_sdk_crypto/src/identities/device.rs | 2 +- matrix_sdk_crypto/src/identities/manager.rs | 10 +++------- matrix_sdk_crypto/src/identities/user.rs | 4 ++-- matrix_sdk_crypto/src/key_request.rs | 4 ++-- matrix_sdk_crypto/src/machine.rs | 2 +- matrix_sdk_crypto/src/session_manager/sessions.rs | 2 +- matrix_sdk_crypto/src/store/mod.rs | 6 +++--- matrix_sdk_crypto/src/verification/machine.rs | 10 +++++----- matrix_sdk_crypto/src/verification/mod.rs | 2 +- matrix_sdk_crypto/src/verification/requests.rs | 14 +++++++------- matrix_sdk_crypto/src/verification/sas/mod.rs | 12 ++++++------ 13 files changed, 38 insertions(+), 42 deletions(-) diff --git a/matrix_sdk_base/src/rooms/normal.rs b/matrix_sdk_base/src/rooms/normal.rs index 6e2fc03c..3ef44659 100644 --- a/matrix_sdk_base/src/rooms/normal.rs +++ b/matrix_sdk_base/src/rooms/normal.rs @@ -52,7 +52,7 @@ pub struct Room { room_id: Arc, own_user_id: Arc, inner: Arc>, - store: Arc>, + store: Arc, } /// The room summary containing member counts and members that should be used to @@ -83,7 +83,7 @@ pub enum RoomType { impl Room { pub(crate) fn new( own_user_id: &UserId, - store: Arc>, + store: Arc, room_id: &RoomId, room_type: RoomType, ) -> Self { @@ -104,7 +104,7 @@ impl Room { pub(crate) fn restore( own_user_id: &UserId, - store: Arc>, + store: Arc, room_info: RoomInfo, ) -> Self { Self { diff --git a/matrix_sdk_base/src/store/mod.rs b/matrix_sdk_base/src/store/mod.rs index bbc915ed..45b38ca0 100644 --- a/matrix_sdk_base/src/store/mod.rs +++ b/matrix_sdk_base/src/store/mod.rs @@ -289,7 +289,7 @@ pub trait StateStore: AsyncTraitDeps { /// `StateStore` implementation. #[derive(Debug, Clone)] pub struct Store { - inner: Arc>, + inner: Arc, pub(crate) session: Arc>>, pub(crate) sync_token: Arc>>, rooms: Arc>, @@ -405,10 +405,10 @@ impl Store { } impl Deref for Store { - type Target = Box; + type Target = dyn StateStore; fn deref(&self) -> &Self::Target { - &self.inner + &*self.inner } } diff --git a/matrix_sdk_crypto/src/identities/device.rs b/matrix_sdk_crypto/src/identities/device.rs index bec4e995..9e171bd4 100644 --- a/matrix_sdk_crypto/src/identities/device.rs +++ b/matrix_sdk_crypto/src/identities/device.rs @@ -184,7 +184,7 @@ impl Device { event_type: EventType, content: Value, ) -> OlmResult<(Session, EncryptedEventContent)> { - self.inner.encrypt(&**self.verification_machine.store, event_type, content).await + self.inner.encrypt(&*self.verification_machine.store, event_type, content).await } /// Encrypt the given inbound group session as a forwarded room key for this diff --git a/matrix_sdk_crypto/src/identities/manager.rs b/matrix_sdk_crypto/src/identities/manager.rs index 37629fda..5584032e 100644 --- a/matrix_sdk_crypto/src/identities/manager.rs +++ b/matrix_sdk_crypto/src/identities/manager.rs @@ -423,14 +423,10 @@ pub(crate) mod test { let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id()))); let user_id = Arc::new(user_id()); let account = ReadOnlyAccount::new(&user_id, &device_id()); - let store: Arc> = Arc::new(Box::new(MemoryStore::new())); + let store: Arc = Arc::new(MemoryStore::new()); let verification = VerificationMachine::new(account, identity.clone(), store); - let store = Store::new( - user_id.clone(), - identity, - Arc::new(Box::new(MemoryStore::new())), - verification, - ); + let store = + Store::new(user_id.clone(), identity, Arc::new(MemoryStore::new()), verification); IdentityManager::new(user_id, device_id().into(), store) } diff --git a/matrix_sdk_crypto/src/identities/user.rs b/matrix_sdk_crypto/src/identities/user.rs index e01a75e0..66405c91 100644 --- a/matrix_sdk_crypto/src/identities/user.rs +++ b/matrix_sdk_crypto/src/identities/user.rs @@ -758,7 +758,7 @@ pub(crate) mod test { let verification_machine = VerificationMachine::new( ReadOnlyAccount::new(second.user_id(), second.device_id()), private_identity.clone(), - Arc::new(Box::new(MemoryStore::new())), + Arc::new(MemoryStore::new()), ); let first = Device { @@ -801,7 +801,7 @@ pub(crate) mod test { let verification_machine = VerificationMachine::new( ReadOnlyAccount::new(device.user_id(), device.device_id()), id.clone(), - Arc::new(Box::new(MemoryStore::new())), + Arc::new(MemoryStore::new()), ); let public_identity = identity.as_public_identity().await.unwrap(); diff --git a/matrix_sdk_crypto/src/key_request.rs b/matrix_sdk_crypto/src/key_request.rs index ab359e52..9f2e793f 100644 --- a/matrix_sdk_crypto/src/key_request.rs +++ b/matrix_sdk_crypto/src/key_request.rs @@ -846,7 +846,7 @@ mod test { fn bob_machine() -> KeyRequestMachine { let user_id = Arc::new(bob_id()); let account = ReadOnlyAccount::new(&user_id, &alice_device_id()); - let store: Arc> = Arc::new(Box::new(MemoryStore::new())); + let store: Arc = Arc::new(MemoryStore::new()); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(bob_id()))); let verification = VerificationMachine::new(account, identity.clone(), store.clone()); let store = Store::new(user_id.clone(), identity, store, verification); @@ -865,7 +865,7 @@ mod test { let user_id: Arc = alice_id().into(); let account = ReadOnlyAccount::new(&user_id, &alice_device_id()); let device = ReadOnlyDevice::from_account(&account).await; - let store: Arc> = Arc::new(Box::new(MemoryStore::new())); + let store: Arc = Arc::new(MemoryStore::new()); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id()))); let verification = VerificationMachine::new(account, identity.clone(), store.clone()); let store = Store::new(user_id.clone(), identity, store, verification); diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 6d969ff2..e5c23c7a 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -144,7 +144,7 @@ impl OlmMachine { let user_id = Arc::new(user_id.clone()); let user_identity = Arc::new(Mutex::new(user_identity)); - let store = Arc::new(store); + let store: Arc = store.into(); let verification_machine = VerificationMachine::new(account.clone(), user_identity.clone(), store.clone()); let store = diff --git a/matrix_sdk_crypto/src/session_manager/sessions.rs b/matrix_sdk_crypto/src/session_manager/sessions.rs index 909e8f37..099e2ffd 100644 --- a/matrix_sdk_crypto/src/session_manager/sessions.rs +++ b/matrix_sdk_crypto/src/session_manager/sessions.rs @@ -332,7 +332,7 @@ mod test { let users_for_key_claim = Arc::new(DashMap::new()); let account = ReadOnlyAccount::new(&user_id, &device_id); - let store: Arc> = Arc::new(Box::new(MemoryStore::new())); + let store: Arc = Arc::new(MemoryStore::new()); store.save_account(account.clone()).await.unwrap(); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id.clone()))); let verification = diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index edb4587f..9b898bc0 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -94,7 +94,7 @@ pub type Result = std::result::Result; pub(crate) struct Store { user_id: Arc, identity: Arc>, - inner: Arc>, + inner: Arc, verification_machine: VerificationMachine, } @@ -140,7 +140,7 @@ impl Store { pub fn new( user_id: Arc, identity: Arc>, - store: Arc>, + store: Arc, verification_machine: VerificationMachine, ) -> Self { Self { user_id, identity, inner: store, verification_machine } @@ -238,7 +238,7 @@ impl Deref for Store { type Target = dyn CryptoStore; fn deref(&self) -> &Self::Target { - &**self.inner + &*self.inner } } diff --git a/matrix_sdk_crypto/src/verification/machine.rs b/matrix_sdk_crypto/src/verification/machine.rs index e569321c..31eb4aaa 100644 --- a/matrix_sdk_crypto/src/verification/machine.rs +++ b/matrix_sdk_crypto/src/verification/machine.rs @@ -40,7 +40,7 @@ use crate::{ pub struct VerificationMachine { account: ReadOnlyAccount, private_identity: Arc>, - pub(crate) store: Arc>, + pub(crate) store: Arc, verifications: VerificationCache, requests: Arc>, } @@ -49,7 +49,7 @@ impl VerificationMachine { pub(crate) fn new( account: ReadOnlyAccount, identity: Arc>, - store: Arc>, + store: Arc, ) -> Self { Self { account, @@ -358,9 +358,9 @@ mod test { store.save_devices(vec![bob_device]).await; bob_store.save_devices(vec![alice_device.clone()]).await; - let bob_store: Arc> = Arc::new(Box::new(bob_store)); + let bob_store: Arc = Arc::new(bob_store); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id()))); - let machine = VerificationMachine::new(alice, identity, Arc::new(Box::new(store))); + let machine = VerificationMachine::new(alice, identity, Arc::new(store)); let (bob_sas, start_content) = Sas::start( bob, PrivateCrossSigningIdentity::empty(bob_id()), @@ -383,7 +383,7 @@ mod test { let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id()); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id()))); let store = MemoryStore::new(); - let _ = VerificationMachine::new(alice, identity, Arc::new(Box::new(store))); + let _ = VerificationMachine::new(alice, identity, Arc::new(store)); } #[tokio::test] diff --git a/matrix_sdk_crypto/src/verification/mod.rs b/matrix_sdk_crypto/src/verification/mod.rs index 3d74178e..d792d053 100644 --- a/matrix_sdk_crypto/src/verification/mod.rs +++ b/matrix_sdk_crypto/src/verification/mod.rs @@ -208,7 +208,7 @@ pub enum VerificationResult { #[derive(Clone, Debug)] pub struct IdentitiesBeingVerified { private_identity: PrivateCrossSigningIdentity, - store: Arc>, + store: Arc, device_being_verified: ReadOnlyDevice, identity_being_verified: Option, } diff --git a/matrix_sdk_crypto/src/verification/requests.rs b/matrix_sdk_crypto/src/verification/requests.rs index 77556ca9..acec84e2 100644 --- a/matrix_sdk_crypto/src/verification/requests.rs +++ b/matrix_sdk_crypto/src/verification/requests.rs @@ -68,7 +68,7 @@ impl VerificationRequest { cache: VerificationCache, account: ReadOnlyAccount, private_cross_signing_identity: PrivateCrossSigningIdentity, - store: Arc>, + store: Arc, room_id: &RoomId, event_id: &EventId, other_user: &UserId, @@ -99,7 +99,7 @@ impl VerificationRequest { cache: VerificationCache, account: ReadOnlyAccount, private_cross_signing_identity: PrivateCrossSigningIdentity, - store: Arc>, + store: Arc, other_user: &UserId, ) -> Self { let flow_id = Uuid::new_v4().to_string().into(); @@ -178,7 +178,7 @@ impl VerificationRequest { cache: VerificationCache, account: ReadOnlyAccount, private_cross_signing_identity: PrivateCrossSigningIdentity, - store: Arc>, + store: Arc, sender: &UserId, flow_id: FlowId, content: &RequestContent, @@ -377,7 +377,7 @@ struct RequestState { account: ReadOnlyAccount, private_cross_signing_identity: PrivateCrossSigningIdentity, verification_cache: VerificationCache, - store: Arc>, + store: Arc, flow_id: Arc, /// The id of the user which is participating in this verification request. @@ -418,7 +418,7 @@ impl RequestState { account: ReadOnlyAccount, private_identity: PrivateCrossSigningIdentity, cache: VerificationCache, - store: Arc>, + store: Arc, other_user_id: &UserId, flow_id: &FlowId, ) -> Self { @@ -479,7 +479,7 @@ impl RequestState { account: ReadOnlyAccount, private_identity: PrivateCrossSigningIdentity, cache: VerificationCache, - store: Arc>, + store: Arc, sender: &UserId, flow_id: &FlowId, content: &RequestContent, @@ -626,7 +626,7 @@ impl RequestState { fn start_sas( self, - store: Arc>, + store: Arc, account: ReadOnlyAccount, private_identity: PrivateCrossSigningIdentity, other_device: ReadOnlyDevice, diff --git a/matrix_sdk_crypto/src/verification/sas/mod.rs b/matrix_sdk_crypto/src/verification/sas/mod.rs index 889c9896..eb8be8d1 100644 --- a/matrix_sdk_crypto/src/verification/sas/mod.rs +++ b/matrix_sdk_crypto/src/verification/sas/mod.rs @@ -106,7 +106,7 @@ impl Sas { account: ReadOnlyAccount, private_identity: PrivateCrossSigningIdentity, other_device: ReadOnlyDevice, - store: Arc>, + store: Arc, other_identity: Option, ) -> Sas { let flow_id = inner_sas.verification_flow_id(); @@ -140,7 +140,7 @@ impl Sas { account: ReadOnlyAccount, private_identity: PrivateCrossSigningIdentity, other_device: ReadOnlyDevice, - store: Arc>, + store: Arc, other_identity: Option, transaction_id: Option, ) -> (Sas, OutgoingContent) { @@ -180,7 +180,7 @@ impl Sas { account: ReadOnlyAccount, private_identity: PrivateCrossSigningIdentity, other_device: ReadOnlyDevice, - store: Arc>, + store: Arc, other_identity: Option, ) -> (Sas, OutgoingContent) { let (inner, content) = InnerSas::start_in_room( @@ -218,7 +218,7 @@ impl Sas { pub(crate) fn from_start_event( flow_id: FlowId, content: &StartContent, - store: Arc>, + store: Arc, account: ReadOnlyAccount, private_identity: PrivateCrossSigningIdentity, other_device: ReadOnlyDevice, @@ -522,12 +522,12 @@ mod test { let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id()); let bob_device = ReadOnlyDevice::from_account(&bob).await; - let alice_store: Arc> = Arc::new(Box::new(MemoryStore::new())); + let alice_store: Arc = Arc::new(MemoryStore::new()); let bob_store = MemoryStore::new(); bob_store.save_devices(vec![alice_device.clone()]).await; - let bob_store: Arc> = Arc::new(Box::new(bob_store)); + let bob_store: Arc = Arc::new(bob_store); let (alice, content) = Sas::start( alice,