Skip to main content

signstar_config/yubihsm2/
error.rs

1use signstar_yubihsm2::yubihsm::Id;
2
3use crate::yubihsm2::admin_credentials::YubiHsm2AdminCredentials;
4
5/// An error that may occur when using YubiHSM2 config objects.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// There is no usable administrative user on the backend.
9    #[error(
10        "There is no usable administrative user in the YubiHSM2 backend. It needs to be reset."
11    )]
12    NoUsableAdmin,
13
14    /// The default administrative credentials are still usable in the backend.
15    #[error(
16        "The default administrative credentials ({}: {}) are still usable on the YubiHSM2 backend.",
17        YubiHsm2AdminCredentials::DEFAULT_ID,
18        YubiHsm2AdminCredentials::DEFAULT_PASSPHRASE
19    )]
20    DefaultAdminStillUsable,
21
22    /// A generic error.
23    #[error("A generic YubiHSM2 backend error occurred while {context}")]
24    Generic {
25        /// The context in which the error happened.
26        ///
27        /// This is meant to complete the sentence "A generic YubiHSM2 backend error occurred while
28        /// ".
29        context: &'static str,
30    },
31
32    /// An error occurred while retrieving data from the backend.
33    #[error("YubiHSM2 data retrieval error while {context}: {source}")]
34    DataRetrieval {
35        /// The reason why data retrieval failed.
36        ///
37        /// This is meant to complete the sentence "YubiHSM2 data retrieval error while ".
38        context: &'static str,
39
40        /// The error source.
41        source: signstar_yubihsm2::Error,
42    },
43
44    /// Encountered duplicate credentials.
45    #[error(
46        "Duplicate credentials {} encountered while {context}",
47        duplicates.iter().map(|id| id.to_string()).collect::<Vec<_>>().join(", "),
48    )]
49    DuplicateCredentials {
50        /// The context in which the error occurred.
51        ///
52        /// This is meant to complete the sentence "Duplicate credentials {} encountered while ".
53        context: &'static str,
54
55        /// The IDs of duplicate credentials.
56        duplicates: Vec<Id>,
57    },
58
59    /// Encountered user mappings without credentials.
60    #[error(
61        "User mapping(s) without credentials encountered while {context}: {}",
62        ids.iter().map(|id| id.to_string()).collect::<Vec<_>>().join(", "),
63    )]
64    UserMappingWithoutCredentials {
65        /// The context in which the error occurred.
66        ///
67        /// This is meant to complete the sentence "User mapping without credentials ({})
68        /// encountered while ".
69        context: &'static str,
70
71        /// The IDs of the user mappings without credentials.
72        ids: Vec<Id>,
73    },
74
75    /// Credentials without a matching user mapping found.
76    #[error(
77        "Credentials without a matching user mapping encountered while {context}: {}",
78        ids.iter().map(|id| id.to_string()).collect::<Vec<_>>().join(", "),
79    )]
80    CredentialsWithoutUserMapping {
81        /// The context in which the error occurred.
82        ///
83        /// This is meant to complete the sentence "User mapping without credentials ({})
84        /// encountered while ".
85        context: &'static str,
86
87        /// The IDs of the user mappings without credentials.
88        ids: Vec<Id>,
89    },
90
91    /// An error occurred in the logic of a scenario.
92    #[error("YubiHSM2 scenario logic error because {context}")]
93    ScenarioLogic {
94        /// The reason why the scenario logic failed.
95        ///
96        /// This is meant to complete the sentence "YubiHSM2 scenario logic error because ".
97        context: String,
98    },
99}