diff --git a/src/crypto/device.rs b/src/crypto/device.rs index a5ef26a9..d0b2fcf1 100644 --- a/src/crypto/device.rs +++ b/src/crypto/device.rs @@ -115,6 +115,11 @@ impl Device { &self.algorithms } + /// Is the device deleted. + pub fn deleted(&self) -> bool { + self.deleted.load(Ordering::Relaxed) + } + /// Update a device with a new device keys struct. pub(crate) fn update_device(&mut self, device_keys: &DeviceKeys) { let mut keys = HashMap::new(); @@ -138,6 +143,11 @@ impl Device { mem::replace(&mut self.keys, Arc::new(keys)); mem::replace(&mut self.display_name, display_name); } + + /// Mark the device as deleted. + pub(crate) fn mark_as_deleted(&self) { + self.deleted.store(true, Ordering::Relaxed); + } } impl From<&DeviceKeys> for Device { @@ -258,4 +268,16 @@ pub(crate) mod test { device.display_name().as_ref().unwrap() ); } + + #[test] + fn delete_a_device() { + let device = get_device(); + assert!(!device.deleted()); + + let device_clone = device.clone(); + + device.mark_as_deleted(); + assert!(device.deleted()); + assert!(device_clone.deleted()); + } }