Skip to content

Commit

Permalink
patch credential match validation for array of values
Browse files Browse the repository at this point in the history
Co-Authored-By: Jacob Ward <[email protected]>
Signed-off-by: Ryan Tate <[email protected]>
  • Loading branch information
Ryanmtate and cobward committed Dec 16, 2024
1 parent 347814f commit f48a5c8
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/core/presentation_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,16 @@ impl PresentationDefinition {
.filter(|field| field.is_required())
.all(|field| {
match field.filter.as_ref().map(|f| f.validator()) {
Some(validator) => {
let is_valid = field
.path
.iter()
// NOTE: Errors are ignored to allow other paths to
// be checked. Interested in whether there is at least
// one valid path.
//
// An empty iterator will return false on an any() call.
.flat_map(|path| path.query(credential))
// NOTE: This is currently assuming that if any of the paths are a match
// to the credential, then the validation is, at least partially, successful,
// and the credential may satisfy the presentation definition.
.any(|value| validator.validate(value).is_ok());

is_valid
}
Some(validator) => field
.path
.iter()
.flat_map(|path| path.query(credential))
.any(|value| match value {
serde_json::Value::Array(vals) => {
vals.iter().any(|val| validator.validate(val).is_ok())
}
_ => validator.validate(value).is_ok(),
}),
// Allow for fields without validators to pass through.
_ => true,
}
Expand Down

0 comments on commit f48a5c8

Please sign in to comment.