identity_credential/sd_jwt_vc/
error.rs

1// Copyright 2020-2024 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use serde_json::Value;
5use thiserror::Error;
6
7/// Error type that represents failures that might arise when dealing
8/// with `SdJwtVc`s.
9#[derive(Error, Debug)]
10pub enum Error {
11  /// A JWT claim required for an operation is missing.
12  #[error("missing required claim \"{0}\"")]
13  MissingClaim(&'static str),
14  /// A JWT claim that must not be disclosed was found among the disclosed values.
15  #[error("claim \"{0}\" cannot be disclosed")]
16  DisclosedClaim(&'static str),
17  /// Invalid value for a given JWT claim.
18  #[error("invalid value for claim \"{name}\"; expected value of type {expected}, but {found} was found")]
19  InvalidClaimValue {
20    /// Name of the invalid claim.
21    name: &'static str,
22    /// Type expected for the claim's value.
23    expected: &'static str,
24    /// The claim's value.
25    found: Value,
26  },
27  /// A low level SD-JWT error.
28  #[error(transparent)]
29  SdJwt(#[from] sd_jwt_payload_rework::Error),
30  /// Value of header parameter `typ` is not valid.
31  #[error("invalid \"typ\" value; expected \"vc+sd-jwt\" (or a superset) but found \"{0}\"")]
32  InvalidJoseType(String),
33  /// Resolution error.
34  #[error("failed to resolve \"{input}\"")]
35  Resolution {
36    /// The resource's identifier.
37    input: String,
38    /// Low level error.
39    #[source]
40    source: super::resolver::Error,
41  },
42  /// Invalid issuer Metadata object.
43  #[error("invalid Issuer Metadata: {0}")]
44  InvalidIssuerMetadata(#[source] anyhow::Error),
45  /// Invalid credential type metadata object.
46  #[error("invalid Type Metadata: {0}")]
47  InvalidTypeMetadata(#[source] anyhow::Error),
48  /// Credential validation failed.
49  #[error("credential validation failed: {0}")]
50  Validation(#[source] anyhow::Error),
51  /// SD-JWT VC signature verification failed.
52  #[error("verification failed: {0}")]
53  Verification(#[source] anyhow::Error),
54}
55
56/// Either a value of type `T` or an [`Error`].
57pub type Result<T> = std::result::Result<T, Error>;