#[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>,
}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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.vct: StringThe 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
impl TypeMetadata
Sourcepub fn parse(document: &[u8]) -> Result<Self, TypeMetadataError>
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.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
This metadata with description.
Sourcepub fn with_extends(
self,
vct: impl Into<String>,
integrity: Option<String>,
) -> Self
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.
Sourcepub fn with_display(self, display: DisplayMetadata) -> Self
pub fn with_display(self, display: DisplayMetadata) -> Self
This metadata with display added.
Sourcepub fn with_claim(self, claim: ClaimMetadata) -> Self
pub fn with_claim(self, claim: ClaimMetadata) -> Self
This metadata with claim added.
Sourcepub fn check(&self) -> Result<(), TypeMetadataError>
pub fn check(&self) -> Result<(), TypeMetadataError>
Checks the claim metadata: each well-formed, svg_ids unique.
§Errors
TypeMetadataError::InvalidClaimMetadata or TypeMetadataError::DuplicateSvgId.
Sourcepub fn claim(&self, path: &ClaimPath) -> Option<&ClaimMetadata>
pub fn claim(&self, path: &ClaimPath) -> Option<&ClaimMetadata>
The claim metadata for path, if any.
Sourcepub fn extend(self, parent: &TypeMetadata) -> Result<Self, TypeMetadataError>
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.
Sourcepub fn check_claims(
&self,
processed: &Processed,
complete: bool,
) -> Result<(), TypeMetadataError>
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
impl Clone for TypeMetadata
Source§impl Debug for TypeMetadata
impl Debug for TypeMetadata
Source§impl<'de> Deserialize<'de> for TypeMetadata
impl<'de> Deserialize<'de> for TypeMetadata
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for TypeMetadata
Source§impl PartialEq for TypeMetadata
impl PartialEq for TypeMetadata
Source§impl PartialSchema for TypeMetadata
Available on crate feature utoipa only.
impl PartialSchema for TypeMetadata
utoipa only.Source§impl Serialize for TypeMetadata
impl Serialize for TypeMetadata
impl StructuralPartialEq for TypeMetadata
Auto Trait Implementations§
impl Freeze for TypeMetadata
impl RefUnwindSafe for TypeMetadata
impl Send for TypeMetadata
impl Sync for TypeMetadata
impl Unpin for TypeMetadata
impl UnsafeUnpin for TypeMetadata
impl UnwindSafe for TypeMetadata
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.