crypto: Allow a device to be marked as deleted.
parent
63c0aa8771
commit
7c54ad5c5f
|
@ -115,6 +115,11 @@ impl Device {
|
||||||
&self.algorithms
|
&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.
|
/// Update a device with a new device keys struct.
|
||||||
pub(crate) fn update_device(&mut self, device_keys: &DeviceKeys) {
|
pub(crate) fn update_device(&mut self, device_keys: &DeviceKeys) {
|
||||||
let mut keys = HashMap::new();
|
let mut keys = HashMap::new();
|
||||||
|
@ -138,6 +143,11 @@ impl Device {
|
||||||
mem::replace(&mut self.keys, Arc::new(keys));
|
mem::replace(&mut self.keys, Arc::new(keys));
|
||||||
mem::replace(&mut self.display_name, display_name);
|
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 {
|
impl From<&DeviceKeys> for Device {
|
||||||
|
@ -258,4 +268,16 @@ pub(crate) mod test {
|
||||||
device.display_name().as_ref().unwrap()
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue