identity_storage/storage/
error.rs

1// Copyright 2020-2025 IOTA Stiftung, Fondazione LINKS
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 the usage of a non-Composite method where a Composite method is expected.
28  #[error("invalid method data format: expected compositePublicKey")]
29  NotCompositePublicKey,
30  /// Caused by an invalid JWS algorithm.
31  #[error("invalid JWS algorithm")]
32  InvalidJwsAlgorithm,
33  /// Caused by an invalid JWP algorithm.
34  #[error("invalid JWP algorithm")]
35  InvalidJwpAlgorithm,
36  /// Cannot construct a valid Jwp (issued or presented form)
37  #[error("Not able to construct a valid Jwp")]
38  JwpBuildingError,
39  /// Credential's proof update internal error
40  #[error("Credential's proof internal error")]
41  ProofUpdateError(String),
42  /// Caused by a failure to construct a verification method.
43  #[error("method generation failed: unable to create a valid verification method")]
44  VerificationMethodConstructionError(#[source] identity_verification::Error),
45  /// Caused by an encoding error.
46  #[error("could not produce jwt: encoding error")]
47  EncodingError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
48  /// Caused by a failure to construct a method digest.
49  #[error("unable to produce method digest")]
50  MethodDigestConstructionError(#[source] MethodDigestConstructionError),
51  /// Caused by a failure during (de)serialization of JWS claims.
52  #[error("could not produce JWS payload from the given claims: serialization failed")]
53  ClaimsSerializationError(#[source] identity_credential::Error),
54  /// Caused by a failure to undo a failed storage operation.
55  #[error("storage operation failed after altering state. Unable to undo operation(s): {message}")]
56  UndoOperationFailed {
57    /// Additional error context.
58    message: String,
59    /// The source error.
60    source: Box<Self>,
61    /// The error that occurred during the undo operation.
62    undo_error: Option<Box<Self>>,
63  },
64}
65
66#[cfg(test)]
67mod tests {
68  use super::JwkStorageDocumentError;
69  fn is_send_sync<T: Send + Sync + 'static>(_input: T) {}
70
71  #[test]
72  fn error_is_send_sync() {
73    is_send_sync(JwkStorageDocumentError::FragmentAlreadyExists);
74  }
75}