Skip to content

Commit

Permalink
fix: sd_hash generation and verification (#31)
Browse files Browse the repository at this point in the history
- Fix generating `sd_hash` at holder side
- Fix retrieving `sd_hash` at verifier side
- Closes #31

Signed-off-by: Abdulbois Tursunov <[email protected]>
  • Loading branch information
Abdulbois authored and jovfer committed Sep 6, 2024
1 parent 842572f commit f97e3df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use error::{Error, Result};
use jsonwebtoken::{Algorithm, EncodingKey, Header};
use serde_json::{Map, Value};
use std::collections::HashMap;
use std::ops::Add;
use std::str::FromStr;
use std::time;

Expand Down Expand Up @@ -332,7 +333,9 @@ impl SDJWTHolder {
let mut combined: Vec<&str> = Vec::with_capacity(self.hs_disclosures.len() + 1);
combined.push(&self.serialized_sd_jwt);
combined.extend(self.hs_disclosures.iter().map(|s| s.as_str()));
let combined = combined.join(COMBINED_SERIALIZATION_FORMAT_SEPARATOR);
let combined = combined
.join(COMBINED_SERIALIZATION_FORMAT_SEPARATOR)
.add(COMBINED_SERIALIZATION_FORMAT_SEPARATOR);

let sd_hash = base64_hash(combined.as_bytes());
self.key_binding_jwt_payload
Expand Down
5 changes: 4 additions & 1 deletion src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use jsonwebtoken::jwk::Jwk;
use jsonwebtoken::{Algorithm, DecodingKey, Header, Validation};
use log::debug;
use serde_json::{Map, Value};
use std::ops::Add;
use std::option::Option;
use std::str::FromStr;
use std::string::String;
Expand Down Expand Up @@ -213,7 +214,9 @@ impl SDJWTVerifier {
.iter()
.map(|s| s.as_str()),
);
let combined = combined.join(COMBINED_SERIALIZATION_FORMAT_SEPARATOR);
let combined = combined
.join(COMBINED_SERIALIZATION_FORMAT_SEPARATOR)
.add(COMBINED_SERIALIZATION_FORMAT_SEPARATOR);

Ok(base64_hash(combined.as_bytes()))
}
Expand Down

0 comments on commit f97e3df

Please sign in to comment.