From 1f37bbe7ece98befa75d11d1d629587f7eea4a44 Mon Sep 17 00:00:00 2001 From: Enrico Marconi Date: Fri, 27 Sep 2024 21:12:45 +0200 Subject: [PATCH] SdJwtBuilder::insert_claim --- src/builder.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index 41b04f5..7bde42d 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -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; @@ -84,7 +86,7 @@ impl SdJwtBuilder { /// .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. @@ -105,6 +107,19 @@ impl SdJwtBuilder { self } + /// Adds a new claim to the underlying object. + pub fn insert_claim(mut self, key: K, value: V) -> Self + where + K: for<'a> Into>, + 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