identity_jose/
error.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Errors that may occur in the library.
5
6/// Alias for a `Result` with the error type [Error].
7pub type Result<T, E = Error> = core::result::Result<T, E>;
8
9/// All possible errors that can occur in the library.
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum Error {
13  /// Caused by invalid json serialization or deserialization.
14  #[error("invalid json")]
15  InvalidJson(#[source] serde_json::Error),
16  /// Caused by invalid base64 encoded data.
17  #[error("invalid base64")]
18  InvalidBase64(#[source] identity_core::error::Error),
19  /// Caused by bytes not being valid utf-8.
20  #[error("invalid utf-8")]
21  InvalidUtf8(#[source] core::str::Utf8Error),
22  /// Caused by a claim not being of an expected value.
23  #[error("invalid claim `{0}`")]
24  InvalidClaim(&'static str),
25  /// Caused by a missing claim.
26  #[error("missing claim `{0}`")]
27  MissingClaim(&'static str),
28  /// Caused by an parameter with an invalid value.
29  #[error("invalid param: {0}")]
30  InvalidParam(&'static str),
31  /// Caused by a missing parameter.
32  #[error("missing param `{0}`")]
33  MissingParam(&'static str),
34  /// Caused by invalid content of a JSON Web Signature.
35  #[error("{0}")]
36  InvalidContent(&'static str),
37  /// Caused by an invalid key format.
38  #[error("invalid key format for type `{0}`")]
39  KeyError(&'static str),
40  /// Caused by a string that does not correspond to a supported [`JwsAlgorithm`](crate::jws::JwsAlgorithm).
41  #[error("attempt to parse an unregistered jws algorithm")]
42  JwsAlgorithmParsingError,
43  /// Caused by an error during signature verification.
44  #[error("signature verification error; {0}")]
45  SignatureVerificationError(#[source] crate::jws::SignatureVerificationError),
46  /// Caused by a missing header.
47  #[error("missing header")]
48  MissingHeader(&'static str),
49  /// Caused by a missing `alg` claim in the protected header.
50  #[error("missing alg in protected header")]
51  ProtectedHeaderWithoutAlg,
52  /// Caused by converting keys to different types.
53  #[error("failed to convert key: `{0}`")]
54  KeyConversion(String),
55  /// Key type not supported.
56  #[error("key type not supported; {0}")]
57  UnsupportedKeyType(String),
58}