Skip to content

Commit

Permalink
_sd elements' order do not depend on the order of the claims
Browse files Browse the repository at this point in the history
  • Loading branch information
UMR1352 committed Sep 26, 2024
1 parent f730806 commit a492c48
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ impl<H: Hasher> SdObjectEncoder<H> {
fn add_digest_to_object(object: &mut Map<String, Value>, digest: String) -> Result<()> {
if let Some(sd_value) = object.get_mut(DIGESTS_KEY) {
if let Value::Array(value) = sd_value {
value.push(Value::String(digest))
// Insert the
let idx = value
.iter()
.enumerate()
.find(|(_, value)| value.as_str().is_some_and(|s| s > &digest))
.map(|(pos, _)| pos)
.unwrap_or(value.len());
value.insert(idx, Value::String(digest));
} else {
return Err(Error::DataTypeMismatch(
"invalid object: existing `_sd` type is not an array".to_string(),
Expand Down

0 comments on commit a492c48

Please sign in to comment.