identity_credential/
error.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Errors that may occur when working with Verifiable Credentials.
5
6/// Alias for a `Result` with the error type [`Error`].
7pub type Result<T, E = Error> = ::core::result::Result<T, E>;
8
9/// This type represents errors that can occur when constructing credentials and presentations or their serializations.
10#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
11#[non_exhaustive]
12pub enum Error {
13  /// Caused when constructing a credential or presentation without a valid base context.
14  #[error("missing base context")]
15  MissingBaseContext,
16  /// Caused when constructing a credential or presentation without a valid base type.
17  #[error("missing base type")]
18  MissingBaseType,
19  /// Caused when constructing a credential without an issuer.
20  #[error("missing credential issuer")]
21  MissingIssuer,
22  /// Caused when constructing a credential without a subject.
23  #[error("missing credential subject")]
24  MissingSubject,
25  /// Caused when constructing a Domain Linkage credential without an expiration date.
26  #[error("missing expiration date")]
27  MissingExpirationDate,
28  /// Caused when constructing a Domain Linkage credential without an origin.
29  #[error("missing origin")]
30  MissingOrigin,
31  /// Caused when constructing a credential with a malformed subject.
32  #[error("invalid credential subject")]
33  InvalidSubject,
34  /// Caused when trying to construct an invalid status.
35  #[error("invalid credential status: {0}")]
36  InvalidStatus(String),
37  /// Caused when constructing an invalid `LinkedDomainService` or `DomainLinkageConfiguration`.
38  #[error("domain linkage error: {0}")]
39  DomainLinkageError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
40  /// Caused when constructing an invalid `LinkedVerifiablePresentationService`.
41  #[error("linked verifiable presentation error: {0}")]
42  LinkedVerifiablePresentationError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
43  /// Caused when attempting to encode a `Credential` containing multiple subjects as a JWT.  
44  #[error("could not create JWT claim set from verifiable credential: more than one subject")]
45  MoreThanOneSubjectInJwt,
46  /// Caused when attempting to convert a JWT to a `Credential` that has conflicting values
47  /// between the registered claims and those in the `vc` object.
48  #[error("could not convert JWT to the VC data model: {0}")]
49  InconsistentCredentialJwtClaims(&'static str),
50
51  /// Caused when deserializing a Presentation with an empty array for the
52  /// `verifiableCredential` property.
53  #[error("empty verifiableCredential array in presentation")]
54  EmptyVerifiableCredentialArray,
55
56  /// Caused when attempting to convert a JWT to a `Presentation` that has conflicting values
57  /// between the registered claims and those in the `vp` object.
58  #[error("could not convert JWT to the VP data model: {0}")]
59  InconsistentPresentationJwtClaims(&'static str),
60  /// Caused when attempting to parse a timestamp value that is outside the
61  /// valid range defined in [RFC 3339](https://tools.ietf.org/html/rfc3339).  
62  #[error("timestamp conversion failed")]
63  TimestampConversionError,
64
65  /// Caused by a failure to serialize the JWT claims set representation of a `Credential` or `Presentation`
66  /// to JSON.
67  #[error("could not serialize JWT claims set")]
68  JwtClaimsSetSerializationError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
69
70  /// Caused by a failure to deserialize the JWT claims set representation of a `Credential` or `Presentation` from
71  /// JSON.
72  #[error("could not deserialize JWT claims set")]
73  JwtClaimsSetDeserializationError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
74
75  /// Caused by a failure to deserialize the JPT claims set representation of a `Credential` JSON.
76  #[error("could not deserialize JWT claims set")]
77  JptClaimsSetDeserializationError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
78
79  /// Cause by an invalid attribute path
80  #[error("Attribute Not found")]
81  SelectiveDisclosureError,
82
83  /// Failure of an SD-JWT VC operation.
84  #[cfg(feature = "sd-jwt-vc")]
85  #[error(transparent)]
86  SdJwtVc(#[from] crate::sd_jwt_vc::Error),
87}