Replace Arc<Box<dyn (Crypto|State)Store>> by Arc<dyn (Crypto|State)Store>

master
Jonas Platte 2021-06-06 18:16:25 +02:00
parent eed2b37885
commit 6b685b671d
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
13 changed files with 38 additions and 42 deletions

View File

@ -52,7 +52,7 @@ pub struct Room {
room_id: Arc<RoomId>, room_id: Arc<RoomId>,
own_user_id: Arc<UserId>, own_user_id: Arc<UserId>,
inner: Arc<SyncRwLock<RoomInfo>>, inner: Arc<SyncRwLock<RoomInfo>>,
store: Arc<Box<dyn StateStore>>, store: Arc<dyn StateStore>,
} }
/// The room summary containing member counts and members that should be used to /// The room summary containing member counts and members that should be used to
@ -83,7 +83,7 @@ pub enum RoomType {
impl Room { impl Room {
pub(crate) fn new( pub(crate) fn new(
own_user_id: &UserId, own_user_id: &UserId,
store: Arc<Box<dyn StateStore>>, store: Arc<dyn StateStore>,
room_id: &RoomId, room_id: &RoomId,
room_type: RoomType, room_type: RoomType,
) -> Self { ) -> Self {
@ -104,7 +104,7 @@ impl Room {
pub(crate) fn restore( pub(crate) fn restore(
own_user_id: &UserId, own_user_id: &UserId,
store: Arc<Box<dyn StateStore>>, store: Arc<dyn StateStore>,
room_info: RoomInfo, room_info: RoomInfo,
) -> Self { ) -> Self {
Self { Self {

View File

@ -289,7 +289,7 @@ pub trait StateStore: AsyncTraitDeps {
/// `StateStore` implementation. /// `StateStore` implementation.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Store { pub struct Store {
inner: Arc<Box<dyn StateStore>>, inner: Arc<dyn StateStore>,
pub(crate) session: Arc<RwLock<Option<Session>>>, pub(crate) session: Arc<RwLock<Option<Session>>>,
pub(crate) sync_token: Arc<RwLock<Option<String>>>, pub(crate) sync_token: Arc<RwLock<Option<String>>>,
rooms: Arc<DashMap<RoomId, Room>>, rooms: Arc<DashMap<RoomId, Room>>,
@ -405,10 +405,10 @@ impl Store {
} }
impl Deref for Store { impl Deref for Store {
type Target = Box<dyn StateStore>; type Target = dyn StateStore;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.inner &*self.inner
} }
} }

View File

@ -184,7 +184,7 @@ impl Device {
event_type: EventType, event_type: EventType,
content: Value, content: Value,
) -> OlmResult<(Session, EncryptedEventContent)> { ) -> 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 /// Encrypt the given inbound group session as a forwarded room key for this

View File

@ -423,14 +423,10 @@ pub(crate) mod test {
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id()))); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id())));
let user_id = Arc::new(user_id()); let user_id = Arc::new(user_id());
let account = ReadOnlyAccount::new(&user_id, &device_id()); let account = ReadOnlyAccount::new(&user_id, &device_id());
let store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new())); let store: Arc<dyn CryptoStore> = Arc::new(MemoryStore::new());
let verification = VerificationMachine::new(account, identity.clone(), store); let verification = VerificationMachine::new(account, identity.clone(), store);
let store = Store::new( let store =
user_id.clone(), Store::new(user_id.clone(), identity, Arc::new(MemoryStore::new()), verification);
identity,
Arc::new(Box::new(MemoryStore::new())),
verification,
);
IdentityManager::new(user_id, device_id().into(), store) IdentityManager::new(user_id, device_id().into(), store)
} }

View File

@ -758,7 +758,7 @@ pub(crate) mod test {
let verification_machine = VerificationMachine::new( let verification_machine = VerificationMachine::new(
ReadOnlyAccount::new(second.user_id(), second.device_id()), ReadOnlyAccount::new(second.user_id(), second.device_id()),
private_identity.clone(), private_identity.clone(),
Arc::new(Box::new(MemoryStore::new())), Arc::new(MemoryStore::new()),
); );
let first = Device { let first = Device {
@ -801,7 +801,7 @@ pub(crate) mod test {
let verification_machine = VerificationMachine::new( let verification_machine = VerificationMachine::new(
ReadOnlyAccount::new(device.user_id(), device.device_id()), ReadOnlyAccount::new(device.user_id(), device.device_id()),
id.clone(), id.clone(),
Arc::new(Box::new(MemoryStore::new())), Arc::new(MemoryStore::new()),
); );
let public_identity = identity.as_public_identity().await.unwrap(); let public_identity = identity.as_public_identity().await.unwrap();

View File

@ -846,7 +846,7 @@ mod test {
fn bob_machine() -> KeyRequestMachine { fn bob_machine() -> KeyRequestMachine {
let user_id = Arc::new(bob_id()); let user_id = Arc::new(bob_id());
let account = ReadOnlyAccount::new(&user_id, &alice_device_id()); let account = ReadOnlyAccount::new(&user_id, &alice_device_id());
let store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new())); let store: Arc<dyn CryptoStore> = Arc::new(MemoryStore::new());
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(bob_id()))); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(bob_id())));
let verification = VerificationMachine::new(account, identity.clone(), store.clone()); let verification = VerificationMachine::new(account, identity.clone(), store.clone());
let store = Store::new(user_id.clone(), identity, store, verification); let store = Store::new(user_id.clone(), identity, store, verification);
@ -865,7 +865,7 @@ mod test {
let user_id: Arc<UserId> = alice_id().into(); let user_id: Arc<UserId> = alice_id().into();
let account = ReadOnlyAccount::new(&user_id, &alice_device_id()); let account = ReadOnlyAccount::new(&user_id, &alice_device_id());
let device = ReadOnlyDevice::from_account(&account).await; let device = ReadOnlyDevice::from_account(&account).await;
let store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new())); let store: Arc<dyn CryptoStore> = Arc::new(MemoryStore::new());
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id()))); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id())));
let verification = VerificationMachine::new(account, identity.clone(), store.clone()); let verification = VerificationMachine::new(account, identity.clone(), store.clone());
let store = Store::new(user_id.clone(), identity, store, verification); let store = Store::new(user_id.clone(), identity, store, verification);

View File

@ -144,7 +144,7 @@ impl OlmMachine {
let user_id = Arc::new(user_id.clone()); let user_id = Arc::new(user_id.clone());
let user_identity = Arc::new(Mutex::new(user_identity)); let user_identity = Arc::new(Mutex::new(user_identity));
let store = Arc::new(store); let store: Arc<dyn CryptoStore> = store.into();
let verification_machine = let verification_machine =
VerificationMachine::new(account.clone(), user_identity.clone(), store.clone()); VerificationMachine::new(account.clone(), user_identity.clone(), store.clone());
let store = let store =

View File

@ -332,7 +332,7 @@ mod test {
let users_for_key_claim = Arc::new(DashMap::new()); let users_for_key_claim = Arc::new(DashMap::new());
let account = ReadOnlyAccount::new(&user_id, &device_id); let account = ReadOnlyAccount::new(&user_id, &device_id);
let store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new())); let store: Arc<dyn CryptoStore> = Arc::new(MemoryStore::new());
store.save_account(account.clone()).await.unwrap(); store.save_account(account.clone()).await.unwrap();
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id.clone()))); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id.clone())));
let verification = let verification =

View File

@ -94,7 +94,7 @@ pub type Result<T, E = CryptoStoreError> = std::result::Result<T, E>;
pub(crate) struct Store { pub(crate) struct Store {
user_id: Arc<UserId>, user_id: Arc<UserId>,
identity: Arc<Mutex<PrivateCrossSigningIdentity>>, identity: Arc<Mutex<PrivateCrossSigningIdentity>>,
inner: Arc<Box<dyn CryptoStore>>, inner: Arc<dyn CryptoStore>,
verification_machine: VerificationMachine, verification_machine: VerificationMachine,
} }
@ -140,7 +140,7 @@ impl Store {
pub fn new( pub fn new(
user_id: Arc<UserId>, user_id: Arc<UserId>,
identity: Arc<Mutex<PrivateCrossSigningIdentity>>, identity: Arc<Mutex<PrivateCrossSigningIdentity>>,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
verification_machine: VerificationMachine, verification_machine: VerificationMachine,
) -> Self { ) -> Self {
Self { user_id, identity, inner: store, verification_machine } Self { user_id, identity, inner: store, verification_machine }
@ -238,7 +238,7 @@ impl Deref for Store {
type Target = dyn CryptoStore; type Target = dyn CryptoStore;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&**self.inner &*self.inner
} }
} }

View File

@ -40,7 +40,7 @@ use crate::{
pub struct VerificationMachine { pub struct VerificationMachine {
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_identity: Arc<Mutex<PrivateCrossSigningIdentity>>, private_identity: Arc<Mutex<PrivateCrossSigningIdentity>>,
pub(crate) store: Arc<Box<dyn CryptoStore>>, pub(crate) store: Arc<dyn CryptoStore>,
verifications: VerificationCache, verifications: VerificationCache,
requests: Arc<DashMap<String, VerificationRequest>>, requests: Arc<DashMap<String, VerificationRequest>>,
} }
@ -49,7 +49,7 @@ impl VerificationMachine {
pub(crate) fn new( pub(crate) fn new(
account: ReadOnlyAccount, account: ReadOnlyAccount,
identity: Arc<Mutex<PrivateCrossSigningIdentity>>, identity: Arc<Mutex<PrivateCrossSigningIdentity>>,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
) -> Self { ) -> Self {
Self { Self {
account, account,
@ -358,9 +358,9 @@ mod test {
store.save_devices(vec![bob_device]).await; store.save_devices(vec![bob_device]).await;
bob_store.save_devices(vec![alice_device.clone()]).await; bob_store.save_devices(vec![alice_device.clone()]).await;
let bob_store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(bob_store)); let bob_store: Arc<dyn CryptoStore> = Arc::new(bob_store);
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id()))); 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( let (bob_sas, start_content) = Sas::start(
bob, bob,
PrivateCrossSigningIdentity::empty(bob_id()), PrivateCrossSigningIdentity::empty(bob_id()),
@ -383,7 +383,7 @@ mod test {
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id()); let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id()))); let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id())));
let store = MemoryStore::new(); let store = MemoryStore::new();
let _ = VerificationMachine::new(alice, identity, Arc::new(Box::new(store))); let _ = VerificationMachine::new(alice, identity, Arc::new(store));
} }
#[tokio::test] #[tokio::test]

View File

@ -208,7 +208,7 @@ pub enum VerificationResult {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct IdentitiesBeingVerified { pub struct IdentitiesBeingVerified {
private_identity: PrivateCrossSigningIdentity, private_identity: PrivateCrossSigningIdentity,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
device_being_verified: ReadOnlyDevice, device_being_verified: ReadOnlyDevice,
identity_being_verified: Option<UserIdentities>, identity_being_verified: Option<UserIdentities>,
} }

View File

@ -68,7 +68,7 @@ impl VerificationRequest {
cache: VerificationCache, cache: VerificationCache,
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_cross_signing_identity: PrivateCrossSigningIdentity, private_cross_signing_identity: PrivateCrossSigningIdentity,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
room_id: &RoomId, room_id: &RoomId,
event_id: &EventId, event_id: &EventId,
other_user: &UserId, other_user: &UserId,
@ -99,7 +99,7 @@ impl VerificationRequest {
cache: VerificationCache, cache: VerificationCache,
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_cross_signing_identity: PrivateCrossSigningIdentity, private_cross_signing_identity: PrivateCrossSigningIdentity,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
other_user: &UserId, other_user: &UserId,
) -> Self { ) -> Self {
let flow_id = Uuid::new_v4().to_string().into(); let flow_id = Uuid::new_v4().to_string().into();
@ -178,7 +178,7 @@ impl VerificationRequest {
cache: VerificationCache, cache: VerificationCache,
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_cross_signing_identity: PrivateCrossSigningIdentity, private_cross_signing_identity: PrivateCrossSigningIdentity,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
sender: &UserId, sender: &UserId,
flow_id: FlowId, flow_id: FlowId,
content: &RequestContent, content: &RequestContent,
@ -377,7 +377,7 @@ struct RequestState<S: Clone> {
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_cross_signing_identity: PrivateCrossSigningIdentity, private_cross_signing_identity: PrivateCrossSigningIdentity,
verification_cache: VerificationCache, verification_cache: VerificationCache,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
flow_id: Arc<FlowId>, flow_id: Arc<FlowId>,
/// The id of the user which is participating in this verification request. /// The id of the user which is participating in this verification request.
@ -418,7 +418,7 @@ impl RequestState<Created> {
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_identity: PrivateCrossSigningIdentity, private_identity: PrivateCrossSigningIdentity,
cache: VerificationCache, cache: VerificationCache,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
other_user_id: &UserId, other_user_id: &UserId,
flow_id: &FlowId, flow_id: &FlowId,
) -> Self { ) -> Self {
@ -479,7 +479,7 @@ impl RequestState<Requested> {
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_identity: PrivateCrossSigningIdentity, private_identity: PrivateCrossSigningIdentity,
cache: VerificationCache, cache: VerificationCache,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
sender: &UserId, sender: &UserId,
flow_id: &FlowId, flow_id: &FlowId,
content: &RequestContent, content: &RequestContent,
@ -626,7 +626,7 @@ impl RequestState<Ready> {
fn start_sas( fn start_sas(
self, self,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_identity: PrivateCrossSigningIdentity, private_identity: PrivateCrossSigningIdentity,
other_device: ReadOnlyDevice, other_device: ReadOnlyDevice,

View File

@ -106,7 +106,7 @@ impl Sas {
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_identity: PrivateCrossSigningIdentity, private_identity: PrivateCrossSigningIdentity,
other_device: ReadOnlyDevice, other_device: ReadOnlyDevice,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
other_identity: Option<UserIdentities>, other_identity: Option<UserIdentities>,
) -> Sas { ) -> Sas {
let flow_id = inner_sas.verification_flow_id(); let flow_id = inner_sas.verification_flow_id();
@ -140,7 +140,7 @@ impl Sas {
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_identity: PrivateCrossSigningIdentity, private_identity: PrivateCrossSigningIdentity,
other_device: ReadOnlyDevice, other_device: ReadOnlyDevice,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
other_identity: Option<UserIdentities>, other_identity: Option<UserIdentities>,
transaction_id: Option<String>, transaction_id: Option<String>,
) -> (Sas, OutgoingContent) { ) -> (Sas, OutgoingContent) {
@ -180,7 +180,7 @@ impl Sas {
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_identity: PrivateCrossSigningIdentity, private_identity: PrivateCrossSigningIdentity,
other_device: ReadOnlyDevice, other_device: ReadOnlyDevice,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
other_identity: Option<UserIdentities>, other_identity: Option<UserIdentities>,
) -> (Sas, OutgoingContent) { ) -> (Sas, OutgoingContent) {
let (inner, content) = InnerSas::start_in_room( let (inner, content) = InnerSas::start_in_room(
@ -218,7 +218,7 @@ impl Sas {
pub(crate) fn from_start_event( pub(crate) fn from_start_event(
flow_id: FlowId, flow_id: FlowId,
content: &StartContent, content: &StartContent,
store: Arc<Box<dyn CryptoStore>>, store: Arc<dyn CryptoStore>,
account: ReadOnlyAccount, account: ReadOnlyAccount,
private_identity: PrivateCrossSigningIdentity, private_identity: PrivateCrossSigningIdentity,
other_device: ReadOnlyDevice, other_device: ReadOnlyDevice,
@ -522,12 +522,12 @@ mod test {
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id()); let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
let bob_device = ReadOnlyDevice::from_account(&bob).await; let bob_device = ReadOnlyDevice::from_account(&bob).await;
let alice_store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new())); let alice_store: Arc<dyn CryptoStore> = Arc::new(MemoryStore::new());
let bob_store = MemoryStore::new(); let bob_store = MemoryStore::new();
bob_store.save_devices(vec![alice_device.clone()]).await; bob_store.save_devices(vec![alice_device.clone()]).await;
let bob_store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(bob_store)); let bob_store: Arc<dyn CryptoStore> = Arc::new(bob_store);
let (alice, content) = Sas::start( let (alice, content) = Sas::start(
alice, alice,