Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if the response contains fields in the aamva namespace, return them a… #73

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/presentation/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ impl SessionManager {
.map_err(|e| anyhow!("unable to encrypt request: {}", e))
}

pub fn handle_response(&mut self, response: &[u8]) -> Result<BTreeMap<String, Value>, Error> {
pub fn handle_response(
&mut self,
response: &[u8],
) -> Result<BTreeMap<String, BTreeMap<String, Value>>, Error> {
let session_data: SessionData = serde_cbor::from_slice(response)?;
let encrypted_response = match session_data.data {
None => return Err(Error::HolderError),
Expand All @@ -187,8 +190,11 @@ impl SessionManager {
)
.map_err(|_e| Error::DecryptionError)?;
let response: DeviceResponse = serde_cbor::from_slice(&decrypted_response)?;
let mut parsed_response = BTreeMap::<String, serde_json::Value>::new();
response
let mut core_namespace = BTreeMap::<String, serde_json::Value>::new();
let mut aamva_namespace = BTreeMap::<String, serde_json::Value>::new();
let mut parsed_response = BTreeMap::<String, BTreeMap<String, serde_json::Value>>::new();

let mut namespaces = response
.documents
.ok_or(Error::DeviceTransmissionError)?
.into_inner()
Expand All @@ -198,7 +204,9 @@ impl SessionManager {
.issuer_signed
.namespaces
.ok_or(Error::NoMdlDataTransmission)?
.into_inner()
.into_inner();

namespaces
.remove("org.iso.18013.5.1")
.ok_or(Error::IncorrectNamespace)?
.into_inner()
Expand All @@ -207,9 +215,27 @@ impl SessionManager {
.for_each(|item| {
let value = parse_response(item.element_value.clone());
if let Ok(val) = value {
parsed_response.insert(item.element_identifier, val);
core_namespace.insert(item.element_identifier, val);
}
});

parsed_response.insert("org.iso.18013.5.1".to_string(), core_namespace);

if let Some(aamva_response) = namespaces.remove("org.iso.18013.5.1.aamva") {
aamva_response
.into_inner()
.into_iter()
.map(|item| item.into_inner())
.for_each(|item| {
let value = parse_response(item.element_value.clone());
if let Ok(val) = value {
aamva_namespace.insert(item.element_identifier, val);
}
});

parsed_response.insert("org.iso.18013.5.1.aamva".to_string(), aamva_namespace);
}

Ok(parsed_response)
}
}
Expand Down
Loading