crypto: Rename Device to ReadOnlyDevice.

master
Damir Jelić 2020-08-17 16:17:28 +02:00
parent e778f7d72d
commit 43aea6e482
17 changed files with 104 additions and 93 deletions

View File

@ -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,
};

View File

@ -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()
}
}

View File

@ -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")]

View File

@ -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<UserId>,
device_id: Arc<Box<DeviceId>>,
algorithms: Arc<Vec<EventEncryptionAlgorithm>>,
@ -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<i64> for TrustState {
}
}
impl Device {
impl ReadOnlyDevice {
/// Create a new Device.
pub fn new(
user_id: UserId,
@ -144,7 +144,7 @@ impl Device {
keys: BTreeMap<DeviceKeyId, String>,
signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
) -> 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<Self, Self::Error> {
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]

View File

@ -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};

View File

@ -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<UserId, BTreeMap<Box<DeviceId>, DeviceKeys>>,
) -> StoreResult<Vec<Device>> {
) -> StoreResult<Vec<ReadOnlyDevice>> {
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<Vec<Device>> {
) -> OlmResult<Vec<ReadOnlyDevice>> {
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<EncryptedEventContent> {
@ -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();

View File

@ -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<DashMap<UserId, DashMap<Box<DeviceId>, Device>>>,
entries: Arc<DashMap<UserId, DashMap<Box<DeviceId>, ReadOnlyDevice>>>,
}
/// A read only view over all devices belonging to a user.
#[derive(Debug)]
pub struct UserDevices {
entries: ReadOnlyView<Box<DeviceId>, Device>,
entries: ReadOnlyView<Box<DeviceId>, ReadOnlyDevice>,
}
impl UserDevices {
/// Get the specific device with the given device id.
pub fn get(&self, device_id: &DeviceId) -> Option<Device> {
pub fn get(&self, device_id: &DeviceId) -> Option<ReadOnlyDevice> {
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<Item = &Device> {
pub fn devices(&self) -> impl Iterator<Item = &ReadOnlyDevice> {
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<Device> {
pub fn get(&self, user_id: &UserId, device_id: &DeviceId) -> Option<ReadOnlyDevice> {
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<Device> {
pub fn remove(&self, user_id: &UserId, device_id: &DeviceId) -> Option<ReadOnlyDevice> {
self.entries
.get(user_id)
.and_then(|m| m.remove(device_id))

View File

@ -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<DeviceKeyId, OneTimeKey>,
) -> Result<Session, SessionCreationError> {
let one_time_key = key_map.values().next().ok_or_else(|| {

View File

@ -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<EncryptedEventContent> {

View File

@ -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<Option<Device>> {
async fn get_device(
&self,
user_id: &UserId,
device_id: &DeviceId,
) -> Result<Option<ReadOnlyDevice>> {
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());
}

View File

@ -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<Option<Device>>;
async fn get_device(
&self,
user_id: &UserId,
device_id: &DeviceId,
) -> Result<Option<ReadOnlyDevice>>;
/// Get all the devices of the given user.
///

View File

@ -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<Option<Device>> {
async fn get_device(
&self,
user_id: &UserId,
device_id: &DeviceId,
) -> Result<Option<ReadOnlyDevice>> {
Ok(self.devices.get(user_id, device_id))
}

View File

@ -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<CrossSigningKey>);
@ -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)
}
}

View File

@ -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<Box<dyn CryptoStore>> = 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

View File

@ -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<MacEventContent>,
) -> Result<(Vec<Device>, Vec<String>), CancelCode> {
) -> Result<(Vec<ReadOnlyDevice>, Vec<String>), CancelCode> {
let mut verified_devices = Vec::new();
let info = extra_mac_info_receive(&ids, flow_id);

View File

@ -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<Mutex<InnerSas>>,
store: Arc<Box<dyn CryptoStore>>,
account: Account,
other_device: Device,
other_device: ReadOnlyDevice,
flow_id: Arc<String>,
}
@ -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<Box<dyn CryptoStore>>,
) -> (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<Box<dyn CryptoStore>>,
event: &ToDeviceEvent<StartEventContent>,
) -> Result<Sas, AnyToDeviceEventContent> {
@ -313,7 +313,7 @@ impl Sas {
content
}
pub(crate) fn verified_devices(&self) -> Option<Arc<Vec<Device>>> {
pub(crate) fn verified_devices(&self) -> Option<Arc<Vec<ReadOnlyDevice>>> {
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::<Created>::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<StartEventContent>,
) -> Result<InnerSas, AnyToDeviceEventContent> {
match SasState::<Started>::from_start_event(account, other_device, event) {
@ -535,7 +535,7 @@ impl InnerSas {
}
}
fn verified_devices(&self) -> Option<Arc<Vec<Device>>> {
fn verified_devices(&self) -> Option<Arc<Vec<ReadOnlyDevice>>> {
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<Created>, SasState<Started>) {
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::<Created>::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<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new()));
let bob_store: Arc<Box<dyn CryptoStore>> = Arc::new(Box::new(MemoryStore::new()));

View File

@ -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<Vec<Device>>,
verified_devices: Arc<Vec<ReadOnlyDevice>>,
verified_master_keys: Arc<Vec<String>>,
}
@ -216,7 +216,7 @@ pub struct MacReceived {
/// the master keys in the verified devices list.
#[derive(Clone, Debug)]
pub struct Done {
verified_devices: Arc<Vec<Device>>,
verified_devices: Arc<Vec<ReadOnlyDevice>>,
verified_master_keys: Arc<Vec<String>>,
}
@ -239,7 +239,7 @@ impl<S: Clone> SasState<S> {
}
#[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<Created> {
/// * `account` - Our own account.
///
/// * `other_device` - The other device which we are going to verify.
pub fn new(account: Account, other_device: Device) -> SasState<Created> {
pub fn new(account: Account, other_device: ReadOnlyDevice) -> SasState<Created> {
let verification_flow_id = Uuid::new_v4().to_string();
SasState {
@ -380,7 +380,7 @@ impl SasState<Started> {
/// the other side.
pub fn from_start_event(
account: Account,
other_device: Device,
other_device: ReadOnlyDevice,
event: &ToDeviceEvent<StartEventContent>,
) -> Result<SasState<Started>, SasState<Canceled>> {
if let StartMethod::MSasV1(content) = &event.content.method {
@ -780,7 +780,7 @@ impl SasState<Done> {
}
/// Get the list of verified devices.
pub fn verified_devices(&self) -> Arc<Vec<Device>> {
pub fn verified_devices(&self) -> Arc<Vec<ReadOnlyDevice>> {
self.state.verified_devices.clone()
}
}
@ -827,7 +827,7 @@ impl SasState<Canceled> {
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<Created>, SasState<Started>) {
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::<Created>::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::<Created>::new(alice.clone(), bob_device);