Skip to main content

signstar_config/nethsm/
error.rs

1//! Error handling specific to interacting with a [`NetHsmBackend`].
2
3use nethsm::{KeyId, NamespaceId, Url, UserId};
4
5#[cfg(doc)]
6use crate::{
7    config::Config,
8    nethsm::{NetHsmAdminCredentials, NetHsmBackend},
9};
10
11/// An error that may occur when handling a NetHSM backend.
12#[derive(Debug, thiserror::Error)]
13pub enum Error {
14    /// A system-wide key misses a tag.
15    #[error("The system-wide key {key_id} misses the tag {tag}")]
16    KeyIsMissingTag {
17        /// The [`KeyId`] of the missing key.
18        key_id: KeyId,
19
20        /// The missing tag.
21        tag: String,
22    },
23
24    /// A system-wide key is missing.
25    #[error("The system-wide key {key_id} is missing")]
26    KeyMissing {
27        /// The [`KeyId`] of the missing key.
28        key_id: KeyId,
29    },
30
31    /// A key has an unexpected number of tags assigned to it.
32    #[error(
33        "The key {key_id} has an unexpected number of tags assigned to it ({number} instead of 1)"
34    )]
35    KeyUnexpectedNumberOfTags {
36        /// The [`KeyId`] of the key that has an unexpected number of tags.
37        key_id: KeyId,
38
39        /// The encountered number of tags.
40        number: usize,
41    },
42
43    /// A namespace admin is not in a namespace.
44    #[error("The NetHSM namespace administrator is not in a namespace: {user}")]
45    NamespaceAdminHasNoNamespace {
46        /// The [`UserId`] of the namespace administrator without a namespace.
47        user: UserId,
48    },
49
50    /// A namespace exists, but no N-Administrator is available for it.
51    #[error(
52        "There is no known N-Administrator available in the namespace {namespace} on the NetHSM backend at {url}"
53    )]
54    NamespaceHasNoAdmin {
55        /// The namespace for which no N-Administrator is available.
56        namespace: NamespaceId,
57
58        /// The URL of the NetHSM backend.
59        url: Url,
60    },
61
62    /// A namespaced key misses a tag.
63    #[error("The key {key_id} in namespace {namespace} misses the tag {tag}")]
64    NamespaceKeyMissesTag {
65        /// The [`KeyId`] of the missing key.
66        key_id: KeyId,
67
68        /// The namespace of the key that is missing a tag.
69        namespace: NamespaceId,
70
71        /// The missing tag.
72        tag: String,
73    },
74
75    /// A namespaced key is missing.
76    #[error("The key {key_id} in namespace {namespace} is missing")]
77    NamespaceKeyMissing {
78        /// The [`KeyId`] of the missing key.
79        key_id: KeyId,
80
81        /// The namespace of the key that is missing.
82        namespace: NamespaceId,
83    },
84
85    /// A namespace does not (yet) exist.
86    #[error("The is namespace {namespace} does not exist (yet)")]
87    NamespaceMissing {
88        /// The namespace that does not (yet) exist.
89        namespace: NamespaceId,
90    },
91
92    /// There is no User ID for an OpenPGP certificate that is supposed to be created.
93    #[error(
94        "The options for the OpenPGP certificate for key {key_id} in namespace {namespace} do not provide a User ID"
95    )]
96    NamespaceOpenPgpUserIdMissing {
97        /// The [`KeyId`] of the key for which the OpenPGP certificate should be created.
98        key_id: KeyId,
99
100        /// The namespace of the key for which the OpenPGP certificate should be created.
101        namespace: NamespaceId,
102    },
103
104    /// A namespaced non-administrative user misses a tag.
105    #[error("The non-administrative user {user} in namespace {namespace} misses the tag {tag}")]
106    NamespaceUserMissingTag {
107        /// The [`UserId`] of the user that misses `tag`.
108        user: UserId,
109
110        /// The namespace that user is in.
111        namespace: NamespaceId,
112
113        /// The missing tag.
114        tag: String,
115    },
116
117    /// A user is not in a specific namespace.
118    #[error("The user {user} is not the namespace {namespace}")]
119    NamespaceUserMissing {
120        /// The [`UserId`] of the user not in `namespace`.
121        user: UserId,
122
123        /// The [`NamespaceId`] of the namespace that `user` is not in.
124        namespace: NamespaceId,
125    },
126
127    /// A user is not in a namespace.
128    #[error("The user {user} is not in a namespace")]
129    NamespaceUserNoNamespace {
130        /// The [`UserId`] of the user without a namespace.
131        user: UserId,
132    },
133
134    /// A [`nethsm::UserError`] occurred.
135    #[error(transparent)]
136    NetHsmUser(#[from] nethsm::UserError),
137
138    /// There is no User ID for an OpenPGP certificate.
139    #[error("The OpenPGP certificate does not have a User ID associated with it")]
140    OpenPgpUserIdMissing {
141        /// The [`KeyId`] of the key for which the OpenPGP certificate should be created.
142        key_id: KeyId,
143    },
144
145    /// The passphrase for a system-wide non-administrative user is missing.
146    #[error("The passphrase for system-wide user {user} is missing")]
147    UserMissingPassphrase {
148        /// The [`UserId`] for which the passphrase is missing.
149        user: UserId,
150    },
151
152    /// A system-wide non-administrative user misses a tag.
153    #[error("The system-wide non-administrative user {user_id} misses the tag {tag}")]
154    UserMissingTag {
155        /// The [`UserId`] of the user that misses `tag`.
156        user_id: UserId,
157
158        /// The  missing tag.
159        tag: String,
160    },
161
162    /// A system-wide non-administrative user is missing.
163    #[error("The system-wide non-administrative user {user_id} is missing")]
164    UserMissing {
165        /// The [`UserId`] of the missing user.
166        user_id: UserId,
167    },
168
169    /// A user has an unexpected number of tags assigned to it.
170    #[error(
171        "The Operator user {user_id} has an unexpected number of tags assigned to it ({number} instead of 0 or 1)"
172    )]
173    UserUnexpectedNumberOfTags {
174        /// The [`UserId`] of the user that has an unexpected number of tags assigned to it.
175        user_id: UserId,
176
177        /// The encountered number of tags.
178        number: usize,
179    },
180}