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

Don't panic in vc_util #2257

Merged
merged 2 commits into from
Feb 8, 2024
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
13 changes: 9 additions & 4 deletions src/vc_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -372,9 +371,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(())
Expand Down
Loading