Struct sd_jwt_payload::SdObjectEncoder
source · 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
impl SdObjectEncoder
sourcepub fn new(object: &str) -> Result<SdObjectEncoder<Sha256Hasher>>
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.
sourcepub fn try_from_serializable<T: Serialize>(object: T) -> Result<Self, Error>
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>
impl<H: Hasher> SdObjectEncoder<H>
sourcepub fn with_custom_hasher(object: &str, hasher: H) -> Result<Self>
pub fn with_custom_hasher(object: &str, hasher: H) -> Result<Self>
Creates a new SdObjectEncoder with custom hash function to create digests.
sourcepub fn conceal(
&mut self,
path: &str,
salt: Option<String>
) -> Result<Disclosure>
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
Error::InvalidPathif pointer is invalid.Error::DataTypeMismatchif existing SD format is invalid.
sourcepub fn add_sd_alg_property(&mut self) -> Option<Value>
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.
sourcepub fn try_to_string(&self) -> Result<String>
pub fn try_to_string(&self) -> Result<String>
Returns the modified object as a string.
sourcepub fn add_decoys(&mut self, path: &str, number_of_decoys: usize) -> Result<()>
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.
Trait Implementations§
source§impl<H: Clone + Hasher> Clone for SdObjectEncoder<H>
impl<H: Clone + Hasher> Clone for SdObjectEncoder<H>
source§fn clone(&self) -> SdObjectEncoder<H>
fn clone(&self) -> SdObjectEncoder<H>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more