Improve the context and IKM list APIs
This commit is contained in:
parent
90c8a2aa87
commit
ae19a16531
5 changed files with 83 additions and 16 deletions
31
src/ikm.rs
31
src/ikm.rs
|
@ -154,6 +154,14 @@ impl InputKeyMaterialList {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for InputKeyMaterialList {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Self::import(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ikm-management")]
|
||||
impl std::ops::Deref for InputKeyMaterialList {
|
||||
type Target = Vec<InputKeyMaterial>;
|
||||
|
@ -166,6 +174,7 @@ impl std::ops::Deref for InputKeyMaterialList {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
fn import() {
|
||||
|
@ -188,6 +197,28 @@ mod tests {
|
|||
);
|
||||
assert_eq!(ikm.is_revoked, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_str() {
|
||||
let s =
|
||||
"AQAAAA:AQAAAAEAAAC_vYEw1ujVG5i-CtoPYSzik_6xaAq59odjPm5ij01-e6zz4mUAAAAALJGBiwAAAAAA";
|
||||
let res = InputKeyMaterialList::from_str(s);
|
||||
assert!(res.is_ok(), "res: {res:?}");
|
||||
let lst = res.unwrap();
|
||||
assert_eq!(lst.id_counter, 1);
|
||||
assert_eq!(lst.ikm_lst.len(), 1);
|
||||
let ikm = lst.ikm_lst.first().unwrap();
|
||||
assert_eq!(ikm.id, 1);
|
||||
assert_eq!(ikm.scheme, Scheme::XChaCha20Poly1305WithBlake3);
|
||||
assert_eq!(
|
||||
ikm.content,
|
||||
[
|
||||
191, 189, 129, 48, 214, 232, 213, 27, 152, 190, 10, 218, 15, 97, 44, 226, 147, 254,
|
||||
177, 104, 10, 185, 246, 135, 99, 62, 110, 98, 143, 77, 126, 123
|
||||
]
|
||||
);
|
||||
assert_eq!(ikm.is_revoked, false);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "ikm-management"))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue