pub struct Integrity { /* private fields */ }Available on crate feature
sd-jwt only.Expand description
Integrity metadata (SD-JWT VC §6, W3C SRI §3): one or more <algorithm>-<base64 digest>
expressions separated by whitespace, verified against the octets of the retrieved
document with the strongest algorithm this crate supports.
§Examples
use identity_kit::sd_jwt_vc::{Integrity, IntegrityAlgorithm};
let document = br#"{"vct":"https://example.com/base-type-metadata"}"#;
let integrity = Integrity::compute(IntegrityAlgorithm::Sha256, document);
assert!(integrity.as_str().starts_with("sha256-"));
assert!(integrity.verify(document).is_ok());
assert!(integrity.verify(b"{}").is_err());
// SD-JWT VC §5.1, Figure 17.
let integrity: Integrity = "sha256-ilOUJsTultOwLfz7QUcFALaRa3BP/jelX1ds04kB9yU=".parse()?;
assert_eq!(integrity.algorithms(), vec![IntegrityAlgorithm::Sha256]);Implementations§
Source§impl Integrity
impl Integrity
Sourcepub fn parse(metadata: &str) -> Self
pub fn parse(metadata: &str) -> Self
Parses metadata, keeping the expressions of the algorithms this crate supports.
Sourcepub fn compute(algorithm: IntegrityAlgorithm, document: &[u8]) -> Self
pub fn compute(algorithm: IntegrityAlgorithm, document: &[u8]) -> Self
The integrity metadata of document under algorithm.
Sourcepub fn algorithms(&self) -> Vec<IntegrityAlgorithm>
pub fn algorithms(&self) -> Vec<IntegrityAlgorithm>
The supported algorithms the metadata uses, strongest last.
Sourcepub fn verify(&self, document: &[u8]) -> Result<(), IntegrityError>
pub fn verify(&self, document: &[u8]) -> Result<(), IntegrityError>
Checks document against the expressions of the strongest supported algorithm.
§Errors
IntegrityError::NoSupportedAlgorithm or IntegrityError::Mismatch.
Trait Implementations§
impl Eq for Integrity
impl StructuralPartialEq for Integrity
Auto Trait Implementations§
impl Freeze for Integrity
impl RefUnwindSafe for Integrity
impl Send for Integrity
impl Sync for Integrity
impl Unpin for Integrity
impl UnsafeUnpin for Integrity
impl UnwindSafe for Integrity
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
Compare self to
key and return true if they are equal.