1use zvault_storage::StorageError;
8
9#[derive(Debug, thiserror::Error)]
11pub enum CryptoError {
12 #[error("encryption failed: {reason}")]
14 Encryption { reason: String },
15
16 #[error("decryption failed: {reason}")]
18 Decryption { reason: String },
19
20 #[error("key derivation failed for context '{context}': {reason}")]
22 KeyDerivation { context: String, reason: String },
23
24 #[error("ciphertext too short: expected at least {expected} bytes, got {actual}")]
26 CiphertextTooShort { expected: usize, actual: usize },
27}
28
29#[derive(Debug, thiserror::Error)]
31pub enum BarrierError {
32 #[error("vault is sealed")]
34 Sealed,
35
36 #[error("barrier crypto error: {0}")]
38 Crypto(#[from] CryptoError),
39
40 #[error("barrier storage error: {0}")]
42 Storage(#[from] StorageError),
43}
44
45#[derive(Debug, thiserror::Error)]
47pub enum SealError {
48 #[error("vault is already initialized")]
50 AlreadyInitialized,
51
52 #[error("vault is not initialized")]
54 NotInitialized,
55
56 #[error("vault is already unsealed")]
58 AlreadyUnsealed,
59
60 #[error("vault is already sealed")]
62 AlreadySealed,
63
64 #[error("invalid seal config: {reason}")]
66 InvalidConfig { reason: String },
67
68 #[error("invalid unseal share: {reason}")]
70 InvalidShare { reason: String },
71
72 #[error("share recovery failed: {reason}")]
74 RecoveryFailed { reason: String },
75
76 #[error("root key decryption failed: {reason}")]
78 RootKeyDecryption { reason: String },
79
80 #[error("seal crypto error: {0}")]
82 Crypto(#[from] CryptoError),
83
84 #[error("seal barrier error: {0}")]
86 Barrier(#[from] BarrierError),
87
88 #[error("seal storage error: {0}")]
90 Storage(#[from] StorageError),
91}
92
93#[derive(Debug, thiserror::Error)]
95pub enum TokenError {
96 #[error("token not found")]
98 NotFound,
99
100 #[error("token expired at {expired_at}")]
102 Expired { expired_at: String },
103
104 #[error("token is not renewable")]
106 NotRenewable,
107
108 #[error("token has exceeded max TTL of {max_ttl_secs}s")]
110 MaxTtlExceeded { max_ttl_secs: i64 },
111
112 #[error("token barrier error: {0}")]
114 Barrier(#[from] BarrierError),
115}
116
117#[derive(Debug, thiserror::Error)]
119pub enum PolicyError {
120 #[error("policy not found: {name}")]
122 NotFound { name: String },
123
124 #[error("invalid policy: {reason}")]
126 Invalid { reason: String },
127
128 #[error("cannot modify built-in policy: {name}")]
130 BuiltIn { name: String },
131
132 #[error("permission denied on path '{path}' for capability '{capability}'")]
134 Denied { path: String, capability: String },
135
136 #[error("policy barrier error: {0}")]
138 Barrier(#[from] BarrierError),
139}
140
141#[derive(Debug, thiserror::Error)]
143pub enum AuditError {
144 #[error("all audit backends failed (fail-closed)")]
146 AllBackendsFailed,
147
148 #[error("audit backend '{name}' failed: {reason}")]
150 BackendFailure { name: String, reason: String },
151
152 #[error("audit serialization failed: {reason}")]
154 Serialization { reason: String },
155}
156
157#[derive(Debug, thiserror::Error)]
159pub enum MountError {
160 #[error("mount path already in use: {path}")]
162 AlreadyMounted { path: String },
163
164 #[error("mount not found: {path}")]
166 NotFound { path: String },
167
168 #[error("invalid mount path: {reason}")]
170 InvalidPath { reason: String },
171
172 #[error("unknown engine type: {engine_type}")]
174 UnknownEngineType { engine_type: String },
175
176 #[error("mount barrier error: {0}")]
178 Barrier(#[from] BarrierError),
179}
180
181#[derive(Debug, thiserror::Error)]
183pub enum EngineError {
184 #[error("secret not found at path '{path}'")]
186 NotFound { path: String },
187
188 #[error("invalid engine request: {reason}")]
190 InvalidRequest { reason: String },
191
192 #[error("engine barrier error: {0}")]
194 Barrier(#[from] BarrierError),
195
196 #[error("engine internal error: {reason}")]
198 Internal { reason: String },
199}
200
201#[derive(Debug, thiserror::Error)]
203pub enum LeaseError {
204 #[error("lease not found: {lease_id}")]
206 NotFound { lease_id: String },
207
208 #[error("lease already expired: {lease_id}")]
210 Expired { lease_id: String },
211
212 #[error("lease is not renewable: {lease_id}")]
214 NotRenewable { lease_id: String },
215
216 #[error("lease barrier error: {0}")]
218 Barrier(#[from] BarrierError),
219}
220
221#[derive(Debug, thiserror::Error)]
223pub enum DatabaseError {
224 #[error("database config not found: {name}")]
226 NotFound { name: String },
227
228 #[error("database role not found: {name}")]
230 RoleNotFound { name: String },
231
232 #[error("invalid database config: {reason}")]
234 InvalidConfig { reason: String },
235
236 #[error("database engine error: {reason}")]
238 Internal { reason: String },
239
240 #[error("database barrier error: {0}")]
242 Barrier(#[from] BarrierError),
243}
244
245#[derive(Debug, thiserror::Error)]
247pub enum PkiError {
248 #[error("no root CA configured — generate one first")]
250 NoRootCa,
251
252 #[error("PKI role not found: {name}")]
254 RoleNotFound { name: String },
255
256 #[error("invalid PKI request: {reason}")]
258 InvalidRequest { reason: String },
259
260 #[error("certificate generation failed: {reason}")]
262 CertGeneration { reason: String },
263
264 #[error("PKI engine error: {reason}")]
266 Internal { reason: String },
267
268 #[error("PKI barrier error: {0}")]
270 Barrier(#[from] BarrierError),
271}
272
273#[derive(Debug, thiserror::Error)]
275pub enum AppRoleError {
276 #[error("approle role not found: {name}")]
278 RoleNotFound { name: String },
279
280 #[error("invalid secret ID for role '{role_name}'")]
282 InvalidSecretId { role_name: String },
283
284 #[error("invalid approle config: {reason}")]
286 InvalidConfig { reason: String },
287
288 #[error("approle error: {reason}")]
290 Internal { reason: String },
291
292 #[error("approle barrier error: {0}")]
294 Barrier(#[from] BarrierError),
295}