Skip to content

Commit

Permalink
SdJwtBuilder::insert_claim
Browse files Browse the repository at this point in the history
  • Loading branch information
UMR1352 committed Sep 27, 2024
1 parent a343b7a commit 1f37bbe
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2020-2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::borrow::Cow;

use anyhow::Context as _;
use itertools::Itertools;
use serde::Serialize;
Expand Down Expand Up @@ -84,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 All @@ -105,6 +107,19 @@ impl<H: Hasher> SdJwtBuilder<H> {
self
}

/// Adds a new claim to the underlying object.
pub fn insert_claim<K, V>(mut self, key: K, value: V) -> Self
where
K: for<'a> Into<Cow<'a, str>>,
V: Serialize,
{
let key = key.into().into_owned();
let value = serde_json::to_value(value).unwrap();
self.encoder.object.as_object_mut().unwrap().insert(key, value);

self
}

/// Adds a decoy digest to the specified path.
///
/// `path` indicates the pointer to the value that will be concealed using the syntax of
Expand Down

0 comments on commit 1f37bbe

Please sign in to comment.