pub struct Disclosure { /* private fields */ }sd-jwt only.Expand description
A disclosure: the salt, the claim name (for an object property; an array element has none) and the claim value, base64url-encoded as a JSON array.
A disclosure keeps the encoded string it was parsed from, since the digest is taken over that string and any JSON serialization of the array is as valid as another.
§Examples
use identity_kit::sd_jwt_vc::{Disclosure, HashAlgorithm};
use serde_json::json;
// RFC 9901 §4.2.1.
let disclosure: Disclosure =
"WyJfMjZiYzRMVC1hYzZxMktJNmNCVzVlcyIsICJmYW1pbHlfbmFtZSIsICJNw7ZiaXVzIl0".parse()?;
assert_eq!(disclosure.salt(), "_26bc4LT-ac6q2KI6cBW5es");
assert_eq!(disclosure.name(), Some("family_name"));
assert_eq!(disclosure.value(), &json!("Möbius"));
assert_eq!(
disclosure.digest(HashAlgorithm::Sha256),
"X9yH0Ajrdm1Oij4tWso9UzzKJvPoDxwmuEcO3XAdRC0"
);
// RFC 9901 §4.2.2: an array element.
let element: Disclosure = "WyJsa2x4RjVqTVlsR1RQVW92TU5JdkNBIiwgIkZSIl0".parse()?;
assert_eq!(element.name(), None);
assert_eq!(element.value(), &json!("FR"));Implementations§
Source§impl Disclosure
impl Disclosure
Sourcepub fn property(
salt: impl Into<String>,
name: impl Into<String>,
value: Value,
) -> Self
pub fn property( salt: impl Into<String>, name: impl Into<String>, value: Value, ) -> Self
A disclosure for the object property name with value, encoded as compact JSON.
Sourcepub fn element(salt: impl Into<String>, value: Value) -> Self
pub fn element(salt: impl Into<String>, value: Value) -> Self
A disclosure for the array element value, encoded as compact JSON.
Sourcepub fn parse(encoded: &str) -> Result<Self, SdJwtError>
pub fn parse(encoded: &str) -> Result<Self, SdJwtError>
Decodes the base64url string encoded.
§Errors
SdJwtError::InvalidDisclosure when the string is not base64url of a JSON array of
two elements (a string salt and a value) or three (a string salt, a string name and a
value).
Sourcepub fn is_element(&self) -> bool
pub fn is_element(&self) -> bool
Whether this discloses an array element rather than an object property.
Sourcepub fn digest(&self, alg: HashAlgorithm) -> String
pub fn digest(&self, alg: HashAlgorithm) -> String
The digest of the encoded disclosure under alg (RFC 9901 §4.2.3).
Trait Implementations§
Source§impl AsRef<str> for Disclosure
impl AsRef<str> for Disclosure
Source§impl Clone for Disclosure
impl Clone for Disclosure
Source§impl Debug for Disclosure
impl Debug for Disclosure
Source§impl<'de> Deserialize<'de> for Disclosure
impl<'de> Deserialize<'de> for Disclosure
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for Disclosure
impl Display for Disclosure
impl Eq for Disclosure
Source§impl FromStr for Disclosure
impl FromStr for Disclosure
Source§impl PartialEq for Disclosure
impl PartialEq for Disclosure
Source§impl Serialize for Disclosure
impl Serialize for Disclosure
impl StructuralPartialEq for Disclosure
Auto Trait Implementations§
impl Freeze for Disclosure
impl RefUnwindSafe for Disclosure
impl Send for Disclosure
impl Sync for Disclosure
impl Unpin for Disclosure
impl UnsafeUnpin for Disclosure
impl UnwindSafe for Disclosure
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.