diff --git a/matrix_sdk_crypto/src/device.rs b/matrix_sdk_crypto/src/device.rs index bcd84fbd..93996b75 100644 --- a/matrix_sdk_crypto/src/device.rs +++ b/matrix_sdk_crypto/src/device.rs @@ -184,40 +184,11 @@ impl Device { pub(crate) fn mark_as_deleted(&self) { self.deleted.store(true, Ordering::Relaxed); } -} -#[cfg(test)] -impl From<&OlmMachine> for Device { - fn from(machine: &OlmMachine) -> Self { - let signatures = BTreeMap::new(); - - Device { - user_id: Arc::new(machine.user_id().clone()), - device_id: Arc::new(machine.device_id().into()), - algorithms: Arc::new(vec![ - Algorithm::MegolmV1AesSha2, - Algorithm::OlmV1Curve25519AesSha2, - ]), - keys: Arc::new( - machine - .identity_keys() - .iter() - .map(|(key, value)| { - ( - AlgorithmAndDeviceId( - KeyAlgorithm::try_from(key.as_ref()).unwrap(), - machine.device_id().into(), - ), - value.to_owned(), - ) - }) - .collect(), - ), - display_name: Arc::new(None), - deleted: Arc::new(AtomicBool::new(false)), - signatures: Arc::new(signatures), - trust_state: Arc::new(Atomic::new(TrustState::Unset)), - } + #[cfg(test)] + pub async fn from_machine(machine: &OlmMachine) -> Device { + let device_keys = machine.account.device_keys().await; + Device::try_from(&device_keys).unwrap() } } diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 255685b2..c69ca24e 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -62,7 +62,7 @@ pub struct OlmMachine { /// The unique device id of the device that holds this account. device_id: Box, /// Our underlying Olm Account holding our identity keys. - account: Account, + pub(crate) account: Account, /// Store for the encryption keys. /// Persists all the encryption keys so a client can resume the session /// without the need to create new keys. @@ -1278,8 +1278,8 @@ mod test { let alice_device = alice_device_id(); let alice = OlmMachine::new(&alice_id, &alice_device); - let alice_deivce = Device::from(&alice); - let bob_device = Device::from(&bob); + let alice_deivce = Device::from_machine(&alice).await; + let bob_device = Device::from_machine(&bob).await; alice.store.save_devices(&[bob_device]).await.unwrap(); bob.store.save_devices(&[alice_deivce]).await.unwrap();