Skip to main content

TypeMetadata

Struct TypeMetadata 

Source
#[non_exhaustive]
pub struct TypeMetadata { pub vct: String, pub name: Option<String>, pub description: Option<String>, pub extends: Option<String>, pub extends_integrity: Option<String>, pub display: Vec<DisplayMetadata>, pub claims: Vec<ClaimMetadata>, pub additional: IndexMap<String, Value>, }
Available on crate feature sd-jwt only.
Expand description

A type metadata document (§5.2).

§Examples

SD-JWT VC §5.6.5.2: a type extending another, and the effective claim metadata.

use identity_kit::sd_jwt_vc::{ClaimPath, TypeMetadata};
use serde_json::json;

let base: TypeMetadata = serde_json::from_value(json!({
  "vct": "https://example.com/base-type-metadata",
  "claims": [
    { "path": ["name"], "display": [{"label": "Full Name", "locale": "en"}] },
    { "path": ["address", "city"], "display": [{"label": "City", "locale": "en"}] }
  ]
}))?;
let child: TypeMetadata = serde_json::from_value(json!({
  "vct": "https://example.com/custom-type-metadata",
  "extends": "https://example.com/base-type-metadata",
  "claims": [
    { "path": ["address", "city"], "display": [{"label": "Town", "locale": "en"}] },
    { "path": ["nationalities"], "display": [{"label": "Nationalities", "locale": "en"}] }
  ]
}))?;
let effective = child.extend(&base)?;
let labels: Vec<_> = effective.claims.iter().map(|c| c.display[0].label.as_str()).collect();
assert_eq!(labels, ["Full Name", "Town", "Nationalities"]);
assert_eq!(effective.claims[1].path, ClaimPath::new(["address", "city"]));
assert_eq!(effective.extends, None);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§vct: String

The type described.

§name: Option<String>

A name for developers.

§description: Option<String>

A description for developers.

§extends: Option<String>

The type this one extends.

§extends_integrity: Option<String>

The integrity metadata of the extended type’s document.

§display: Vec<DisplayMetadata>

Display information per locale.

§claims: Vec<ClaimMetadata>

Claim metadata.

§additional: IndexMap<String, Value>

Every other property.

Implementations§

Source§

impl TypeMetadata

Source

pub fn new(vct: impl Into<String>) -> Self

Metadata for the type vct.

Source

pub fn parse(document: &[u8]) -> Result<Self, TypeMetadataError>

Parses a type metadata document and checks its structure.

§Errors

TypeMetadataError::Json, or the errors of check.

Source

pub fn with_name(self, name: impl Into<String>) -> Self

This metadata with name.

Source

pub fn with_description(self, description: impl Into<String>) -> Self

This metadata with description.

Source

pub fn with_extends( self, vct: impl Into<String>, integrity: Option<String>, ) -> Self

This metadata extending vct, with the integrity metadata of its document if known.

Source

pub fn with_display(self, display: DisplayMetadata) -> Self

This metadata with display added.

Source

pub fn with_claim(self, claim: ClaimMetadata) -> Self

This metadata with claim added.

Source

pub fn check(&self) -> Result<(), TypeMetadataError>

Checks the claim metadata: each well-formed, svg_ids unique.

§Errors

TypeMetadataError::InvalidClaimMetadata or TypeMetadataError::DuplicateSvgId.

Source

pub fn claim(&self, path: &ClaimPath) -> Option<&ClaimMetadata>

The claim metadata for path, if any.

Source

pub fn extend(self, parent: &TypeMetadata) -> Result<Self, TypeMetadataError>

The effective metadata of this type given the metadata of the type it extends (§5.4): the parent’s display information unless this type has its own (§5.5.2), the parent’s claim metadata with this type’s properties taking precedence per path (§5.6.5), and the parent’s extends so that a chain can be folded parent by parent.

§Errors

TypeMetadataError::WrongParent when parent is not the type this one extends, TypeMetadataError::IllegalOverride when this type changes a claim’s sd from always or never or its mandatory from true.

Source

pub fn check_claims( &self, processed: &Processed, complete: bool, ) -> Result<(), TypeMetadataError>

Validates processed against the claim metadata (§5.6): every path must fit the payload, a claim with sd: always must have come from a disclosure, one with sd: never must not have, and, when complete says every disclosure is at hand (the holder’s view), every mandatory claim must be present, unless its path runs through an undisclosed array element, whose contents are unknown.

Paths are evaluated against the payload as issued, so an undisclosed array element counts as present and selectively disclosable, with nothing beneath it.

§Errors

TypeMetadataError::Path, TypeMetadataError::SdViolation or TypeMetadataError::MissingMandatoryClaim.

Trait Implementations§

Source§

impl Clone for TypeMetadata

Source§

fn clone(&self) -> Self

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 TypeMetadata

Source§

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

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

impl<'de> Deserialize<'de> for TypeMetadata

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for TypeMetadata

Source§

impl PartialEq for TypeMetadata

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialSchema for TypeMetadata

Available on crate feature utoipa only.
Source§

fn schema() -> RefOr<Schema>

Return ref or schema of implementing type that can then be used to construct combined schemas.
Source§

impl Serialize for TypeMetadata

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for TypeMetadata

Source§

impl ToSchema for TypeMetadata

Available on crate feature utoipa only.
Source§

fn name() -> Cow<'static, str>

Return name of the schema. Read more
Source§

fn schemas(schemas: &mut Vec<(String, RefOr<Schema>)>)

Implement reference utoipa::openapi::schema::Schemas for this type. Read more

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more