Skip to content

Commit

Permalink
ensure order of disclosures in SdJwtPresentationBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
UMR1352 committed Oct 11, 2024
1 parent ebc05f6 commit 9601f3f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ serde_with = "3.6.1"
josekit = "0.8.4"
async-trait = "0.1.80"
anyhow = "1"
indexmap = "2.6.0"

[dev-dependencies]
tokio = { version = "1.38.1", features = ["macros", "rt-multi-thread"] }
Expand Down
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<H: Hasher> SdJwtBuilder<H> {
/// .make_concealable("/claim1/abc").unwrap() //"abc": true
/// .make_concealable("/claim2/0").unwrap(); //conceals "val_1"
/// ```
///
///
/// ## Error
/// * [`Error::InvalidPath`] if pointer is invalid.
/// * [`Error::DataTypeMismatch`] if existing SD format is invalid.
Expand Down
12 changes: 6 additions & 6 deletions src/sd_jwt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::collections::HashMap;
use std::fmt::Display;
use std::iter::Peekable;
use std::ops::Deref;
Expand All @@ -20,6 +19,7 @@ use crate::SdObjectDecoder;
use crate::ARRAY_DIGEST_KEY;
use crate::DIGESTS_KEY;
use crate::SHA_ALG_NAME;
use indexmap::IndexMap;
use itertools::Itertools;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -192,7 +192,7 @@ impl FromStr for SdJwt {
#[derive(Debug, Clone)]
pub struct SdJwtPresentationBuilder {
sd_jwt: SdJwt,
disclosures: HashMap<String, Disclosure>,
disclosures: IndexMap<String, Disclosure>,
removed_disclosures: Vec<Disclosure>,
object: Value,
}
Expand Down Expand Up @@ -254,7 +254,7 @@ impl SdJwtPresentationBuilder {

digests_to_remove
.into_iter()
.flat_map(|digest| self.disclosures.remove(&digest))
.flat_map(|digest| self.disclosures.shift_remove(&digest))
.for_each(|disclosure| self.removed_disclosures.push(disclosure));

Ok(self)
Expand Down Expand Up @@ -309,7 +309,7 @@ impl SdJwtPresentationBuilder {
fn conceal<'p, 'o, 'd, I>(
object: &'o Value,
mut path: Peekable<I>,
disclosures: &'d HashMap<String, Disclosure>,
disclosures: &'d IndexMap<String, Disclosure>,
) -> Result<Vec<&'o str>>
where
I: Iterator<Item = &'p str>,
Expand Down Expand Up @@ -381,7 +381,7 @@ where
fn find_disclosure<'o>(
object: &'o JsonObject,
key: &str,
disclosures: &HashMap<String, Disclosure>,
disclosures: &IndexMap<String, Disclosure>,
) -> Option<&'o str> {
let maybe_disclosable_array_entry = || {
object
Expand Down Expand Up @@ -409,7 +409,7 @@ fn find_disclosure<'o>(

fn get_all_sub_disclosures<'v, 'd>(
start: &'v Value,
disclosures: &'d HashMap<String, Disclosure>,
disclosures: &'d IndexMap<String, Disclosure>,
) -> Box<dyn Iterator<Item = &'v str> + 'v>
where
'd: 'v,
Expand Down

0 comments on commit 9601f3f

Please sign in to comment.