From a492c48fea2aef77c890c471658392d01ff00f84 Mon Sep 17 00:00:00 2001 From: Enrico Marconi Date: Thu, 26 Sep 2024 15:27:33 +0200 Subject: [PATCH] _sd elements' order do not depend on the order of the claims --- src/encoder.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/encoder.rs b/src/encoder.rs index 347610c..f2a5242 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -169,7 +169,14 @@ impl SdObjectEncoder { fn add_digest_to_object(object: &mut Map, 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(),