Allow to revoke an IKM
This commit is contained in:
parent
a1bf9e0bcc
commit
c6a3855847
1 changed files with 30 additions and 0 deletions
30
src/ikm.rs
30
src/ikm.rs
|
@ -98,6 +98,17 @@ impl InputKeyMaterialList {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "ikm-management")]
|
||||
pub fn revoke_ikm(&mut self, id: IkmId) -> Result<()> {
|
||||
let ikm = self
|
||||
.ikm_lst
|
||||
.iter_mut()
|
||||
.find(|ikm| ikm.id == id)
|
||||
.ok_or(Error::IkmNotFound(id))?;
|
||||
ikm.is_revoked = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "ikm-management")]
|
||||
pub fn export(&self) -> Result<String> {
|
||||
let data_size = (self.ikm_lst.len() * IKM_STRUCT_SIZE) + 4;
|
||||
|
@ -277,6 +288,25 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "ikm-management")]
|
||||
fn revoke_ikm() {
|
||||
let mut lst = InputKeyMaterialList::new();
|
||||
let _ = lst.add_ikm();
|
||||
let _ = lst.add_ikm();
|
||||
|
||||
let latest_ikm = lst.get_latest_ikm().unwrap();
|
||||
assert_eq!(latest_ikm.id, 2);
|
||||
|
||||
let _ = lst.revoke_ikm(2);
|
||||
let latest_ikm = lst.get_latest_ikm().unwrap();
|
||||
assert_eq!(latest_ikm.id, 1);
|
||||
|
||||
let _ = lst.revoke_ikm(1);
|
||||
let res = lst.get_latest_ikm();
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "encryption")]
|
||||
fn get_latest_ikm() {
|
||||
|
|
Loading…
Reference in a new issue