crytpo: Let the verification machine hold on to a raw CryptoStore.
This will later be useful when our higher level store wrapper holds on to a verification machine to return higher level Device objects.master
parent
d644af7be9
commit
c8ca93c924
|
@ -40,7 +40,7 @@ use crate::{
|
|||
error::{EventError, OlmError, OlmResult, SignatureError},
|
||||
identities::{OwnUserIdentity, UserIdentities},
|
||||
olm::Utility,
|
||||
store::{caches::ReadOnlyUserDevices, Result as StoreResult, Store},
|
||||
store::{caches::ReadOnlyUserDevices, CryptoStore, Result as StoreResult},
|
||||
verification::VerificationMachine,
|
||||
Sas, ToDeviceRequest,
|
||||
};
|
||||
|
@ -122,7 +122,7 @@ impl Device {
|
|||
content: Value,
|
||||
) -> OlmResult<EncryptedEventContent> {
|
||||
self.inner
|
||||
.encrypt(self.verification_machine.store.clone(), event_type, content)
|
||||
.encrypt(&**self.verification_machine.store, event_type, content)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ impl ReadOnlyDevice {
|
|||
|
||||
pub(crate) async fn encrypt(
|
||||
&self,
|
||||
store: Store,
|
||||
store: &dyn CryptoStore,
|
||||
event_type: EventType,
|
||||
content: Value,
|
||||
) -> OlmResult<EncryptedEventContent> {
|
||||
|
|
|
@ -381,7 +381,7 @@ pub(crate) mod test {
|
|||
|
||||
fn manager() -> IdentityManager {
|
||||
let user_id = Arc::new(user_id());
|
||||
let store = Store::new(user_id.clone(), Box::new(MemoryStore::new()));
|
||||
let store = Store::new(user_id.clone(), Arc::new(Box::new(MemoryStore::new())));
|
||||
IdentityManager::new(user_id, Arc::new(device_id()), store)
|
||||
}
|
||||
|
||||
|
|
|
@ -667,7 +667,7 @@ pub(crate) mod test {
|
|||
Device, ReadOnlyDevice,
|
||||
},
|
||||
olm::ReadOnlyAccount,
|
||||
store::{MemoryStore, Store},
|
||||
store::MemoryStore,
|
||||
verification::VerificationMachine,
|
||||
};
|
||||
|
||||
|
@ -736,10 +736,7 @@ pub(crate) mod test {
|
|||
|
||||
let verification_machine = VerificationMachine::new(
|
||||
ReadOnlyAccount::new(second.user_id(), second.device_id()),
|
||||
Store::new(
|
||||
Arc::new(second.user_id().clone()),
|
||||
Box::new(MemoryStore::new()),
|
||||
),
|
||||
Arc::new(Box::new(MemoryStore::new())),
|
||||
);
|
||||
|
||||
let first = Device {
|
||||
|
|
|
@ -93,9 +93,7 @@ impl Device {
|
|||
event_type: EventType,
|
||||
content: Value,
|
||||
) -> OlmResult<EncryptedEventContent> {
|
||||
self.inner
|
||||
.encrypt(self.store.clone(), event_type, content)
|
||||
.await
|
||||
self.inner.encrypt(&*self.store, event_type, content).await
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -651,7 +649,7 @@ mod test {
|
|||
|
||||
fn bob_machine() -> KeyRequestMachine {
|
||||
let user_id = Arc::new(bob_id());
|
||||
let store = Store::new(user_id.clone(), Box::new(MemoryStore::new()));
|
||||
let store = Store::new(user_id.clone(), Arc::new(Box::new(MemoryStore::new())));
|
||||
|
||||
KeyRequestMachine::new(
|
||||
user_id,
|
||||
|
@ -663,7 +661,7 @@ mod test {
|
|||
|
||||
fn get_machine() -> KeyRequestMachine {
|
||||
let user_id = Arc::new(alice_id());
|
||||
let store = Store::new(user_id.clone(), Box::new(MemoryStore::new()));
|
||||
let store = Store::new(user_id.clone(), Arc::new(Box::new(MemoryStore::new())));
|
||||
|
||||
KeyRequestMachine::new(
|
||||
user_id,
|
||||
|
|
|
@ -125,8 +125,9 @@ impl OlmMachine {
|
|||
) -> Self {
|
||||
let user_id = Arc::new(user_id.clone());
|
||||
|
||||
let store = Store::new(user_id.clone(), store);
|
||||
let store = Arc::new(store);
|
||||
let verification_machine = VerificationMachine::new(account.clone(), store.clone());
|
||||
let store = Store::new(user_id.clone(), store);
|
||||
let device_id: Arc<DeviceIdBox> = Arc::new(device_id);
|
||||
let outbound_group_sessions = Arc::new(DashMap::new());
|
||||
let key_request_machine = KeyRequestMachine::new(
|
||||
|
|
|
@ -93,10 +93,10 @@ pub(crate) struct Store {
|
|||
}
|
||||
|
||||
impl Store {
|
||||
pub fn new(user_id: Arc<UserId>, store: Box<dyn CryptoStore>) -> Self {
|
||||
pub fn new(user_id: Arc<UserId>, store: Arc<Box<dyn CryptoStore>>) -> Self {
|
||||
Self {
|
||||
user_id,
|
||||
inner: Arc::new(store),
|
||||
inner: store,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,20 +27,20 @@ use matrix_sdk_common::{
|
|||
use super::sas::{content_to_request, Sas};
|
||||
use crate::{
|
||||
requests::{OutgoingRequest, ToDeviceRequest},
|
||||
store::{CryptoStoreError, Store},
|
||||
store::{CryptoStore, CryptoStoreError},
|
||||
ReadOnlyAccount, ReadOnlyDevice,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct VerificationMachine {
|
||||
account: ReadOnlyAccount,
|
||||
pub(crate) store: Store,
|
||||
pub(crate) store: Arc<Box<dyn CryptoStore>>,
|
||||
verifications: Arc<DashMap<String, Sas>>,
|
||||
outgoing_to_device_messages: Arc<DashMap<Uuid, OutgoingRequest>>,
|
||||
}
|
||||
|
||||
impl VerificationMachine {
|
||||
pub(crate) fn new(account: ReadOnlyAccount, store: Store) -> Self {
|
||||
pub(crate) fn new(account: ReadOnlyAccount, store: Arc<Box<dyn CryptoStore>>) -> Self {
|
||||
Self {
|
||||
account,
|
||||
store,
|
||||
|
@ -233,7 +233,7 @@ mod test {
|
|||
use super::{Sas, VerificationMachine};
|
||||
use crate::{
|
||||
requests::OutgoingRequests,
|
||||
store::{CryptoStore, MemoryStore, Store},
|
||||
store::{CryptoStore, MemoryStore},
|
||||
verification::test::{get_content_from_request, wrap_any_to_device_content},
|
||||
ReadOnlyAccount, ReadOnlyDevice,
|
||||
};
|
||||
|
@ -258,7 +258,7 @@ mod test {
|
|||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let store = MemoryStore::new();
|
||||
let bob_store = Store::new(Arc::new(bob_id()), Box::new(MemoryStore::new()));
|
||||
let bob_store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new()));
|
||||
|
||||
let bob_device = ReadOnlyDevice::from_account(&bob).await;
|
||||
let alice_device = ReadOnlyDevice::from_account(&alice).await;
|
||||
|
@ -269,8 +269,7 @@ mod test {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
let machine =
|
||||
VerificationMachine::new(alice, Store::new(Arc::new(alice_id()), Box::new(store)));
|
||||
let machine = VerificationMachine::new(alice, Arc::new(Box::new(store)));
|
||||
let (bob_sas, start_content) = Sas::start(bob, alice_device, bob_store, None);
|
||||
machine
|
||||
.receive_event(&mut wrap_any_to_device_content(
|
||||
|
@ -286,9 +285,8 @@ mod test {
|
|||
#[test]
|
||||
fn create() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let user_id = Arc::new(alice_id());
|
||||
let store = MemoryStore::new();
|
||||
let _ = VerificationMachine::new(alice, Store::new(user_id, Box::new(store)));
|
||||
let _ = VerificationMachine::new(alice, Arc::new(Box::new(store)));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
|
|
@ -34,7 +34,7 @@ use matrix_sdk_common::{
|
|||
|
||||
use crate::{
|
||||
identities::{LocalTrust, ReadOnlyDevice, UserIdentities},
|
||||
store::{CryptoStoreError, Store},
|
||||
store::{CryptoStore, CryptoStoreError},
|
||||
ReadOnlyAccount, ToDeviceRequest,
|
||||
};
|
||||
|
||||
|
@ -47,7 +47,7 @@ use sas_state::{
|
|||
/// Short authentication string object.
|
||||
pub struct Sas {
|
||||
inner: Arc<Mutex<InnerSas>>,
|
||||
store: Store,
|
||||
store: Arc<Box<dyn CryptoStore>>,
|
||||
account: ReadOnlyAccount,
|
||||
other_device: ReadOnlyDevice,
|
||||
other_identity: Option<UserIdentities>,
|
||||
|
@ -104,7 +104,7 @@ impl Sas {
|
|||
pub(crate) fn start(
|
||||
account: ReadOnlyAccount,
|
||||
other_device: ReadOnlyDevice,
|
||||
store: Store,
|
||||
store: Arc<Box<dyn CryptoStore>>,
|
||||
other_identity: Option<UserIdentities>,
|
||||
) -> (Sas, StartEventContent) {
|
||||
let (inner, content) = InnerSas::start(
|
||||
|
@ -139,7 +139,7 @@ impl Sas {
|
|||
pub(crate) fn from_start_event(
|
||||
account: ReadOnlyAccount,
|
||||
other_device: ReadOnlyDevice,
|
||||
store: Store,
|
||||
store: Arc<Box<dyn CryptoStore>>,
|
||||
event: &ToDeviceEvent<StartEventContent>,
|
||||
other_identity: Option<UserIdentities>,
|
||||
) -> Result<Sas, AnyToDeviceEventContent> {
|
||||
|
@ -654,7 +654,7 @@ mod test {
|
|||
};
|
||||
|
||||
use crate::{
|
||||
store::{MemoryStore, Store},
|
||||
store::{CryptoStore, MemoryStore},
|
||||
verification::test::{get_content_from_request, wrap_any_to_device_content},
|
||||
ReadOnlyAccount, ReadOnlyDevice,
|
||||
};
|
||||
|
@ -776,8 +776,8 @@ mod test {
|
|||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let bob_device = ReadOnlyDevice::from_account(&bob).await;
|
||||
|
||||
let alice_store = Store::new(Arc::new(alice_id()), Box::new(MemoryStore::new()));
|
||||
let bob_store = Store::new(Arc::new(bob_id()), Box::new(MemoryStore::new()));
|
||||
let alice_store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new()));
|
||||
let bob_store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new()));
|
||||
|
||||
bob_store
|
||||
.save_devices(&[alice_device.clone()])
|
||||
|
|
Loading…
Reference in New Issue