identity_storage/storage/
error.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::key_id_storage::KeyIdStorageError;
5use crate::key_id_storage::MethodDigestConstructionError;
6use crate::key_storage::KeyStorageError;
7
8/// Errors that can occur when working with the [`JwkDocumentExt`](crate::storage::JwkDocumentExt) API.
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum JwkStorageDocumentError {
12  /// Caused by a failure in the key storage.
13  #[error("storage operation failed: key storage error")]
14  KeyStorageError(KeyStorageError),
15  /// Caused by a failure in the key id storage.
16  #[error("storage operation failed: key id storage error: {0}")]
17  KeyIdStorageError(KeyIdStorageError),
18  /// Caused by an attempt to add a method with a fragment that already exists.
19  #[error("could not add method: the fragment already exists")]
20  FragmentAlreadyExists,
21  /// Caused by a missing verification method.
22  #[error("method not found")]
23  MethodNotFound,
24  /// Caused by the usage of a non-JWK method where a JWK method is expected.
25  #[error("invalid method data format: expected publicKeyJwk")]
26  NotPublicKeyJwk,
27  /// Caused by an invalid JWS algorithm.
28  #[error("invalid JWS algorithm")]
29  InvalidJwsAlgorithm,
30  /// Caused by an invalid JWP algorithm.
31  #[error("invalid JWP algorithm")]
32  InvalidJwpAlgorithm,
33  /// Cannot construct a valid Jwp (issued or presented form)
34  #[error("Not able to construct a valid Jwp")]
35  JwpBuildingError,
36  /// Credential's proof update internal error
37  #[error("Credential's proof internal error")]
38  ProofUpdateError(String),
39  /// Caused by a failure to construct a verification method.
40  #[error("method generation failed: unable to create a valid verification method")]
41  VerificationMethodConstructionError(#[source] identity_verification::Error),
42  /// Caused by an encoding error.
43  #[error("could not produce jwt: encoding error")]
44  EncodingError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
45  /// Caused by a failure to construct a method digest.
46  #[error("unable to produce method digest")]
47  MethodDigestConstructionError(#[source] MethodDigestConstructionError),
48  /// Caused by a failure during (de)serialization of JWS claims.
49  #[error("could not produce JWS payload from the given claims: serialization failed")]
50  ClaimsSerializationError(#[source] identity_credential::Error),
51  /// Caused by a failure to undo a failed storage operation.
52  #[error("storage operation failed after altering state. Unable to undo operation(s): {message}")]
53  UndoOperationFailed {
54    /// Additional error context.
55    message: String,
56    /// The source error.
57    source: Box<Self>,
58    /// The error that occurred during the undo operation.
59    undo_error: Option<Box<Self>>,
60  },
61}
62
63#[cfg(test)]
64mod tests {
65  use super::JwkStorageDocumentError;
66  fn is_send_sync<T: Send + Sync + 'static>(_input: T) {}
67
68  #[test]
69  fn error_is_send_sync() {
70    is_send_sync(JwkStorageDocumentError::FragmentAlreadyExists);
71  }
72}