Have .delete_ikm()
return an error if the requested id is not found
This commit is contained in:
parent
af2c83f934
commit
67f1c247cc
1 changed files with 14 additions and 3 deletions
17
src/ikm.rs
17
src/ikm.rs
|
@ -266,8 +266,14 @@ impl InputKeyMaterialList {
|
||||||
/// # Ok::<(), coffio::Error>(())
|
/// # Ok::<(), coffio::Error>(())
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(feature = "ikm-management")]
|
#[cfg(feature = "ikm-management")]
|
||||||
pub fn delete_ikm(&mut self, id: IkmId) {
|
pub fn delete_ikm(&mut self, id: IkmId) -> Result<()> {
|
||||||
|
let initial_len = self.ikm_lst.len();
|
||||||
self.ikm_lst.retain(|ikm| ikm.id != id);
|
self.ikm_lst.retain(|ikm| ikm.id != id);
|
||||||
|
if self.ikm_lst.len() == initial_len {
|
||||||
|
Err(Error::IkmNotFound(id))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Revoke the specified IKM from the list.
|
/// Revoke the specified IKM from the list.
|
||||||
|
@ -563,13 +569,18 @@ mod ikm_management {
|
||||||
let latest_ikm = lst.get_latest_ikm(SystemTime::now()).unwrap();
|
let latest_ikm = lst.get_latest_ikm(SystemTime::now()).unwrap();
|
||||||
assert_eq!(latest_ikm.id, 2);
|
assert_eq!(latest_ikm.id, 2);
|
||||||
|
|
||||||
lst.delete_ikm(2);
|
let res = lst.delete_ikm(2);
|
||||||
|
assert!(res.is_ok(), "res: {res:?}");
|
||||||
let latest_ikm = lst.get_latest_ikm(SystemTime::now()).unwrap();
|
let latest_ikm = lst.get_latest_ikm(SystemTime::now()).unwrap();
|
||||||
assert_eq!(latest_ikm.id, 1);
|
assert_eq!(latest_ikm.id, 1);
|
||||||
|
|
||||||
lst.delete_ikm(1);
|
let res = lst.delete_ikm(1);
|
||||||
|
assert!(res.is_ok(), "res: {res:?}");
|
||||||
let res = lst.get_latest_ikm(SystemTime::now());
|
let res = lst.get_latest_ikm(SystemTime::now());
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
|
|
||||||
|
let res = lst.delete_ikm(42);
|
||||||
|
assert!(res.is_err(), "res: {res:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue