Skip to content

Commit 1f37bbe

Browse files
committed
SdJwtBuilder::insert_claim
1 parent a343b7a commit 1f37bbe

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/builder.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2020-2024 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use std::borrow::Cow;
5+
46
use anyhow::Context as _;
57
use itertools::Itertools;
68
use serde::Serialize;
@@ -84,7 +86,7 @@ impl<H: Hasher> SdJwtBuilder<H> {
8486
/// .make_concealable("/claim1/abc").unwrap() //"abc": true
8587
/// .make_concealable("/claim2/0").unwrap(); //conceals "val_1"
8688
/// ```
87-
///
89+
///
8890
/// ## Error
8991
/// * [`Error::InvalidPath`] if pointer is invalid.
9092
/// * [`Error::DataTypeMismatch`] if existing SD format is invalid.
@@ -105,6 +107,19 @@ impl<H: Hasher> SdJwtBuilder<H> {
105107
self
106108
}
107109

110+
/// Adds a new claim to the underlying object.
111+
pub fn insert_claim<K, V>(mut self, key: K, value: V) -> Self
112+
where
113+
K: for<'a> Into<Cow<'a, str>>,
114+
V: Serialize,
115+
{
116+
let key = key.into().into_owned();
117+
let value = serde_json::to_value(value).unwrap();
118+
self.encoder.object.as_object_mut().unwrap().insert(key, value);
119+
120+
self
121+
}
122+
108123
/// Adds a decoy digest to the specified path.
109124
///
110125
/// `path` indicates the pointer to the value that will be concealed using the syntax of

0 commit comments

Comments
 (0)