Implement deref on the IKM list, mainly to allow iteration over IKMs

This commit is contained in:
Rodolphe Bréard 2024-02-25 18:14:13 +01:00
parent 395703dae4
commit 15198f5286
2 changed files with 24 additions and 1 deletions

View file

@ -158,6 +158,15 @@ impl InputKeyMaterialList {
}
}
#[cfg(feature = "ikm-management")]
impl std::ops::Deref for InputKeyMaterialList {
type Target = Vec<InputKeyMaterial>;
fn deref(&self) -> &Self::Target {
&self.ikm_lst
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -331,6 +340,20 @@ mod tests {
assert!(res.is_err());
}
#[test]
#[cfg(feature = "ikm-management")]
fn iterate() {
let mut lst = InputKeyMaterialList::new();
for _ in 0..10 {
let _ = lst.add_ikm();
}
let mut id = 1;
for ikm in lst.iter() {
assert_eq!(id, ikm.id);
id += 1;
}
}
#[test]
#[cfg(feature = "encryption")]
fn get_latest_ikm() {

View file

@ -15,7 +15,7 @@ mod storage;
pub use encryption::{decrypt, encrypt};
pub use error::Error;
#[cfg(any(feature = "encryption", feature = "ikm-management"))]
pub use ikm::{InputKeyMaterialList, InputKeyMaterial, IkmId};
pub use ikm::{IkmId, InputKeyMaterial, InputKeyMaterialList};
#[cfg(any(feature = "encryption", feature = "ikm-management"))]
pub use scheme::Scheme;