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    /// Wraps a [`rustls::Error`] for issues with rustls based TLS setups
10    #[error("TLS error: {0}")]
11    Rustls(#[from] rustls::Error),
12
13    /// A Base64 encoded string can not be decode
14    #[error("Decoding Base64 string failed: {0}")]
15    Base64Decode(#[from] base64ct::Error),
16
17    /// A generic error with a custom message
18    #[error("NetHSM error: {0}")]
19    Default(String),
20
21    /// The loading of TLS root certificates from the platform's native certificate store failed
22    #[error("Loading system TLS certs failed: {0:?}")]
23    CertLoading(Vec<rustls_native_certs::Error>),
24
25    /// No TLS root certificates from the platform's native certificate store could be added
26    ///
27    /// Provides the number certificates that failed to be added
28    #[error("Unable to load any system TLS certs ({failed} failed)")]
29    NoSystemCertsAdded {
30        /// The number of certificates that failed to be added.
31        failed: usize,
32    },
33
34    /// A call to the NetHSM API failed
35    #[error("NetHSM API error: {0}")]
36    Api(String),
37
38    /// An error occurred in the [`connection`] module.
39    #[error("NetHSM connection error:\n{0}")]
40    Connection(#[from] crate::connection::Error),
41
42    /// An error with a key occurred
43    #[error("Key error: {0}")]
44    Key(#[from] crate::key::Error),
45
46    /// User data error
47    #[error("User data error: {0}")]
48    User(#[from] crate::user::Error),
49
50    /// OpenPGP error
51    #[error("OpenPGP error: {0}")]
52    OpenPgp(#[from] crate::openpgp::Error),
53
54    /// A signstar_crypto key error.
55    #[error("A signstar_crypto key error:\n{0}")]
56    SignstarCryptoKey(#[from] signstar_crypto::key::Error),
57}