identity_credential/sd_jwt_vc/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2020-2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use serde_json::Value;
use thiserror::Error;

/// Error type that represents failures that might arise when dealing
/// with `SdJwtVc`s.
#[derive(Error, Debug)]
pub enum Error {
  /// A JWT claim required for an operation is missing.
  #[error("missing required claim \"{0}\"")]
  MissingClaim(&'static str),
  /// A JWT claim that must not be disclosed was found among the disclosed values.
  #[error("claim \"{0}\" cannot be disclosed")]
  DisclosedClaim(&'static str),
  /// Invalid value for a given JWT claim.
  #[error("invalid value for claim \"{name}\"; expected value of type {expected}, but {found} was found")]
  InvalidClaimValue {
    /// Name of the invalid claim.
    name: &'static str,
    /// Type expected for the claim's value.
    expected: &'static str,
    /// The claim's value.
    found: Value,
  },
  /// A low level SD-JWT error.
  #[error(transparent)]
  SdJwt(#[from] sd_jwt_payload_rework::Error),
  /// Value of header parameter `typ` is not valid.
  #[error("invalid \"typ\" value; expected \"vc+sd-jwt\" (or a superset) but found \"{0}\"")]
  InvalidJoseType(String),
  /// Resolution error.
  #[error("failed to resolve \"{input}\"")]
  Resolution {
    /// The resource's identifier.
    input: String,
    /// Low level error.
    #[source]
    source: super::resolver::Error,
  },
  /// Invalid issuer Metadata object.
  #[error("invalid Issuer Metadata: {0}")]
  InvalidIssuerMetadata(#[source] anyhow::Error),
  /// Invalid credential type metadata object.
  #[error("invalid Type Metadata: {0}")]
  InvalidTypeMetadata(#[source] anyhow::Error),
  /// Credential validation failed.
  #[error("credential validation failed: {0}")]
  Validation(#[source] anyhow::Error),
  /// SD-JWT VC signature verification failed.
  #[error("verification failed: {0}")]
  Verification(#[source] anyhow::Error),
}

/// Either a value of type `T` or an [`Error`].
pub type Result<T> = std::result::Result<T, Error>;