From 15198f5286c39e34cd024a24d88c041f4d9126ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sun, 25 Feb 2024 18:14:13 +0100 Subject: [PATCH] Implement deref on the IKM list, mainly to allow iteration over IKMs --- src/ikm.rs | 23 +++++++++++++++++++++++ src/lib.rs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ikm.rs b/src/ikm.rs index 8584257..fb8f544 100644 --- a/src/ikm.rs +++ b/src/ikm.rs @@ -158,6 +158,15 @@ impl InputKeyMaterialList { } } +#[cfg(feature = "ikm-management")] +impl std::ops::Deref for InputKeyMaterialList { + type Target = Vec; + + 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() { diff --git a/src/lib.rs b/src/lib.rs index 5fd09af..bd5d380 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;