pub struct SdObjectEncoder<H: Hasher = Sha256Hasher> { /* private fields */ }
Expand description

Transforms a JSON object into an SD-JWT object by substituting selected values with their corresponding disclosure digests.

Implementations§

source§

impl SdObjectEncoder

source

pub fn new(object: &str) -> Result<SdObjectEncoder<Sha256Hasher>>

Creates a new SdObjectEncoder with sha-256 hash function.

§Error

Returns Error::DeserializationError if object is not a valid JSON object.

source

pub fn try_from_serializable<T: Serialize>(object: T) -> Result<Self, Error>

Creates a new SdObjectEncoder with sha-256 hash function from a serializable object.

§Error

Returns Error::DeserializationError if object can not be serialized into a valid JSON object.

source§

impl<H: Hasher> SdObjectEncoder<H>

source

pub fn with_custom_hasher(object: &str, hasher: H) -> Result<Self>

Creates a new SdObjectEncoder with custom hash function to create digests.

source

pub fn conceal( &mut self, path: &str, salt: Option<String> ) -> Result<Disclosure>

Substitutes a value with the digest of its disclosure. If no salt is provided, the disclosure will be created with a random salt value.

path indicates the pointer to the value that will be concealed using the syntax of JSON pointer.

§Example
use sd_jwt_payload::SdObjectEncoder;
use sd_jwt_payload::json;

let obj = json!({
 "id": "did:value",
 "claim1": {
    "abc": true
 },
 "claim2": ["val_1", "val_2"]
});
let mut encoder = SdObjectEncoder::try_from(obj).unwrap();
encoder.conceal("/id", None).unwrap(); //conceals "id": "did:value"
encoder.conceal("/claim1/abc", None).unwrap(); //"abc": true
encoder.conceal("/claim2/0", None).unwrap(); //conceals "val_1"
§Error
source

pub fn add_sd_alg_property(&mut self) -> Option<Value>

Adds the _sd_alg property to the top level of the object. The value is taken from the crate::Hasher::alg_name implementation.

source

pub fn try_to_string(&self) -> Result<String>

Returns the modified object as a string.

source

pub fn add_decoys(&mut self, path: &str, number_of_decoys: usize) -> Result<()>

Adds a decoy digest to the specified path.

path indicates the pointer to the value that will be concealed using the syntax of JSON pointer.

Use path = “” to add decoys to the top level.

source

pub fn object(&self) -> Result<&Map<String, Value>>

Returns a reference to the internal object.

source

pub fn salt_size(&self) -> usize

Returns the used salt length.

source

pub fn set_salt_size(&mut self, salt_size: usize) -> Result<()>

Sets size of random data used to generate the salts for disclosures in bytes.

§Warning

Salt size must be >= 16.

Trait Implementations§

source§

impl<H: Clone + Hasher> Clone for SdObjectEncoder<H>

source§

fn clone(&self) -> SdObjectEncoder<H>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<H: Debug + Hasher> Debug for SdObjectEncoder<H>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl TryFrom<Value> for SdObjectEncoder

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<H> Freeze for SdObjectEncoder<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for SdObjectEncoder<H>
where H: RefUnwindSafe,

§

impl<H> Send for SdObjectEncoder<H>

§

impl<H> Sync for SdObjectEncoder<H>

§

impl<H> Unpin for SdObjectEncoder<H>
where H: Unpin,

§

impl<H> UnwindSafe for SdObjectEncoder<H>
where H: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V