pub mod common;
pub mod device_retrieval;
use std::collections::HashMap;
use common::{DataElementIdentifier, DataElementValue, NameSpace};
use crate::utils::json::cbor_to_json;
#[derive(Debug, Clone, PartialEq)]
pub struct Claims(pub HashMap<NameSpace, HashMap<DataElementIdentifier, DataElementValue>>);
impl Claims {
pub fn into_json(self) -> Option<serde_json::Map<String, serde_json::Value>> {
self.0
.into_iter()
.map(|(k, v)| {
let v_json = serde_json::Value::Object(
v.into_iter()
.map(|(k, v)| Some((k.0, cbor_to_json(v.0)?)))
.collect::<Option<_>>()?,
);
Some((k.0, v_json))
})
.collect::<Option<_>>()
}
}
pub struct BorrowedClaims<'a>(
pub HashMap<&'a NameSpace, HashMap<&'a DataElementIdentifier, &'a DataElementValue>>,
);
impl BorrowedClaims<'_> {
pub fn into_claims(self) -> Claims {
Claims(
self.0
.into_iter()
.map(|(k, v)| {
let v_owned = v.into_iter().map(|(k, v)| (k.clone(), v.clone())).collect();
(k.clone(), v_owned)
})
.collect(),
)
}
}