Skip to main content

DisclosureSet

Struct DisclosureSet 

Source
pub struct DisclosureSet { /* private fields */ }
Expand description

A collection of Salted Disclosed Claims.

Implementations§

Source§

impl DisclosureSet

Source

pub fn new() -> Self

Creates an empty disclosure set.

Source

pub fn from_disclosures<I>(disclosures: I) -> Self
where I: IntoIterator<Item = Disclosure>,

Creates a disclosure set from an iterator.

Source

pub fn from_unprotected(header: &Header) -> Result<Self, Error>

Decodes the sd_claims unprotected header parameter.

Source

pub fn as_slice(&self) -> &[Disclosure]

Returns the disclosures.

Examples found in repository?
examples/basic.rs (line 91)
58fn main() -> Result<(), Error> {
59    // Start from a pre-issued claim set. Tag 58 asks the issuer to redact a
60    // map key/value pair or an array element. Tag 62 asks for a decoy digest.
61    let preissued_claims = Value::Map(vec![
62        (Value::from(1), Value::from("https://issuer.example")),
63        (Value::from(8), Value::Map(vec![])), // cnf; fill with a real COSE key in production.
64        (
65            Value::Tag(TO_BE_REDACTED_TAG, Box::new(Value::from("name"))),
66            Value::from("Alice Example"),
67        ),
68        (
69            Value::from("roles"),
70            Value::Array(vec![
71                Value::Tag(TO_BE_REDACTED_TAG, Box::new(Value::from("admin"))),
72                Value::from("user"),
73            ]),
74        ),
75        (
76            Value::Tag(TO_BE_DECOY_TAG, Box::new(Value::from(1))),
77            Value::Null,
78        ),
79    ]);
80
81    // The library never generates randomness. Issuers provide fresh 16-byte
82    // salts. This deterministic generator is for a reproducible example only.
83    let mut salts = deterministic_demo_salts();
84    let issued = issue_from_preissuance(preissued_claims, &mut salts, &Sha256RedactionHasher)?;
85
86    // Sign the issued SD-CWT as a COSE_Sign1 message. The payload contains the
87    // redacted claims; sd_claims carries all disclosures for the Holder.
88    let mut sd_cwt = Sign1Message::new(Some(cbor2::to_vec(&issued.value)?));
89    set_sd_cwt_typ(&mut sd_cwt.protected);
90    set_sd_alg(&mut sd_cwt.protected, Sha256RedactionHasher.algorithm());
91    set_disclosures(&mut sd_cwt.unprotected, issued.disclosures.as_slice());
92    let encoded = sd_cwt.sign_and_encode(&Issuer, None)?;
93
94    // Holder receives every disclosure at issuance, so Holder validation uses
95    // the strict one-to-one rule: every redaction must have a disclosure.
96    let holder_sd_cwt = Sign1Message::verify_and_decode(&IssuerVerifier, &encoded, None)?;
97    let holder_claims = restore_payload_from_message(&holder_sd_cwt, RestoreMode::Holder)?;
98    println!("holder disclosed claims: {}", holder_claims.disclosed);
99
100    // During presentation, the Holder can disclose a subset. Unprotected
101    // headers are not issuer-signed; production presentations bind the selected
102    // disclosures with a Key Binding Token (KBT).
103    let mut presented = holder_sd_cwt.clone();
104    let selected = issued.disclosures.as_slice()[0].clone();
105    set_disclosures(&mut presented.unprotected, std::slice::from_ref(&selected));
106
107    let verifier_claims = restore_payload_from_message(&presented, RestoreMode::Verifier)?;
108    println!(
109        "verifier disclosed claims: {}, removed redactions: {}",
110        verifier_claims.disclosed, verifier_claims.removed_redactions
111    );
112
113    Ok(())
114}
Source

pub fn push(&mut self, disclosure: Disclosure)

Appends a disclosure.

Source

pub fn is_empty(&self) -> bool

Returns true when there are no disclosures.

Source

pub fn len(&self) -> usize

Returns the number of disclosures.

Source

pub fn write_unprotected(&self, header: &mut Header)

Writes this set to the sd_claims unprotected header parameter.

Per the draft, an empty disclosure set omits sd_claims.

Trait Implementations§

Source§

impl Clone for DisclosureSet

Source§

fn clone(&self) -> DisclosureSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DisclosureSet

Source§

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

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

impl Default for DisclosureSet

Source§

fn default() -> DisclosureSet

Returns the “default value” for a type. Read more
Source§

impl IntoIterator for DisclosureSet

Source§

type Item = Disclosure

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Disclosure>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a DisclosureSet

Source§

type Item = &'a Disclosure

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Disclosure>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for DisclosureSet

Source§

fn eq(&self, other: &DisclosureSet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DisclosureSet

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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.