libvault 0.2.2

the libvault is modified from RustyVault
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
//! The `libvault::errors` module defines an enumeration of various error code, and implements
//! neccessary traits against it.
//!
//! The error code defined in this module are used widely in RustyVault.

use std::{
    io,
    sync::{PoisonError, RwLockReadGuard, RwLockWriteGuard},
};

use thiserror::Error;

/// Centralized error enumeration for `libvault`.
///
/// `RvError` enumerates the common error conditions surfaced by the
/// library and the server. It implements `std::error::Error` via
/// `thiserror` and includes helpers such as `response_status()` to map
/// library errors to HTTP response codes.
#[derive(Error, Debug)]
pub enum RvError {
    #[error("Cipher operation update failed.")]
    ErrCryptoCipherUpdateFailed,
    #[error("Cipher operation finalization failed.")]
    ErrCryptoCipherFinalizeFailed,
    #[error("Cipher initialization failed.")]
    ErrCryptoCipherInitFailed,
    #[error("Cipher not initialized.")]
    ErrCryptoCipherNotInited,
    #[error("Cipher operation not supported.")]
    ErrCryptoCipherOPNotSupported,
    #[error("AEAD Cipher tag is missing.")]
    ErrCryptoCipherNoTag,
    #[error("AEAD Cipher tag should not be present.")]
    ErrCryptoCipherAEADTagPresent,
    #[error("Config path is invalid.")]
    ErrConfigPathInvalid,
    #[error("Config load failed.")]
    ErrConfigLoadFailed,
    #[error("Config storage not found.")]
    ErrConfigStorageNotFound,
    #[error("Config listener not found.")]
    ErrConfigListenerNotFound,
    #[error("Core is not initialized.")]
    ErrCoreNotInit,
    #[error("Core logical backend already exists.")]
    ErrCoreLogicalBackendExist,
    #[error("Core logical backend does not exist.")]
    ErrCoreLogicalBackendNoExist,
    #[error("Core router not handling.")]
    ErrCoreRouterNotHandling,
    #[error("Core handler already exists.")]
    ErrCoreHandlerExist,
    #[error("Core seal config is invalid.")]
    ErrCoreSealConfigInvalid,
    #[error("Core seal config not found.")]
    ErrCoreSealConfigNotFound,
    #[error("Core unseal key set not found.")]
    ErrCoreDeprecatedUnsealKeySetNotFound,
    #[error("Physical configuration item is missing.")]
    ErrPhysicalConfigItemMissing,
    #[error("Physical type is invalid.")]
    ErrPhysicalTypeInvalid,
    #[error("Physical backend prefix is invalid.")]
    ErrPhysicalBackendPrefixInvalid,
    #[error("Physical backend key is invalid.")]
    ErrPhysicalBackendKeyInvalid,
    #[error("RustyVault key sanity check failed.")]
    ErrBarrierKeySanityCheckFailed,
    #[error("RustyVault is already initialized.")]
    ErrBarrierAlreadyInit,
    #[error("RustyVault unseal key is invalid.")]
    ErrBarrierKeyInvalid,
    #[error("RustyVault unseal key is deprecated.")]
    ErrBarrierKeyDeprecated,
    #[error("RustyVault is not initialized.")]
    ErrBarrierNotInit,
    #[error("RustyVault is sealed.")]
    ErrBarrierSealed,
    #[error("RustyVault is unsealing.")]
    ErrBarrierUnsealing,
    #[error("RustyVault is unsealed.")]
    ErrBarrierUnsealed,
    #[error("RustyVault unseal failed.")]
    ErrBarrierUnsealFailed,
    #[error("RustyVualt barrier epoch do not match.")]
    ErrBarrierEpochMismatch,
    #[error("RustyVault barrier version do not match.")]
    ErrBarrierVersionMismatch,
    #[error("RustyVault barrier key generation failed.")]
    ErrBarrierKeyGenerationFailed,
    #[error("Router mount conflict.")]
    ErrRouterMountConflict,
    #[error("Router mount not found.")]
    ErrRouterMountNotFound,
    #[error("Mount path is failed, cannot mount.")]
    ErrMountFailed,
    #[error("Mount path is protected, cannot mount.")]
    ErrMountPathProtected,
    #[error("Mount path already exists.")]
    ErrMountPathExist,
    #[error("Mount table not found.")]
    ErrMountTableNotFound,
    #[error("Mount table is not ready.")]
    ErrMountTableNotReady,
    #[error("Mount not match.")]
    ErrMountNotMatch,
    #[error("Logical backend path not supported.")]
    ErrLogicalPathUnsupported,
    #[error("Logical backend operation not supported.")]
    ErrLogicalOperationUnsupported,
    #[error("Request is not ready.")]
    ErrRequestNotReady,
    #[error("No data is available for the request.")]
    ErrRequestNoData,
    #[error("No data field is available for the request.")]
    ErrRequestNoDataField,
    #[error("Request is invalid.")]
    ErrRequestInvalid,
    #[error("Request client token is missing.")]
    ErrRequestClientTokenMissing,
    #[error("Request field is not found.")]
    ErrRequestFieldNotFound,
    #[error("Request field is invalid.")]
    ErrRequestFieldInvalid,
    #[error("Response data is invalid.")]
    ErrResponseDataInvalid,
    #[error("Handler is default.")]
    ErrHandlerDefault,
    #[error("Module kv data field is missing.")]
    ErrModuleKvDataFieldMissing,
    #[error("Rust downcast failed.")]
    ErrRustDowncastFailed,
    #[error("Shamir share count invalid.")]
    ErrShamirShareCountInvalid,
    #[error("Module conflict.")]
    ErrModuleConflict,
    #[error("Module is not init.")]
    ErrModuleNotInit,
    #[error("Module is not found.")]
    ErrModuleNotFound,
    #[error("Auth module is disabled.")]
    ErrAuthModuleDisabled,
    #[error("Auth token is not found.")]
    ErrAuthTokenNotFound,
    #[error("Auth token id is invalid.")]
    ErrAuthTokenIdInvalid,
    #[error("Lease is not found.")]
    ErrLeaseNotFound,
    #[error("Lease is not renewable.")]
    ErrLeaseNotRenewable,
    #[error("Permission denied.")]
    ErrPermissionDenied,
    #[error("PKI pem bundle is invalid.")]
    ErrPkiPemBundleInvalid,
    #[error("PKI ca public key of certificate does not match private key.")]
    ErrPkiCertKeyMismatch,
    #[error("PKI cert chain is incorrect.")]
    ErrPkiCertChainIncorrect,
    #[error("PKI cert is not ca.")]
    ErrPkiCertIsNotCA,
    #[error("PKI ca private key is not found.")]
    ErrPkiCaKeyNotFound,
    #[error("PKI ca is not config.")]
    ErrPkiCaNotConfig,
    #[error("PKI ca extension is incorrect.")]
    ErrPkiCaExtensionIncorrect,
    #[error("PKI key type is invalid.")]
    ErrPkiKeyTypeInvalid,
    #[error("PKI key bits is invalid.")]
    ErrPkiKeyBitsInvalid,
    #[error("PKI key_name already exists.")]
    ErrPkiKeyNameAlreadyExist,
    #[error("PKI key operation is invalid.")]
    ErrPkiKeyOperationInvalid,
    #[error("PKI certificate is not found.")]
    ErrPkiCertNotFound,
    #[error("PKI role is not found.")]
    ErrPkiRoleNotFound,
    #[error("PKI data is invalid.")]
    ErrPkiDataInvalid,
    #[error("PKI internal error.")]
    ErrPkiInternal,
    #[error("PKI SSH CA is not configured.")]
    ErrPkiSshCaNotConfig,
    #[error("PKI SSH role is not found.")]
    ErrPkiSshRoleNotFound,
    #[error("PKI SSH certificate type is invalid.")]
    ErrPkiSshCertTypeInvalid,
    #[error("PKI SSH public key is invalid.")]
    ErrPkiSshPublicKeyInvalid,
    #[error("PKI SSH principal is not allowed by role.")]
    ErrPkiSshPrincipalNotAllowed,
    #[error("PKI PGP key is not found.")]
    ErrPkiPgpKeyNotFound,
    #[error("PKI PGP key_name already exists.")]
    ErrPkiPgpKeyNameAlreadyExist,
    #[error("PKI PGP key generation failed.")]
    ErrPkiPgpKeyGenerationFailed,
    #[error("Credential is invalid.")]
    ErrCredentialInvalid,
    #[error("Credential is not config.")]
    ErrCredentialNotConfig,
    #[error("Storage backend doesn't require a lock.")]
    ErrStorageBackendLockless,
    #[error("Storage backend lock failed.")]
    ErrStorageBackendLockFailed,
    #[error("Storage backend unlock failed.")]
    ErrStorageBackendUnlockFailed,
    #[cfg(feature = "storage_sqlite")]
    #[error("SQLite backend does not support absolute paths yet.")]
    ErrSqliteBackendNotSupportAbsolute,
    #[cfg(feature = "storage_sqlite")]
    #[error("Sqlite disallowed fields: {}", .0)]
    ErrSqliteDisallowedFields(String),
    #[error("Some IO error happened, {:?}", .source)]
    IO {
        #[from]
        source: io::Error,
    },
    #[error("Some serde_json error happened, {:?}", .source)]
    SerdeJson {
        #[from]
        source: serde_json::Error,
    },
    #[error("Some serde_yaml error happened, {:?}", .source)]
    SerdeYaml {
        #[from]
        source: serde_yaml::Error,
    },
    #[error("HTTP client error: {source}")]
    Reqwest {
        #[from]
        source: reqwest::Error,
    },
    #[error("Some openssl error happened, {:?}", .source)]
    OpenSSL {
        #[from]
        source: openssl::error::ErrorStack,
    },
    #[error("Some pem error happened, {:?}", .source)]
    Pem {
        #[from]
        source: pem::PemError,
    },
    #[error("Some regex error happened, {:?}", .source)]
    Regex {
        #[from]
        source: regex::Error,
    },
    #[error("Some hex error happened, {:?}", .source)]
    Hex {
        #[from]
        source: hex::FromHexError,
    },
    #[error("Some hcl error happened, {:?}", .source)]
    Hcl {
        #[from]
        source: hcl::Error,
    },
    #[error("Some humantime duration error happened, {:?}", .source)]
    HumantimeDuration {
        #[from]
        source: humantime::DurationError,
    },
    #[error("Some humantime timestamp error happened, {:?}", .source)]
    HumantimeTimestamp {
        #[from]
        source: humantime::TimestampError,
    },
    #[error("Some system_time error happened, {:?}", .source)]
    SystemTimeError {
        #[from]
        source: std::time::SystemTimeError,
    },
    #[error("Some chrono error happened, {:?}", .source)]
    ChronoError {
        #[from]
        source: chrono::ParseError,
    },
    #[error("Some bcrypt error happened, {:?}", .source)]
    BcryptError {
        #[from]
        source: bcrypt::BcryptError,
    },
    #[error("Some ureq error happened, {:?}", .source)]
    UreqError {
        #[from]
        source: ureq::Error,
    },
    #[error("RwLock was poisoned (reading)")]
    ErrRwLockReadPoison,
    #[error("RwLock was poisoned (writing)")]
    ErrRwLockWritePoison,

    #[error("Some net addr parse error happened, {:?}", .source)]
    AddrParseError {
        #[from]
        source: std::net::AddrParseError,
    },
    #[error("Some ipnetwork error happened, {:?}", .source)]
    IpNetworkError {
        #[from]
        source: ipnetwork::IpNetworkError,
    },

    #[error("Some url error happened, {:?}", .source)]
    UrlError {
        #[from]
        source: url::ParseError,
    },

    #[error("Some rustls error happened, {:?}", .source)]
    RustlsError {
        #[from]
        source: rustls::Error,
    },

    #[error("Some rustls_pemfile error happened")]
    RustlsPemFileError(rustls_pemfile::Error),

    #[error("Some rustls_pki_types error happened")]
    RustlsPkiTypesPemFileError(rustls::pki_types::pem::Error),

    #[error("Some tokio task error happened")]
    TokioTaskJoinError {
        #[from]
        source: tokio::task::JoinError,
    },

    #[error("Some string utf8 error happened, {:?}", .source)]
    StringUtf8Error {
        #[from]
        source: std::string::FromUtf8Error,
    },

    #[error("Some lockfile error happened, {:?}", .source)]
    LockfileError {
        #[from]
        source: lockfile::Error,
    },

    #[error("Database connection info invalid")]
    ErrDatabaseConnectionInfoInvalid,

    #[cfg(feature = "storage_xline")]
    #[error("Some etcd client error happened, {:?}", .source)]
    EtcdClientError {
        #[from]
        source: etcd_client::Error,
    },

    #[cfg(feature = "storage_sqlite")]
    #[error("Some sqlite client error happened, {:?}", .source)]
    SqliteClientError {
        #[from]
        source: sqlx::Error,
    },

    #[error(transparent)]
    ErrOther(#[from] anyhow::Error),
    #[error("Some error happend, response text: {0}")]
    ErrResponse(String),
    #[error("Some error happend, status: {0}, response text: {1}")]
    ErrResponseStatus(u16, String),
    #[error("{0}")]
    ErrString(String),
    #[error("Unknown error.")]
    ErrUnknown,
}

impl RvError {
    pub fn response_status(&self) -> u16 {
        match self {
            RvError::ErrRequestNoData
            | RvError::ErrBarrierAlreadyInit
            | RvError::ErrBarrierKeyInvalid
            | RvError::ErrBarrierNotInit
            | RvError::ErrBarrierUnsealed
            | RvError::ErrBarrierUnsealFailed
            | RvError::ErrRequestNoDataField
            | RvError::ErrRequestInvalid
            | RvError::ErrRequestClientTokenMissing
            | RvError::ErrRequestFieldNotFound
            | RvError::ErrRequestFieldInvalid
            | RvError::ErrPkiSshCertTypeInvalid
            | RvError::ErrPkiSshPublicKeyInvalid => 400,
            RvError::ErrBarrierSealed => 503,
            RvError::ErrPermissionDenied => 403,
            RvError::ErrRouterMountNotFound => 404,
            _ => 500,
        }
    }
}

/// PartialEq is implemented to allow simple equality checks between
/// `RvError` variants (useful in tests and conditional error handling).
impl PartialEq for RvError {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (RvError::ErrCryptoCipherUpdateFailed, RvError::ErrCryptoCipherUpdateFailed)
            | (RvError::ErrCryptoCipherFinalizeFailed, RvError::ErrCryptoCipherFinalizeFailed)
            | (RvError::ErrCryptoCipherInitFailed, RvError::ErrCryptoCipherInitFailed)
            | (RvError::ErrCryptoCipherNotInited, RvError::ErrCryptoCipherNotInited)
            | (RvError::ErrCryptoCipherOPNotSupported, RvError::ErrCryptoCipherOPNotSupported)
            | (RvError::ErrCryptoCipherNoTag, RvError::ErrCryptoCipherNoTag)
            | (RvError::ErrCryptoCipherAEADTagPresent, RvError::ErrCryptoCipherAEADTagPresent)
            | (RvError::ErrCoreLogicalBackendExist, RvError::ErrCoreLogicalBackendExist)
            | (RvError::ErrCoreNotInit, RvError::ErrCoreNotInit)
            | (RvError::ErrCoreLogicalBackendNoExist, RvError::ErrCoreLogicalBackendNoExist)
            | (RvError::ErrCoreSealConfigInvalid, RvError::ErrCoreSealConfigInvalid)
            | (RvError::ErrCoreSealConfigNotFound, RvError::ErrCoreSealConfigNotFound)
            | (RvError::ErrCoreRouterNotHandling, RvError::ErrCoreRouterNotHandling)
            | (RvError::ErrCoreHandlerExist, RvError::ErrCoreHandlerExist)
            | (RvError::ErrPhysicalConfigItemMissing, RvError::ErrPhysicalConfigItemMissing)
            | (RvError::ErrPhysicalTypeInvalid, RvError::ErrPhysicalTypeInvalid)
            | (
                RvError::ErrPhysicalBackendPrefixInvalid,
                RvError::ErrPhysicalBackendPrefixInvalid,
            )
            | (RvError::ErrPhysicalBackendKeyInvalid, RvError::ErrPhysicalBackendKeyInvalid)
            | (RvError::ErrBarrierKeySanityCheckFailed, RvError::ErrBarrierKeySanityCheckFailed)
            | (RvError::ErrBarrierAlreadyInit, RvError::ErrBarrierAlreadyInit)
            | (RvError::ErrBarrierKeyInvalid, RvError::ErrBarrierKeyInvalid)
            | (RvError::ErrBarrierNotInit, RvError::ErrBarrierNotInit)
            | (RvError::ErrBarrierSealed, RvError::ErrBarrierSealed)
            | (RvError::ErrBarrierUnsealed, RvError::ErrBarrierUnsealed)
            | (RvError::ErrBarrierUnsealFailed, RvError::ErrBarrierUnsealFailed)
            | (RvError::ErrBarrierEpochMismatch, RvError::ErrBarrierEpochMismatch)
            | (RvError::ErrBarrierVersionMismatch, RvError::ErrBarrierVersionMismatch)
            | (RvError::ErrBarrierKeyGenerationFailed, RvError::ErrBarrierKeyGenerationFailed)
            | (RvError::ErrRouterMountConflict, RvError::ErrRouterMountConflict)
            | (RvError::ErrRouterMountNotFound, RvError::ErrRouterMountNotFound)
            | (RvError::ErrMountFailed, RvError::ErrMountFailed)
            | (RvError::ErrMountPathProtected, RvError::ErrMountPathProtected)
            | (RvError::ErrMountPathExist, RvError::ErrMountPathExist)
            | (RvError::ErrMountTableNotFound, RvError::ErrMountTableNotFound)
            | (RvError::ErrMountTableNotReady, RvError::ErrMountTableNotReady)
            | (RvError::ErrMountNotMatch, RvError::ErrMountNotMatch)
            | (RvError::ErrLogicalPathUnsupported, RvError::ErrLogicalPathUnsupported)
            | (RvError::ErrLogicalOperationUnsupported, RvError::ErrLogicalOperationUnsupported)
            | (RvError::ErrRequestNotReady, RvError::ErrRequestNotReady)
            | (RvError::ErrRequestNoData, RvError::ErrRequestNoData)
            | (RvError::ErrRequestNoDataField, RvError::ErrRequestNoDataField)
            | (RvError::ErrRequestInvalid, RvError::ErrRequestInvalid)
            | (RvError::ErrRequestClientTokenMissing, RvError::ErrRequestClientTokenMissing)
            | (RvError::ErrRequestFieldNotFound, RvError::ErrRequestFieldNotFound)
            | (RvError::ErrRequestFieldInvalid, RvError::ErrRequestFieldInvalid)
            | (RvError::ErrResponseDataInvalid, RvError::ErrResponseDataInvalid)
            | (RvError::ErrHandlerDefault, RvError::ErrHandlerDefault)
            | (RvError::ErrModuleKvDataFieldMissing, RvError::ErrModuleKvDataFieldMissing)
            | (RvError::ErrRustDowncastFailed, RvError::ErrRustDowncastFailed)
            | (RvError::ErrShamirShareCountInvalid, RvError::ErrShamirShareCountInvalid)
            | (RvError::ErrRwLockReadPoison, RvError::ErrRwLockReadPoison)
            | (RvError::ErrRwLockWritePoison, RvError::ErrRwLockWritePoison)
            | (RvError::ErrConfigPathInvalid, RvError::ErrConfigPathInvalid)
            | (RvError::ErrConfigLoadFailed, RvError::ErrConfigLoadFailed)
            | (RvError::ErrConfigStorageNotFound, RvError::ErrConfigStorageNotFound)
            | (RvError::ErrConfigListenerNotFound, RvError::ErrConfigListenerNotFound)
            | (RvError::ErrModuleConflict, RvError::ErrModuleConflict)
            | (RvError::ErrModuleNotInit, RvError::ErrModuleNotInit)
            | (RvError::ErrModuleNotFound, RvError::ErrModuleNotFound)
            | (RvError::ErrAuthModuleDisabled, RvError::ErrAuthModuleDisabled)
            | (RvError::ErrAuthTokenNotFound, RvError::ErrAuthTokenNotFound)
            | (RvError::ErrAuthTokenIdInvalid, RvError::ErrAuthTokenIdInvalid)
            | (RvError::ErrLeaseNotFound, RvError::ErrLeaseNotFound)
            | (RvError::ErrLeaseNotRenewable, RvError::ErrLeaseNotRenewable)
            | (RvError::ErrPermissionDenied, RvError::ErrPermissionDenied)
            | (RvError::ErrPkiPemBundleInvalid, RvError::ErrPkiPemBundleInvalid)
            | (RvError::ErrPkiCertKeyMismatch, RvError::ErrPkiCertKeyMismatch)
            | (RvError::ErrPkiCertChainIncorrect, RvError::ErrPkiCertChainIncorrect)
            | (RvError::ErrPkiCertIsNotCA, RvError::ErrPkiCertIsNotCA)
            | (RvError::ErrPkiCaKeyNotFound, RvError::ErrPkiCaKeyNotFound)
            | (RvError::ErrPkiCaNotConfig, RvError::ErrPkiCaNotConfig)
            | (RvError::ErrPkiCaExtensionIncorrect, RvError::ErrPkiCaExtensionIncorrect)
            | (RvError::ErrPkiKeyTypeInvalid, RvError::ErrPkiKeyTypeInvalid)
            | (RvError::ErrPkiKeyBitsInvalid, RvError::ErrPkiKeyBitsInvalid)
            | (RvError::ErrPkiKeyNameAlreadyExist, RvError::ErrPkiKeyNameAlreadyExist)
            | (RvError::ErrPkiKeyOperationInvalid, RvError::ErrPkiKeyOperationInvalid)
            | (RvError::ErrPkiCertNotFound, RvError::ErrPkiCertNotFound)
            | (RvError::ErrPkiRoleNotFound, RvError::ErrPkiRoleNotFound)
            | (RvError::ErrPkiDataInvalid, RvError::ErrPkiDataInvalid)
            | (RvError::ErrPkiInternal, RvError::ErrPkiInternal)
            | (RvError::ErrPkiSshCaNotConfig, RvError::ErrPkiSshCaNotConfig)
            | (RvError::ErrPkiSshRoleNotFound, RvError::ErrPkiSshRoleNotFound)
            | (RvError::ErrPkiSshCertTypeInvalid, RvError::ErrPkiSshCertTypeInvalid)
            | (RvError::ErrPkiSshPublicKeyInvalid, RvError::ErrPkiSshPublicKeyInvalid)
            | (RvError::ErrPkiPgpKeyNotFound, RvError::ErrPkiPgpKeyNotFound)
            | (RvError::ErrPkiPgpKeyNameAlreadyExist, RvError::ErrPkiPgpKeyNameAlreadyExist)
            | (RvError::ErrPkiPgpKeyGenerationFailed, RvError::ErrPkiPgpKeyGenerationFailed)
            | (RvError::ErrCredentialInvalid, RvError::ErrCredentialInvalid)
            | (RvError::ErrCredentialNotConfig, RvError::ErrCredentialNotConfig)
            | (RvError::ErrUnknown, RvError::ErrUnknown) => true,
            (RvError::ErrResponse(a), RvError::ErrResponse(b)) => a == b,
            (RvError::ErrResponseStatus(sa, ta), RvError::ErrResponseStatus(sb, tb)) => {
                sa == sb && ta == tb
            }
            (RvError::ErrString(a), RvError::ErrString(b)) => a == b,
            _ => false,
        }
    }
}

impl<T> From<PoisonError<RwLockWriteGuard<'_, T>>> for RvError {
    fn from(_: PoisonError<RwLockWriteGuard<'_, T>>) -> Self {
        RvError::ErrRwLockWritePoison
    }
}

impl<T> From<PoisonError<RwLockReadGuard<'_, T>>> for RvError {
    fn from(_: PoisonError<RwLockReadGuard<'_, T>>) -> Self {
        RvError::ErrRwLockReadPoison
    }
}

impl From<rustls_pemfile::Error> for RvError {
    fn from(err: rustls_pemfile::Error) -> Self {
        RvError::RustlsPemFileError(err)
    }
}

impl From<rustls::pki_types::pem::Error> for RvError {
    fn from(err: rustls::pki_types::pem::Error) -> Self {
        RvError::RustlsPkiTypesPemFileError(err)
    }
}

#[macro_export]
macro_rules! rv_error_string {
    ($message:expr) => {
        RvError::ErrString($message.to_string())
    };
}

#[macro_export]
macro_rules! rv_error_response {
    ($message:expr) => {
        RvError::ErrResponse($message.to_string())
    };
}

#[macro_export]
macro_rules! rv_error_response_status {
    ($status:expr, $message:expr) => {
        RvError::ErrResponseStatus($status, $message.to_string())
    };
}