diff --git a/matrix_sdk/src/device.rs b/matrix_sdk/src/device.rs index c3ebbb41..a7958294 100644 --- a/matrix_sdk/src/device.rs +++ b/matrix_sdk/src/device.rs @@ -14,7 +14,7 @@ use std::ops::Deref; -use matrix_sdk_base::{Device as ReadOnlyDevice, DeviceWrap, UserDevicesWrap}; +use matrix_sdk_base::{DeviceWrap, ReadOnlyDevice, UserDevicesWrap}; use matrix_sdk_common::{ api::r0::to_device::send_event_to_device::Request as ToDeviceRequest, identifiers::DeviceId, }; diff --git a/matrix_sdk/src/sas.rs b/matrix_sdk/src/sas.rs index b1dca584..3092c5aa 100644 --- a/matrix_sdk/src/sas.rs +++ b/matrix_sdk/src/sas.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use matrix_sdk_base::{Device, Sas as BaseSas}; +use matrix_sdk_base::{ReadOnlyDevice, Sas as BaseSas}; use matrix_sdk_common::api::r0::to_device::send_event_to_device::Request as ToDeviceRequest; use crate::{error::Result, http_client::HttpClient}; @@ -89,7 +89,7 @@ impl Sas { } /// Get the other users device that we're veryfying. - pub fn other_device(&self) -> Device { + pub fn other_device(&self) -> ReadOnlyDevice { self.inner.other_device() } } diff --git a/matrix_sdk_base/src/lib.rs b/matrix_sdk_base/src/lib.rs index 633aa3f4..90003ca3 100644 --- a/matrix_sdk_base/src/lib.rs +++ b/matrix_sdk_base/src/lib.rs @@ -57,7 +57,7 @@ pub use state::{AllRooms, ClientState}; #[cfg(feature = "encryption")] #[cfg_attr(feature = "docs", doc(cfg(encryption)))] pub use matrix_sdk_crypto::{ - CryptoStoreError, Device, DeviceWrap, Sas, TrustState, UserDevicesWrap, + CryptoStoreError, DeviceWrap, ReadOnlyDevice, Sas, TrustState, UserDevicesWrap, }; #[cfg(feature = "messages")] diff --git a/matrix_sdk_crypto/src/device.rs b/matrix_sdk_crypto/src/device.rs index 5b4850ec..152e319f 100644 --- a/matrix_sdk_crypto/src/device.rs +++ b/matrix_sdk_crypto/src/device.rs @@ -41,7 +41,7 @@ use crate::{ /// A device represents a E2EE capable client of an user. #[derive(Debug, Clone)] -pub struct Device { +pub struct ReadOnlyDevice { user_id: Arc, device_id: Arc>, algorithms: Arc>, @@ -55,12 +55,12 @@ pub struct Device { #[derive(Debug, Clone)] /// A device represents a E2EE capable client of an user. pub struct DeviceWrap { - pub(crate) inner: Device, + pub(crate) inner: ReadOnlyDevice, pub(crate) verification_machine: VerificationMachine, } impl Deref for DeviceWrap { - type Target = Device; + type Target = ReadOnlyDevice; fn deref(&self) -> &Self::Target { &self.inner @@ -133,7 +133,7 @@ impl From for TrustState { } } -impl Device { +impl ReadOnlyDevice { /// Create a new Device. pub fn new( user_id: UserId, @@ -144,7 +144,7 @@ impl Device { keys: BTreeMap, signatures: BTreeMap>, ) -> Self { - Device { + Self { user_id: Arc::new(user_id), device_id: Arc::new(device_id), display_name: Arc::new(display_name), @@ -285,22 +285,22 @@ impl Device { } #[cfg(test)] - pub async fn from_machine(machine: &OlmMachine) -> Device { - Device::from_account(machine.account()).await + pub async fn from_machine(machine: &OlmMachine) -> ReadOnlyDevice { + ReadOnlyDevice::from_account(machine.account()).await } #[cfg(test)] - pub async fn from_account(account: &Account) -> Device { + pub async fn from_account(account: &Account) -> ReadOnlyDevice { let device_keys = account.device_keys().await; - Device::try_from(&device_keys).unwrap() + ReadOnlyDevice::try_from(&device_keys).unwrap() } } -impl TryFrom<&DeviceKeys> for Device { +impl TryFrom<&DeviceKeys> for ReadOnlyDevice { type Error = SignatureError; fn try_from(device_keys: &DeviceKeys) -> Result { - let device = Device { + let device = Self { user_id: Arc::new(device_keys.user_id.clone()), device_id: Arc::new(device_keys.device_id.clone()), algorithms: Arc::new(device_keys.algorithms.clone()), @@ -322,7 +322,7 @@ impl TryFrom<&DeviceKeys> for Device { } } -impl PartialEq for Device { +impl PartialEq for ReadOnlyDevice { fn eq(&self, other: &Self) -> bool { self.user_id() == other.user_id() && self.device_id() == other.device_id() } @@ -333,7 +333,7 @@ pub(crate) mod test { use serde_json::json; use std::convert::TryFrom; - use crate::device::{Device, TrustState}; + use crate::device::{ReadOnlyDevice, TrustState}; use matrix_sdk_common::{ encryption::DeviceKeys, identifiers::{user_id, DeviceKeyAlgorithm}, @@ -364,9 +364,9 @@ pub(crate) mod test { serde_json::from_value(device_keys).unwrap() } - pub(crate) fn get_device() -> Device { + pub(crate) fn get_device() -> ReadOnlyDevice { let device_keys = device_keys(); - Device::try_from(&device_keys).unwrap() + ReadOnlyDevice::try_from(&device_keys).unwrap() } #[test] diff --git a/matrix_sdk_crypto/src/lib.rs b/matrix_sdk_crypto/src/lib.rs index 6147b978..17a6cef9 100644 --- a/matrix_sdk_crypto/src/lib.rs +++ b/matrix_sdk_crypto/src/lib.rs @@ -37,7 +37,7 @@ mod store; mod user_identity; mod verification; -pub use device::{Device, DeviceWrap, TrustState, UserDevicesWrap}; +pub use device::{DeviceWrap, ReadOnlyDevice, TrustState, UserDevicesWrap}; pub use error::{MegolmError, OlmError}; pub use machine::{OlmMachine, OneTimeKeys}; pub use memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}; diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 1a23513f..9d0a5c47 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -53,7 +53,7 @@ use matrix_sdk_common::{ #[cfg(feature = "sqlite_cryptostore")] use super::store::sqlite::SqliteStore; use super::{ - device::{Device, DeviceWrap, UserDevicesWrap}, + device::{DeviceWrap, ReadOnlyDevice, UserDevicesWrap}, error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult}, olm::{ Account, EncryptionSettings, GroupSessionKey, IdentityKeys, InboundGroupSession, @@ -370,7 +370,7 @@ impl OlmMachine { for (user_id, user_devices) in &response.one_time_keys { for (device_id, key_map) in user_devices { - let device: Device = match self.store.get_device(&user_id, device_id).await { + let device = match self.store.get_device(&user_id, device_id).await { Ok(Some(d)) => d, Ok(None) => { warn!( @@ -425,7 +425,7 @@ impl OlmMachine { async fn handle_devices_from_key_query( &self, device_keys_map: &BTreeMap, DeviceKeys>>, - ) -> StoreResult> { + ) -> StoreResult> { let mut changed_devices = Vec::new(); for (user_id, device_map) in device_keys_map { @@ -457,7 +457,7 @@ impl OlmMachine { } device } else { - let device = match Device::try_from(device_keys) { + let device = match ReadOnlyDevice::try_from(device_keys) { Ok(d) => d, Err(e) => { warn!( @@ -504,7 +504,7 @@ impl OlmMachine { pub async fn receive_keys_query_response( &self, response: &get_keys::Response, - ) -> OlmResult> { + ) -> OlmResult> { let changed_devices = self .handle_devices_from_key_query(&response.device_keys) .await?; @@ -920,7 +920,7 @@ impl OlmMachine { /// * `content` - The content of the event that should be encrypted. async fn olm_encrypt( &self, - recipient_device: &Device, + recipient_device: &ReadOnlyDevice, event_type: EventType, content: Value, ) -> OlmResult { @@ -1395,7 +1395,7 @@ pub(crate) mod test { use crate::{ machine::{OlmMachine, OneTimeKeys}, verification::test::request_to_event, - verify_json, Device, EncryptionSettings, + verify_json, EncryptionSettings, ReadOnlyDevice, }; use matrix_sdk_common::{ @@ -1498,8 +1498,8 @@ pub(crate) mod test { let alice_device = alice_device_id(); let alice = OlmMachine::new(&alice_id, &alice_device); - let alice_deivce = Device::from_machine(&alice).await; - let bob_device = Device::from_machine(&bob).await; + let alice_deivce = ReadOnlyDevice::from_machine(&alice).await; + let bob_device = ReadOnlyDevice::from_machine(&bob).await; alice.store.save_devices(&[bob_device]).await.unwrap(); bob.store.save_devices(&[alice_deivce]).await.unwrap(); diff --git a/matrix_sdk_crypto/src/memory_stores.rs b/matrix_sdk_crypto/src/memory_stores.rs index 2bceb1dc..19a3fad6 100644 --- a/matrix_sdk_crypto/src/memory_stores.rs +++ b/matrix_sdk_crypto/src/memory_stores.rs @@ -21,7 +21,7 @@ use matrix_sdk_common::{ }; use super::{ - device::Device, + device::ReadOnlyDevice, olm::{InboundGroupSession, Session}, }; @@ -134,18 +134,18 @@ impl GroupSessionStore { /// In-memory store holding the devices of users. #[derive(Clone, Debug, Default)] pub struct DeviceStore { - entries: Arc, Device>>>, + entries: Arc, ReadOnlyDevice>>>, } /// A read only view over all devices belonging to a user. #[derive(Debug)] pub struct UserDevices { - entries: ReadOnlyView, Device>, + entries: ReadOnlyView, ReadOnlyDevice>, } impl UserDevices { /// Get the specific device with the given device id. - pub fn get(&self, device_id: &DeviceId) -> Option { + pub fn get(&self, device_id: &DeviceId) -> Option { self.entries.get(device_id).cloned() } @@ -155,7 +155,7 @@ impl UserDevices { } /// Iterator over all the devices of the user devices. - pub fn devices(&self) -> impl Iterator { + pub fn devices(&self) -> impl Iterator { self.entries.values() } } @@ -171,7 +171,7 @@ impl DeviceStore { /// Add a device to the store. /// /// Returns true if the device was already in the store, false otherwise. - pub fn add(&self, device: Device) -> bool { + pub fn add(&self, device: ReadOnlyDevice) -> bool { let user_id = device.user_id(); if !self.entries.contains_key(&user_id) { @@ -185,7 +185,7 @@ impl DeviceStore { } /// Get the device with the given device_id and belonging to the given user. - pub fn get(&self, user_id: &UserId, device_id: &DeviceId) -> Option { + pub fn get(&self, user_id: &UserId, device_id: &DeviceId) -> Option { self.entries .get(user_id) .and_then(|m| m.get(device_id).map(|d| d.value().clone())) @@ -194,7 +194,7 @@ impl DeviceStore { /// Remove the device with the given device_id and belonging to the given user. /// /// Returns the device if it was removed, None if it wasn't in the store. - pub fn remove(&self, user_id: &UserId, device_id: &DeviceId) -> Option { + pub fn remove(&self, user_id: &UserId, device_id: &DeviceId) -> Option { self.entries .get(user_id) .and_then(|m| m.remove(device_id)) diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index a41bb93b..2e60b493 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -45,7 +45,7 @@ pub use olm_rs::{ }; use super::{EncryptionSettings, InboundGroupSession, OutboundGroupSession, Session}; -use crate::{device::Device, error::SessionCreationError}; +use crate::{device::ReadOnlyDevice, error::SessionCreationError}; /// Account holding identity keys for which sessions can be created. /// @@ -436,7 +436,7 @@ impl Account { /// key that the other account created and shared with us. pub(crate) async fn create_outbound_session( &self, - device: Device, + device: ReadOnlyDevice, key_map: &BTreeMap, ) -> Result { let one_time_key = key_map.values().next().ok_or_else(|| { diff --git a/matrix_sdk_crypto/src/olm/session.rs b/matrix_sdk_crypto/src/olm/session.rs index a4f31a32..01191e75 100644 --- a/matrix_sdk_crypto/src/olm/session.rs +++ b/matrix_sdk_crypto/src/olm/session.rs @@ -29,7 +29,7 @@ use serde_json::{json, Value}; use super::IdentityKeys; use crate::{ error::{EventError, OlmResult}, - Device, + ReadOnlyDevice, }; pub use olm_rs::{ @@ -103,7 +103,7 @@ impl Session { /// * `content` - The content of the event. pub async fn encrypt( &mut self, - recipient_device: &Device, + recipient_device: &ReadOnlyDevice, event_type: EventType, content: Value, ) -> OlmResult { diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index 1c76ca73..151dc0f9 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -23,7 +23,7 @@ use matrix_sdk_common::{ use super::{Account, CryptoStore, InboundGroupSession, Result, Session}; use crate::{ - device::Device, + device::ReadOnlyDevice, memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}, }; #[derive(Debug, Clone)] @@ -107,11 +107,15 @@ impl CryptoStore for MemoryStore { Ok(self.tracked_users.insert(user.clone())) } - async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result> { + async fn get_device( + &self, + user_id: &UserId, + device_id: &DeviceId, + ) -> Result> { Ok(self.devices.get(user_id, device_id)) } - async fn delete_device(&self, device: Device) -> Result<()> { + async fn delete_device(&self, device: ReadOnlyDevice) -> Result<()> { let _ = self.devices.remove(device.user_id(), device.device_id()); Ok(()) } @@ -120,7 +124,7 @@ impl CryptoStore for MemoryStore { Ok(self.devices.user_devices(user_id)) } - async fn save_devices(&self, devices: &[Device]) -> Result<()> { + async fn save_devices(&self, devices: &[ReadOnlyDevice]) -> Result<()> { for device in devices { let _ = self.devices.add(device.clone()); } diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index f4dc7e94..991a39ed 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -27,7 +27,7 @@ use thiserror::Error; use url::ParseError; use super::{ - device::Device, + device::ReadOnlyDevice, memory_stores::UserDevices, olm::{Account, InboundGroupSession, Session}, }; @@ -169,14 +169,14 @@ pub trait CryptoStore: Debug { /// # Arguments /// /// * `device` - The device that should be stored. - async fn save_devices(&self, devices: &[Device]) -> Result<()>; + async fn save_devices(&self, devices: &[ReadOnlyDevice]) -> Result<()>; /// Delete the given device from the store. /// /// # Arguments /// /// * `device` - The device that should be stored. - async fn delete_device(&self, device: Device) -> Result<()>; + async fn delete_device(&self, device: ReadOnlyDevice) -> Result<()>; /// Get the device for the given user with the given device id. /// @@ -185,7 +185,11 @@ pub trait CryptoStore: Debug { /// * `user_id` - The user that the device belongs to. /// /// * `device_id` - The unique id of the device. - async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result>; + async fn get_device( + &self, + user_id: &UserId, + device_id: &DeviceId, + ) -> Result>; /// Get all the devices of the given user. /// diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 6c5a62ea..10079b05 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -36,7 +36,7 @@ use zeroize::Zeroizing; use super::{CryptoStore, CryptoStoreError, Result}; use crate::{ - device::{Device, TrustState}, + device::{ReadOnlyDevice, TrustState}, memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}, Account, IdentityKeys, InboundGroupSession, Session, }; @@ -556,7 +556,7 @@ impl SqliteStore { ); } - let device = Device::new( + let device = ReadOnlyDevice::new( user_id, device_id.as_str().into(), display_name.clone(), @@ -572,7 +572,7 @@ impl SqliteStore { Ok(()) } - async fn save_device_helper(&self, device: Device) -> Result<()> { + async fn save_device_helper(&self, device: ReadOnlyDevice) -> Result<()> { let account_id = self.account_id().ok_or(CryptoStoreError::AccountUnset)?; let mut connection = self.connection.lock().await; @@ -844,7 +844,7 @@ impl CryptoStore for SqliteStore { Ok(already_added) } - async fn save_devices(&self, devices: &[Device]) -> Result<()> { + async fn save_devices(&self, devices: &[ReadOnlyDevice]) -> Result<()> { // TODO turn this into a bulk transaction. for device in devices { self.devices.add(device.clone()); @@ -854,7 +854,7 @@ impl CryptoStore for SqliteStore { Ok(()) } - async fn delete_device(&self, device: Device) -> Result<()> { + async fn delete_device(&self, device: ReadOnlyDevice) -> Result<()> { let account_id = self.account_id().ok_or(CryptoStoreError::AccountUnset)?; let mut connection = self.connection.lock().await; @@ -872,8 +872,11 @@ impl CryptoStore for SqliteStore { Ok(()) } - #[allow(clippy::ptr_arg)] - async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result> { + async fn get_device( + &self, + user_id: &UserId, + device_id: &DeviceId, + ) -> Result> { Ok(self.devices.get(user_id, device_id)) } diff --git a/matrix_sdk_crypto/src/user_identity.rs b/matrix_sdk_crypto/src/user_identity.rs index 1b9032ac..77f349d0 100644 --- a/matrix_sdk_crypto/src/user_identity.rs +++ b/matrix_sdk_crypto/src/user_identity.rs @@ -24,7 +24,7 @@ use matrix_sdk_common::{ identifiers::{DeviceKeyId, UserId}, }; -use crate::{error::SignatureError, verify_json, Device}; +use crate::{error::SignatureError, verify_json, ReadOnlyDevice}; #[derive(Debug, Clone)] pub struct MasterPubkey(Arc); @@ -132,7 +132,7 @@ impl UserSigningPubkey { } impl SelfSigningPubkey { - fn verify_device(&self, device: &Device) -> Result<(), SignatureError> { + fn verify_device(&self, device: &ReadOnlyDevice) -> Result<(), SignatureError> { let (key_id, key) = self .0 .keys @@ -165,7 +165,7 @@ impl UserIdentity { }) } - pub fn is_device_signed(&self, device: &Device) -> Result<(), SignatureError> { + pub fn is_device_signed(&self, device: &ReadOnlyDevice) -> Result<(), SignatureError> { self.self_signing_key.verify_device(device) } } diff --git a/matrix_sdk_crypto/src/verification/machine.rs b/matrix_sdk_crypto/src/verification/machine.rs index a9085a2b..e4e7575d 100644 --- a/matrix_sdk_crypto/src/verification/machine.rs +++ b/matrix_sdk_crypto/src/verification/machine.rs @@ -25,7 +25,7 @@ use matrix_sdk_common::{ }; use super::sas::{content_to_request, Sas}; -use crate::{Account, CryptoStore, CryptoStoreError, Device}; +use crate::{Account, CryptoStore, CryptoStoreError, ReadOnlyDevice}; #[derive(Clone, Debug)] pub struct VerificationMachine { @@ -45,7 +45,7 @@ impl VerificationMachine { } } - pub fn start_sas(&self, device: Device) -> (Sas, OwnedToDeviceRequest) { + pub fn start_sas(&self, device: ReadOnlyDevice) -> (Sas, OwnedToDeviceRequest) { let (sas, content) = Sas::start(self.account.clone(), device.clone(), self.store.clone()); let request = content_to_request( device.user_id(), @@ -196,7 +196,7 @@ mod test { use crate::{ store::memorystore::MemoryStore, verification::test::{get_content_from_request, wrap_any_to_device_content}, - Account, CryptoStore, Device, + Account, CryptoStore, ReadOnlyDevice, }; fn alice_id() -> UserId { @@ -221,8 +221,8 @@ mod test { let store = MemoryStore::new(); let bob_store: Arc> = Arc::new(Box::new(MemoryStore::new())); - let bob_device = Device::from_account(&bob).await; - let alice_device = Device::from_account(&alice).await; + let bob_device = ReadOnlyDevice::from_account(&bob).await; + let alice_device = ReadOnlyDevice::from_account(&alice).await; store.save_devices(&[bob_device]).await.unwrap(); bob_store diff --git a/matrix_sdk_crypto/src/verification/sas/helpers.rs b/matrix_sdk_crypto/src/verification/sas/helpers.rs index c5aaf17b..ac364ba7 100644 --- a/matrix_sdk_crypto/src/verification/sas/helpers.rs +++ b/matrix_sdk_crypto/src/verification/sas/helpers.rs @@ -30,12 +30,12 @@ use matrix_sdk_common::{ uuid::Uuid, }; -use crate::{Account, Device}; +use crate::{Account, ReadOnlyDevice}; #[derive(Clone, Debug)] pub struct SasIds { pub account: Account, - pub other_device: Device, + pub other_device: ReadOnlyDevice, } /// Get a tuple of an emoji and a description of the emoji using a number. @@ -158,7 +158,7 @@ pub fn receive_mac_event( ids: &SasIds, flow_id: &str, event: &ToDeviceEvent, -) -> Result<(Vec, Vec), CancelCode> { +) -> Result<(Vec, Vec), CancelCode> { let mut verified_devices = Vec::new(); let info = extra_mac_info_receive(&ids, flow_id); diff --git a/matrix_sdk_crypto/src/verification/sas/mod.rs b/matrix_sdk_crypto/src/verification/sas/mod.rs index b5bc0208..6e79a4e5 100644 --- a/matrix_sdk_crypto/src/verification/sas/mod.rs +++ b/matrix_sdk_crypto/src/verification/sas/mod.rs @@ -33,7 +33,7 @@ use matrix_sdk_common::{ identifiers::{DeviceId, UserId}, }; -use crate::{Account, CryptoStore, CryptoStoreError, Device, TrustState}; +use crate::{Account, CryptoStore, CryptoStoreError, ReadOnlyDevice, TrustState}; pub use helpers::content_to_request; use sas_state::{ @@ -46,7 +46,7 @@ pub struct Sas { inner: Arc>, store: Arc>, account: Account, - other_device: Device, + other_device: ReadOnlyDevice, flow_id: Arc, } @@ -72,7 +72,7 @@ impl Sas { } /// Get the device of the other user. - pub fn other_device(&self) -> Device { + pub fn other_device(&self) -> ReadOnlyDevice { self.other_device.clone() } @@ -99,7 +99,7 @@ impl Sas { /// sent out through the server to the other device. pub(crate) fn start( account: Account, - other_device: Device, + other_device: ReadOnlyDevice, store: Arc>, ) -> (Sas, StartEventContent) { let (inner, content) = InnerSas::start(account.clone(), other_device.clone()); @@ -128,7 +128,7 @@ impl Sas { /// the other side. pub(crate) fn from_start_event( account: Account, - other_device: Device, + other_device: ReadOnlyDevice, store: Arc>, event: &ToDeviceEvent, ) -> Result { @@ -313,7 +313,7 @@ impl Sas { content } - pub(crate) fn verified_devices(&self) -> Option>> { + pub(crate) fn verified_devices(&self) -> Option>> { self.inner.lock().unwrap().verified_devices() } @@ -338,7 +338,7 @@ enum InnerSas { } impl InnerSas { - fn start(account: Account, other_device: Device) -> (InnerSas, StartEventContent) { + fn start(account: Account, other_device: ReadOnlyDevice) -> (InnerSas, StartEventContent) { let sas = SasState::::new(account, other_device); let content = sas.as_content(); (InnerSas::Created(sas), content) @@ -346,7 +346,7 @@ impl InnerSas { fn from_start_event( account: Account, - other_device: Device, + other_device: ReadOnlyDevice, event: &ToDeviceEvent, ) -> Result { match SasState::::from_start_event(account, other_device, event) { @@ -535,7 +535,7 @@ impl InnerSas { } } - fn verified_devices(&self) -> Option>> { + fn verified_devices(&self) -> Option>> { if let InnerSas::Done(s) = self { Some(s.verified_devices()) } else { @@ -556,7 +556,7 @@ mod test { use crate::{ store::memorystore::MemoryStore, verification::test::{get_content_from_request, wrap_any_to_device_content}, - Account, CryptoStore, Device, + Account, CryptoStore, ReadOnlyDevice, }; use super::{Accepted, Created, Sas, SasState, Started}; @@ -586,10 +586,10 @@ mod test { async fn get_sas_pair() -> (SasState, SasState) { let alice = Account::new(&alice_id(), &alice_device_id()); - let alice_device = Device::from_account(&alice).await; + let alice_device = ReadOnlyDevice::from_account(&alice).await; let bob = Account::new(&bob_id(), &bob_device_id()); - let bob_device = Device::from_account(&bob).await; + let bob_device = ReadOnlyDevice::from_account(&bob).await; let alice_sas = SasState::::new(alice.clone(), bob_device); @@ -670,10 +670,10 @@ mod test { #[tokio::test] async fn sas_wrapper_full() { let alice = Account::new(&alice_id(), &alice_device_id()); - let alice_device = Device::from_account(&alice).await; + let alice_device = ReadOnlyDevice::from_account(&alice).await; let bob = Account::new(&bob_id(), &bob_device_id()); - let bob_device = Device::from_account(&bob).await; + let bob_device = ReadOnlyDevice::from_account(&bob).await; let alice_store: Arc> = Arc::new(Box::new(MemoryStore::new())); let bob_store: Arc> = Arc::new(Box::new(MemoryStore::new())); diff --git a/matrix_sdk_crypto/src/verification/sas/sas_state.rs b/matrix_sdk_crypto/src/verification/sas/sas_state.rs index d5e0ccb4..0ff6d61d 100644 --- a/matrix_sdk_crypto/src/verification/sas/sas_state.rs +++ b/matrix_sdk_crypto/src/verification/sas/sas_state.rs @@ -43,7 +43,7 @@ use matrix_sdk_common::{ use super::helpers::{get_decimal, get_emoji, get_mac_content, receive_mac_event, SasIds}; -use crate::{Account, Device}; +use crate::{Account, ReadOnlyDevice}; const KEY_AGREEMENT_PROTOCOLS: &[KeyAgreementProtocol] = &[KeyAgreementProtocol::Curve25519HkdfSha256]; @@ -206,7 +206,7 @@ pub struct Confirmed { pub struct MacReceived { we_started: bool, their_pubkey: String, - verified_devices: Arc>, + verified_devices: Arc>, verified_master_keys: Arc>, } @@ -216,7 +216,7 @@ pub struct MacReceived { /// the master keys in the verified devices list. #[derive(Clone, Debug)] pub struct Done { - verified_devices: Arc>, + verified_devices: Arc>, verified_master_keys: Arc>, } @@ -239,7 +239,7 @@ impl SasState { } #[cfg(test)] - pub fn other_device(&self) -> Device { + pub fn other_device(&self) -> ReadOnlyDevice { self.ids.other_device.clone() } @@ -286,7 +286,7 @@ impl SasState { /// * `account` - Our own account. /// /// * `other_device` - The other device which we are going to verify. - pub fn new(account: Account, other_device: Device) -> SasState { + pub fn new(account: Account, other_device: ReadOnlyDevice) -> SasState { let verification_flow_id = Uuid::new_v4().to_string(); SasState { @@ -380,7 +380,7 @@ impl SasState { /// the other side. pub fn from_start_event( account: Account, - other_device: Device, + other_device: ReadOnlyDevice, event: &ToDeviceEvent, ) -> Result, SasState> { if let StartMethod::MSasV1(content) = &event.content.method { @@ -780,7 +780,7 @@ impl SasState { } /// Get the list of verified devices. - pub fn verified_devices(&self) -> Arc> { + pub fn verified_devices(&self) -> Arc> { self.state.verified_devices.clone() } } @@ -827,7 +827,7 @@ impl SasState { mod test { use std::convert::TryFrom; - use crate::{Account, Device}; + use crate::{Account, ReadOnlyDevice}; use matrix_sdk_common::{ events::{ key::verification::{ @@ -866,10 +866,10 @@ mod test { async fn get_sas_pair() -> (SasState, SasState) { let alice = Account::new(&alice_id(), &alice_device_id()); - let alice_device = Device::from_account(&alice).await; + let alice_device = ReadOnlyDevice::from_account(&alice).await; let bob = Account::new(&bob_id(), &bob_device_id()); - let bob_device = Device::from_account(&bob).await; + let bob_device = ReadOnlyDevice::from_account(&bob).await; let alice_sas = SasState::::new(alice.clone(), bob_device); @@ -1022,10 +1022,10 @@ mod test { #[tokio::test] async fn sas_from_start_unknown_method() { let alice = Account::new(&alice_id(), &alice_device_id()); - let alice_device = Device::from_account(&alice).await; + let alice_device = ReadOnlyDevice::from_account(&alice).await; let bob = Account::new(&bob_id(), &bob_device_id()); - let bob_device = Device::from_account(&bob).await; + let bob_device = ReadOnlyDevice::from_account(&bob).await; let alice_sas = SasState::::new(alice.clone(), bob_device);