From c134aeb6f26c3edc3fe63ee6089b88ab47d2904c Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 8 Feb 2024 12:09:01 +0100 Subject: [PATCH 1/2] Don't panic in vc_util This ensures that the vc_util lib does not panic because of missing keys (keys specified in the cred spec argument but not in the subject properties). --- src/vc_util/src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/vc_util/src/lib.rs b/src/vc_util/src/lib.rs index 940001d8a0..0cea97f784 100644 --- a/src/vc_util/src/lib.rs +++ b/src/vc_util/src/lib.rs @@ -372,9 +372,15 @@ fn validate_claims_match_spec( let subject = Subject::from_json_value(credential_subject.clone()).map_err(|_| { inconsistent_jwt_claims("missing credentialSubject in VerifiedAdult JWT vc") })?; - for (key, value) in spec.arguments.as_ref().unwrap_or(&HashMap::new()).iter() { - if *value != subject.properties[key] { - return Err(inconsistent_jwt_claims("wrong VerifiedAdult vc")); + if let Some(arguments) = spec.arguments.as_ref() { + for (key, value) in arguments.iter() { + if let Some(v) = subject.properties.get(key) { + if value != v { + return Err(inconsistent_jwt_claims("wrong VerifiedAdult vc")); + } + } else { + return Err(inconsistent_jwt_claims("Missing key in subject properties")); + } } } Ok(()) From 10602a47f3bdb42d635b295ee75d3de6e0bc3f1e Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 8 Feb 2024 12:19:25 +0100 Subject: [PATCH 2/2] Remove unused import --- src/vc_util/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vc_util/src/lib.rs b/src/vc_util/src/lib.rs index 0cea97f784..0081cb5c6e 100644 --- a/src/vc_util/src/lib.rs +++ b/src/vc_util/src/lib.rs @@ -18,7 +18,6 @@ use identity_jose::jwt::JwtClaims; use identity_jose::jwu::{decode_b64, encode_b64}; use serde_json::{Map, Value}; use sha2::{Digest, Sha256}; -use std::collections::HashMap; use std::ops::{Add, Deref, DerefMut}; pub mod custom;