Skip to content

Commit

Permalink
bugfix for SDJWTClaimsStrategy::No support (#19)
Browse files Browse the repository at this point in the history
Fix for #17. Allows holder and verifier to parse SD-JWT with no disclosures included.

Signed-off-by: Alexander Sukhachev <[email protected]>
  • Loading branch information
alexsdsr authored Jan 17, 2024
1 parent b99ffbe commit d2f8fc1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl SDJWTCommon {
let parts: Vec<&str> = sd_jwt_with_disclosures
.split(COMBINED_SERIALIZATION_FORMAT_SEPARATOR)
.collect();
if parts.len() < 3 {
if parts.len() < 2 { // minimal number of SD-JWT parts according to the standard
return Err(Error::InvalidInput(format!(
"Invalid SD-JWT length: {}",
parts.len()
Expand Down
51 changes: 51 additions & 0 deletions src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,57 @@ mod tests {
assert_eq!(user_claims, verified_claims);
}

#[test]
fn verify_noclaim_presentation() {
let user_claims = json!({
"sub": "6c5c0a49-b589-431d-bae7-219122a9ec2c",
"iss": "https://example.com/issuer",
"iat": 1683000000,
"exp": 1883000000,
"address": {
"street_address": "Schulstr. 12",
"locality": "Schulpforta",
"region": "Sachsen-Anhalt",
"country": "DE"
}
});
let private_issuer_bytes = PRIVATE_ISSUER_PEM.as_bytes();
let issuer_key = EncodingKey::from_ec_pem(private_issuer_bytes).unwrap();
let sd_jwt = SDJWTIssuer::new(issuer_key, None).issue_sd_jwt(
user_claims.clone(),
SDJWTClaimsStrategy::No,
None,
false,
"compact".to_owned(),
)
.unwrap();

let presentation = SDJWTHolder::new(sd_jwt.clone(), "compact".to_owned())
.unwrap()
.create_presentation(
user_claims.as_object().unwrap().clone(),
None,
None,
None,
None,
)
.unwrap();
assert_eq!(sd_jwt, presentation);
let verified_claims = SDJWTVerifier::new(
presentation,
Box::new(|_, _| {
let public_issuer_bytes = PUBLIC_ISSUER_PEM.as_bytes();
DecodingKey::from_ec_pem(public_issuer_bytes).unwrap()
}),
None,
None,
"compact".to_owned(),
)
.unwrap()
.verified_claims;
assert_eq!(user_claims, verified_claims);
}

#[test]
fn verify_arrayed_presentation() {
let user_claims = json!(
Expand Down

0 comments on commit d2f8fc1

Please sign in to comment.