crypto: Simplify the OlmMachine -> Device conversion.
This commit is contained in:
parent
2481fbbd27
commit
9ef784d665
2 changed files with 7 additions and 36 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ pub struct OlmMachine {
|
|||
/// The unique device id of the device that holds this account.
|
||||
device_id: Box<DeviceId>,
|
||||
/// 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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue