Skip to content

Commit

Permalink
avoid stripping leading zero from non-integer attribute
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Oct 24, 2023
1 parent 0260b93 commit 5b3aa2c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion indy-credx/src/services/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct Filter {

static INTERNAL_TAG_MATCHER: Lazy<Regex> =
Lazy::new(|| Regex::new("^attr::([^:]+)::(value|marker)$").unwrap());
static ENCODED_ATTR_MATCHER: Lazy<Regex> = Lazy::new(|| Regex::new("^0+([0-9]+)$").unwrap());

pub fn verify_presentation(
presentation: &Presentation,
Expand Down Expand Up @@ -533,12 +534,19 @@ fn verify_revealed_attribute_values(
Ok(())
}

fn normalize_encoded_attr(attr: &str) -> &str {
match ENCODED_ATTR_MATCHER.captures(attr) {
Some(m) => m.get(1).unwrap().as_str(),
None => attr,
}
}

fn verify_revealed_attribute_value(
attr_name: &str,
proof: &Presentation,
attr_info: &RevealedAttributeInfo,
) -> Result<()> {
let reveal_attr_encoded = attr_info.encoded.trim_start_matches('0');
let reveal_attr_encoded = normalize_encoded_attr(&attr_info.encoded);
let sub_proof_index = attr_info.sub_proof_index as usize;

let crypto_proof_encoded = proof
Expand Down Expand Up @@ -1238,4 +1246,14 @@ mod tests {
validate_timestamp(&_received(), "referent_2", &None, &Some(_interval())).unwrap_err();
validate_timestamp(&_received(), "referent_3", &None, &Some(_interval())).unwrap_err();
}

#[test]
fn format_attribute() {
assert_eq!(normalize_encoded_attr(""), "");
assert_eq!(normalize_encoded_attr("abc"), "abc");
assert_eq!(normalize_encoded_attr("0"), "0");
assert_eq!(normalize_encoded_attr("01"), "1");
assert_eq!(normalize_encoded_attr("01.0"), "01.0");
assert_eq!(normalize_encoded_attr("0abc"), "0abc");
}
}

0 comments on commit 5b3aa2c

Please sign in to comment.