Skip to main content

nethsm/
error.rs

1//! Error handling for [`NetHsm`].
2
3#[cfg(doc)]
4use crate::{NetHsm, connection};
5
6/// An error that may occur when using a NetHSM.
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9    /// A Base64 encoded string can not be decode
10    #[error("Decoding Base64 string failed: {0}")]
11    Base64Decode(#[from] base64ct::Error),
12
13    /// A backup error.
14    #[cfg(feature = "backup")]
15    #[error(transparent)]
16    Backup(#[from] crate::backup::Error),
17
18    /// A CLI error.
19    #[cfg(feature = "cli")]
20    #[error(transparent)]
21    Cli(#[from] crate::cli::Error),
22
23    /// A generic error with a custom message
24    #[error("NetHSM error: {0}")]
25    Default(String),
26
27    /// A call to the NetHSM API failed
28    #[error("NetHSM API error: {0}")]
29    Api(String),
30
31    /// An error occurred in the [`connection`] module.
32    #[error("NetHSM connection error:\n{0}")]
33    Connection(#[from] crate::connection::Error),
34
35    /// An error with a key occurred
36    #[error("Key error: {0}")]
37    Key(#[from] crate::key::Error),
38
39    /// User data error
40    #[error("User data error: {0}")]
41    User(#[from] crate::user::Error),
42
43    /// A [`signstar_crypto::Error`] occurred.
44    #[error(transparent)]
45    SignstarCrypto(#[from] signstar_crypto::Error),
46
47    /// An compatibility issue occurred in the NetHSM SDK translation interface.
48    #[error("Compatibility issue with nethsm-sdk-rs: {0}")]
49    NetHsmSdkRsCompatibility(#[from] crate::nethsm_sdk::Error),
50}