From f48a5c85094a3fed2bd26f2fb6020be3d65b08c2 Mon Sep 17 00:00:00 2001 From: Ryan Tate Date: Sun, 15 Dec 2024 18:32:33 -0800 Subject: [PATCH] patch credential match validation for array of values Co-Authored-By: Jacob Ward Signed-off-by: Ryan Tate --- src/core/presentation_definition.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/core/presentation_definition.rs b/src/core/presentation_definition.rs index 0365fac..46fcc18 100644 --- a/src/core/presentation_definition.rs +++ b/src/core/presentation_definition.rs @@ -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, }