Skip to main content

kanidm_proto/internal/
error.rs

1use super::credupdate::PasswordFeedback;
2use crate::attribute::Attribute;
3use serde::{Deserialize, Serialize};
4use std::fmt::{Display, Formatter};
5use utoipa::ToSchema;
6use uuid::Uuid;
7
8/* ===== errors ===== */
9#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, ToSchema)]
10#[serde(rename_all = "lowercase")]
11pub enum SchemaError {
12    NotImplemented,
13    NoClassFound,
14    InvalidClass(Vec<String>),
15    MissingMustAttribute(Vec<Attribute>),
16    InvalidAttribute(String),
17    InvalidAttributeSyntax(String),
18    AttributeNotValidForClass(String),
19    SupplementsNotSatisfied(Vec<String>),
20    ExcludesNotSatisfied(Vec<String>),
21    EmptyFilter,
22    Corrupted,
23    PhantomAttribute(String),
24}
25
26#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, ToSchema)]
27#[serde(rename_all = "lowercase")]
28pub enum PluginError {
29    Base(String),
30    ReferentialIntegrity(String),
31    CredImport(String),
32    Oauth2Secrets,
33}
34
35#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, ToSchema)]
36#[serde(rename_all = "lowercase")]
37pub enum ConsistencyError {
38    Unknown,
39    // Class, Attribute
40    SchemaClassMissingAttribute(String, String),
41    SchemaClassPhantomAttribute(String, String),
42    SchemaUuidNotUnique(Uuid),
43    QueryServerSearchFailure,
44    EntryUuidCorrupt(u64),
45    UuidIndexCorrupt(String),
46    UuidNotUnique(String),
47    RefintNotUpheld(u64),
48    MemberOfInvalid(u64),
49    InvalidAttributeType(String),
50    DuplicateUniqueAttribute,
51    InvalidSpn(u64),
52    SqliteIntegrityFailure,
53    BackendAllIdsSync,
54    BackendIndexSync,
55    ChangelogDesynchronised(u64),
56    ChangeStateDesynchronised(u64),
57    RuvInconsistent(String),
58    DeniedName(Uuid),
59    KeyProviderUuidMissing { key_object: Uuid },
60    KeyProviderNoKeys { key_object: Uuid },
61    KeyProviderNotFound { key_object: Uuid, provider: Uuid },
62}
63
64#[derive(Serialize, Deserialize, Debug, ToSchema)]
65#[serde(rename_all = "lowercase")]
66pub enum OperationError {
67    // Logic errors, or "soft" errors. These are to guide the user or user-interface
68    // in some way.
69    SessionExpired,
70    DuplicateKey,
71    DuplicateLabel,
72    EmptyRequest,
73    Backend,
74    NoMatchingEntries,
75    NoMatchingAttributes,
76    UniqueConstraintViolation,
77    CorruptedEntry(u64),
78    CorruptedIndex(String),
79    ConsistencyError(Vec<ConsistencyError>),
80    SchemaViolation(SchemaError),
81    Plugin(PluginError),
82    FilterGeneration,
83    FilterParseError,
84    FilterUuidResolution,
85    InvalidAttributeName(String),
86    InvalidAttribute(String),
87    InvalidLabel,
88    InvalidDbState,
89    InvalidCacheState,
90    InvalidValueState,
91    InvalidEntryId,
92    InvalidRequestState,
93    InvalidSyncState,
94    InvalidState,
95    InvalidEntryState,
96    InvalidUuid,
97    InvalidReplChangeId,
98    InvalidAcpState(String),
99    InvalidSchemaState(String),
100    InvalidAccountState(String),
101    // This really oughta be EntryClass but its not in proto...
102    // It should at least be &'static str but we
103    // Serialize & Deserialize this enum...
104    MissingClass(String),
105    MissingAttribute(Attribute),
106    AttributeUniqueness(Vec<Attribute>),
107    MissingEntries,
108    ModifyAssertionFailed,
109    BackendEngine,
110    SqliteError, //(RusqliteError)
111    FsError,
112    SerdeJsonError,
113    SerdeCborError,
114    AccessDenied,
115    NotAuthenticated,
116    NotAuthorised,
117    InvalidAuthState(String),
118    InvalidSessionState,
119    SystemProtectedObject,
120    SystemProtectedAttribute,
121    PasswordQuality(Vec<PasswordFeedback>),
122    CryptographyError,
123    ResourceLimit,
124    QueueDisconnected,
125    Webauthn,
126    #[serde(with = "time::serde::timestamp")]
127    Wait(time::OffsetDateTime),
128    ReplReplayFailure,
129    ReplEntryNotChanged,
130    ReplInvalidRUVState,
131    ReplDomainLevelUnsatisfiable,
132    ReplDomainUuidMismatch,
133    ReplServerUuidSplitDataState,
134    TransactionAlreadyCommitted,
135    CannotStartMFADuringOngoingMFASession,
136    /// when you ask for a gid that overlaps a system reserved range
137    /// When a name is denied by the system config
138    ValueDenyName,
139    /// When the DB is potentially over-loaded a timeout can occur starting
140    /// your operation.
141    DatabaseLockAcquisitionTimeout,
142    /// Your change would introduce a reference loop
143    ReferenceLoop,
144    /// This session is not able to re-authenticate and has static privileges
145    SessionMayNotReauth,
146
147    // Specific internal errors.
148    AU0001InvalidState,
149    AU0002JwsSerialisation,
150    AU0003JwsSignature,
151    AU0004UserAuthTokenInvalid,
152    AU0005DelayedProcessFailure,
153    AU0006CredentialMayNotReauthenticate,
154    AU0007UserAuthTokenInvalid,
155    AU0008ClientAuthInfoPrevalidation,
156
157    // Kanidm Generic Errors
158    KG001TaskTimeout,
159    KG002TaskCommFailure,
160    KG003CacheClearFailed,
161    KG004UnknownFeatureUuid,
162    KG005HowDidYouEvenManageThis,
163    KG006DatastructureCorruption,
164
165    // Account Signup Errors
166    AS0001FeatureDisabled,
167    AS0002FeatureDisabled,
168    AS0003FeatureDisabled,
169    AS0004InvalidState,
170    AS0005InvalidState,
171    AS0006InvalidState,
172
173    // Credential Update Errors
174    CU0001WebauthnAttestationNotTrusted,
175    CU0002WebauthnRegistrationError,
176    CU0003WebauthnUserNotVerified,
177
178    // The session is inconsistent and can't be committed, but the errors
179    // can be resolved.
180    CU0004SessionInconsistent,
181    // Another session used this intent token, and so it can't be committed.
182    CU0005IntentTokenConflict,
183    // The intent token was invalidated before we could commit.
184    CU0006IntentTokenInvalidated,
185    CU0007AccountEmailNotFound,
186    CU0008AccountMissingEmail,
187    CU0009AccountEmailNotFound,
188    CU0010AccountRecoveryDisabled,
189
190    // ValueSet errors
191    VS0001IncomingReplSshPublicKey,
192    VS0002CertificatePublicKeyDigest,
193    VS0003CertificateDerDecode,
194    VS0004CertificatePublicKeyDigest,
195    VS0005CertificatePublicKeyDigest,
196    // Value Errors
197    VL0001ValueSshPublicKeyString,
198
199    // LDAP Errors
200    LD0001AnonymousNotAllowed,
201
202    // DB low level errors.
203    DB0001MismatchedRestoreVersion,
204    DB0002MismatchedRestoreVersion,
205    DB0003FilterResolveCacheBuild,
206    DB0004DatabaseTooOld,
207
208    // SCIM
209    SC0001IncomingSshPublicKey,
210    SC0002ReferenceSyntaxInvalid,
211    SC0003MailSyntaxInvalid,
212    SC0004UuidSyntaxInvalid,
213    SC0005BoolSyntaxInvalid,
214    SC0006Uint32SyntaxInvalid,
215    SC0007UrlSyntaxInvalid,
216    SC0008SyntaxTypeSyntaxInvalid,
217    SC0009IndexTypeSyntaxInvalid,
218    SC0010DateTimeSyntaxInvalid,
219    SC0011AddressSyntaxInvalid,
220    SC0012CertificateSyntaxInvalid,
221    SC0013CertificateInvalidDer,
222    SC0014CertificateInvalidDigest,
223    SC0015CredentialTypeSyntaxInvalid,
224    SC0016InameSyntaxInvalid,
225    SC0017Iutf8SyntaxInvalid,
226    SC0018NsUniqueIdSyntaxInvalid,
227    SC0019Oauth2ScopeSyntaxInvalid,
228    SC0020Oauth2ScopeMapSyntaxInvalid,
229    SC0021Oauth2ScopeMapMissingGroupIdentifier,
230    SC0022Oauth2ClaimMapSyntaxInvalid,
231    SC0023Oauth2ClaimMapMissingGroupIdentifier,
232    SC0024SshPublicKeySyntaxInvalid,
233    SC0025UiHintSyntaxInvalid,
234    SC0026Utf8SyntaxInvalid,
235    SC0027ClassSetInvalid,
236    SC0028CreatedUuidsInvalid,
237    SC0029PaginationOutOfBounds,
238    SC0030Sha256SyntaxInvalid,
239    SC0031Int64SyntaxInvalid,
240    SC0032Uint64SyntaxInvalid,
241    SC0033AssertionContainsDuplicateUuids,
242    SC0034UuidSyntaxInvalid,
243
244    // Migration
245    MG0001InvalidReMigrationLevel,
246    MG0002RaiseDomainLevelExceedsMaximum,
247    MG0003ServerPhaseInvalidForMigration,
248    MG0004DomainLevelInDevelopment,
249    MG0005GidConstraintsNotMet,
250    MG0006SKConstraintsNotMet,
251    MG0007Oauth2StrictConstraintsNotMet,
252    MG0008SkipUpgradeAttempted,
253    MG0009InvalidTargetLevelForBootstrap,
254    MG0010DowngradeNotAllowed,
255    //
256    KP0001KeyProviderNotLoaded,
257    KP0002KeyProviderInvalidClass,
258    KP0003KeyProviderInvalidType,
259    KP0004KeyProviderMissingAttributeName,
260    KP0005KeyProviderDuplicate,
261    KP0006KeyObjectJwtEs256Generation,
262    KP0007KeyProviderDefaultNotAvailable,
263    KP0008KeyObjectMissingUuid,
264    KP0009KeyObjectPrivateToDer,
265    KP0010KeyObjectSignerToVerifier,
266    KP0011KeyObjectMissingClass,
267    KP0012KeyObjectMissingProvider,
268    KP0012KeyProviderNotLoaded,
269    KP0013KeyObjectJwsEs256DerInvalid,
270    KP0014KeyObjectSignerToVerifier,
271    KP0015KeyObjectJwsEs256DerInvalid,
272    KP0016KeyObjectJwsEs256DerInvalid,
273    KP0017KeyProviderNoSuchKey,
274    KP0018KeyProviderNoSuchKey,
275    KP0019KeyProviderUnsupportedAlgorithm,
276    KP0020KeyObjectNoActiveSigningKeys,
277    KP0021KeyObjectJwsEs256Signature,
278    KP0022KeyObjectJwsNotAssociated,
279    KP0023KeyObjectJwsKeyRevoked,
280    KP0024KeyObjectJwsInvalid,
281    KP0025KeyProviderNotAvailable,
282    KP0026KeyObjectNoSuchKey,
283    KP0027KeyObjectPublicToDer,
284    KP0028KeyObjectImportJwsEs256DerInvalid,
285    KP0029KeyObjectSignerToVerifier,
286    KP0030KeyObjectPublicToDer,
287    KP0031KeyObjectNotFound,
288    KP0032KeyProviderNoSuchKey,
289    KP0033KeyProviderNoSuchKey,
290    KP0034KeyProviderUnsupportedAlgorithm,
291    KP0035KeyObjectJweA128GCMGeneration,
292    KP0036KeyObjectPrivateToBytes,
293    KP0037KeyObjectImportJweA128GCMInvalid,
294    KP0038KeyObjectImportJweA128GCMInvalid,
295    KP0039KeyObjectJweNotAssociated,
296    KP0040KeyObjectJweInvalid,
297    KP0041KeyObjectJweRevoked,
298    KP0042KeyObjectNoActiveEncryptionKeys,
299    KP0043KeyObjectJweA128GCMEncryption,
300    KP0044KeyObjectJwsPublicJwk,
301
302    KP0045KeyObjectImportJwsRs256DerInvalid,
303    KP0046KeyObjectSignerToVerifier,
304    KP0047KeyObjectPublicToDer,
305    KP0048KeyObjectJwtRs256Generation,
306    KP0049KeyObjectSignerToVerifier,
307    KP0050KeyObjectPrivateToDer,
308    KP0051KeyObjectPublicToDer,
309    KP0052KeyObjectJwsRs256DerInvalid,
310    KP0053KeyObjectSignerToVerifier,
311    KP0054KeyObjectJwsRs256DerInvalid,
312    KP0055KeyObjectJwsRs256DerInvalid,
313    KP0056KeyObjectJwsRs256Signature,
314    KP0057KeyObjectJwsNotAssociated,
315    KP0058KeyObjectJwsInvalid,
316    KP0059KeyObjectJwsKeyRevoked,
317    KP0060KeyObjectJwsPublicJwk,
318    KP0061KeyObjectNoActiveSigningKeys,
319    KP0062KeyProviderNoSuchKey,
320
321    KP0063KeyObjectJwsHs256DerInvalid,
322    KP0064KeyObjectSignerToVerifier,
323    KP0065KeyObjectJwtHs256Generation,
324    KP0066KeyObjectJwsHs256DerInvalid,
325    KP0067KeyObjectSignerToVerifier,
326    KP0068KeyObjectJwsHs256DerInvalid,
327    KP0069KeyObjectNoActiveSigningKeys,
328    KP0070KeyObjectJwsHs256Signature,
329    KP0071KeyObjectPrivateToDer,
330
331    KP0072KeyObjectHs256Invalid,
332    KP0073KeyObjectHs256Invalid,
333    KP0074KeyObjectNoActiveSigningKeys,
334    KP0075KeyObjectHmacInvalidLength,
335    KP0076KeyObjectHkdfOutputLengthInvalid,
336    KP0077KeyProviderNoSuchKey,
337    KP0078KeyObjectNotFound,
338    KP0079KeyObjectNotFound,
339
340    KP0080KeyProviderNoSuchKey,
341
342    KP0081KeyObjectImportJweA256GCMInvalid,
343    KP0082KeyObjectImportJweA256GCMInvalid,
344    KP0083KeyObjectJweNotAssociated,
345    KP0084KeyObjectJweInvalid,
346    KP0085KeyObjectJweRevoked,
347    KP0086KeyObjectNoActiveEncryptionKeys,
348    KP0087KeyObjectJweA256GCMEncryption,
349    KP0088KeyProviderNoSuchKey,
350
351    // Plugins
352    PL0001GidOverlapsSystemRange,
353
354    // Web UI
355    UI0001ChallengeSerialisation,
356    UI0002InvalidState,
357    UI0003InvalidOauth2Resume,
358    UI0004MemberAlreadyExists,
359    UI0005PersonAlreadyExists,
360    UI0006MissingDisplayName,
361    UI0007DuplicateEmail,
362    UI0008InvalidUserName,
363    UI0009GroupAlreadyExists,
364    UI0010MissingGroupName,
365    UI0011InvalidGroupName,
366
367    // Unixd Things
368    KU001InitWhileSessionActive,
369    KU002ContinueWhileSessionInActive,
370    KU003PamAuthFailed,
371    KU004PamInitFailed,
372    KU005ErrorCheckingAccount,
373    KU006OnlyRootAllowed,
374}
375
376impl PartialEq for OperationError {
377    fn eq(&self, other: &Self) -> bool {
378        // We do this to avoid InvalidPassword being checked as it's not
379        // derive PartialEq. Generally we only use the PartialEq for TESTING
380        // anyway.
381        std::mem::discriminant(self) == std::mem::discriminant(other)
382    }
383}
384
385impl Display for OperationError {
386    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
387        let mut output = format!("{self:?}")
388            .split("::")
389            .last()
390            .unwrap_or("")
391            .to_string();
392
393        if let Some(msg) = self.message() {
394            output += &format!(" - {msg}");
395        };
396        f.write_str(&output)
397    }
398}
399
400impl OperationError {
401    /// Return the message associated with the error if there is one.
402    pub fn message(&self) -> Option<String> {
403        match self {
404            Self::SessionExpired => None,
405            Self::EmptyRequest => None,
406            Self::Backend => None,
407            Self::NoMatchingEntries => None,
408            Self::NoMatchingAttributes => None,
409            Self::UniqueConstraintViolation => Some("A unique constraint was violated resulting in multiple conflicting results.".into()),
410            Self::CorruptedEntry(_) => None,
411            Self::CorruptedIndex(_) => None,
412            Self::ConsistencyError(_) => None,
413            Self::SchemaViolation(_) => None,
414            Self::Plugin(_) => None,
415            Self::FilterGeneration => None,
416            Self::FilterParseError => None,
417            Self::FilterUuidResolution => None,
418            Self::InvalidAttributeName(_) => None,
419            Self::InvalidAttribute(_) => None,
420            Self::InvalidLabel => Some("The submitted label for this item is invalid.".into()),
421            Self::DuplicateLabel => Some("The submitted label for this item is already in use.".into()),
422            Self::DuplicateKey => Some("The submitted key already exists.".into()),
423            Self::InvalidDbState => None,
424            Self::InvalidCacheState => None,
425            Self::InvalidValueState => None,
426            Self::InvalidEntryId => None,
427            Self::InvalidRequestState => None,
428            Self::InvalidSyncState => None,
429            Self::InvalidState => None,
430            Self::InvalidEntryState => None,
431            Self::InvalidUuid => None,
432            Self::InvalidReplChangeId => None,
433            Self::InvalidAcpState(_) => None,
434            Self::InvalidSchemaState(_) => None,
435            Self::InvalidAccountState(val) => Some(format!("Invalid account state: {val}")),
436            Self::MissingClass(val) => Some(format!("Missing class: {val}")),
437            Self::MissingAttribute(val) => Some(format!("Missing attribute: {val}")),
438            Self::AttributeUniqueness(attrs) => Some(format!("The value of some attributes is not unique. {attrs:?}")),
439            Self::MissingEntries => None,
440            Self::ModifyAssertionFailed => None,
441            Self::BackendEngine => None,
442            Self::SqliteError => None,
443            Self::FsError => None,
444            Self::SerdeJsonError => None,
445            Self::SerdeCborError => None,
446            Self::AccessDenied => None,
447            Self::NotAuthenticated => None,
448            Self::NotAuthorised => None,
449            Self::InvalidAuthState(_) => None,
450            Self::InvalidSessionState => None,
451            Self::SystemProtectedObject => None,
452            Self::SystemProtectedAttribute => None,
453            Self::PasswordQuality(_) => None,
454            Self::CryptographyError => None,
455            Self::ResourceLimit => None,
456            Self::QueueDisconnected => None,
457            Self::Webauthn => None,
458            Self::Wait(_) => None,
459            Self::CannotStartMFADuringOngoingMFASession => Some("Cannot start a new MFA authentication flow when there already is one active.".into()),
460            Self::ReplReplayFailure => None,
461            Self::ReplEntryNotChanged => None,
462            Self::ReplInvalidRUVState => None,
463            Self::ReplDomainLevelUnsatisfiable => None,
464            Self::ReplDomainUuidMismatch => None,
465            Self::ReplServerUuidSplitDataState => None,
466            Self::TransactionAlreadyCommitted => None,
467            Self::ValueDenyName => None,
468            Self::DatabaseLockAcquisitionTimeout => Some("Unable to acquire a database lock - the current server may be too busy. Try again later.".into()),
469            Self::ReferenceLoop => Some("The change you have made would introduce an invalid reference loop. Unable to proceed.".into()),
470            Self::SessionMayNotReauth => Some("The current session is not able to re-authenticate to elevate privileges to read-write.".into()),
471
472            Self::AU0001InvalidState => Some("Invalid authentication session state for request".into()),
473            Self::AU0002JwsSerialisation => Some("JWS serialisation failed".into()),
474            Self::AU0003JwsSignature => Some("JWS signature failed".into()),
475            Self::AU0004UserAuthTokenInvalid => Some("User auth token was unable to be generated".into()),
476            Self::AU0005DelayedProcessFailure => Some("Delaying processing failure, unable to proceed".into()),
477            Self::AU0006CredentialMayNotReauthenticate => Some("Credential may not reauthenticate".into()),
478            Self::AU0007UserAuthTokenInvalid => Some("User auth token was unable to be generated".into()),
479            Self::AU0008ClientAuthInfoPrevalidation => Some("Client Authentication Info prevalidation did not occur when expected".into()),
480
481            Self::CU0001WebauthnAttestationNotTrusted => None,
482            Self::CU0002WebauthnRegistrationError => None,
483            Self::CU0003WebauthnUserNotVerified => Some("User Verification bit not set while registering credential, you may need to configure a PIN on this device.".into()),
484
485            Self::CU0004SessionInconsistent => Some("The session is unable to be committed due to unresolved warnings.".into()),
486            Self::CU0005IntentTokenConflict => Some("The intent token used to create this session has been reused in another browser/tab and may not proceed.".into()),
487            Self::CU0006IntentTokenInvalidated => Some("The intent token has been invalidated/revoked before the commit could be accepted. Has it been used in another browser or tab?".into()),
488            Self::CU0007AccountEmailNotFound |
489            Self::CU0009AccountEmailNotFound
490            => Some("The target email for a credential update intent token send request is not registered to the account.".into()),
491            Self::CU0008AccountMissingEmail => Some("The account has no email addresses and may not have a credential update intent token sent to it.".into()),
492            Self::CU0010AccountRecoveryDisabled => Some("The account recovery feature is disabled. See `kanidm system domain set-allow-account-recovery`".into()),
493
494            Self::DB0001MismatchedRestoreVersion => None,
495            Self::DB0002MismatchedRestoreVersion => None,
496            Self::DB0003FilterResolveCacheBuild => None,
497            Self::DB0004DatabaseTooOld => Some("The database is too old to be migrated.".into()),
498            Self::KG001TaskTimeout => Some("Task timed out".into()),
499            Self::KG002TaskCommFailure => Some("Inter-Task communication failure".into()),
500            Self::KG003CacheClearFailed => Some("Failed to clear cache".into()),
501            Self::KG004UnknownFeatureUuid => None,
502            Self::KG005HowDidYouEvenManageThis => Some("You have damaged the fabric of space time and managed to perform an impossible action.".into()),
503            Self::KG006DatastructureCorruption => None,
504            Self::AS0001FeatureDisabled
505            | Self::AS0002FeatureDisabled
506            | Self::AS0003FeatureDisabled
507            | Self::AS0004InvalidState
508            | Self::AS0005InvalidState
509            | Self::AS0006InvalidState => None,
510
511            Self::KP0001KeyProviderNotLoaded => None,
512            Self::KP0002KeyProviderInvalidClass => None,
513            Self::KP0003KeyProviderInvalidType => None,
514            Self::KP0004KeyProviderMissingAttributeName => None,
515            Self::KP0005KeyProviderDuplicate => None,
516            Self::KP0006KeyObjectJwtEs256Generation => None,
517            Self::KP0007KeyProviderDefaultNotAvailable => None,
518            Self::KP0008KeyObjectMissingUuid => None,
519            Self::KP0009KeyObjectPrivateToDer => None,
520            Self::KP0010KeyObjectSignerToVerifier => None,
521            Self::KP0011KeyObjectMissingClass => None,
522            Self::KP0012KeyObjectMissingProvider => None,
523            Self::KP0012KeyProviderNotLoaded => None,
524            Self::KP0013KeyObjectJwsEs256DerInvalid => None,
525            Self::KP0014KeyObjectSignerToVerifier => None,
526            Self::KP0015KeyObjectJwsEs256DerInvalid => None,
527            Self::KP0016KeyObjectJwsEs256DerInvalid => None,
528            Self::KP0017KeyProviderNoSuchKey => None,
529            Self::KP0018KeyProviderNoSuchKey => None,
530            Self::KP0019KeyProviderUnsupportedAlgorithm => None,
531            Self::KP0020KeyObjectNoActiveSigningKeys => None,
532            Self::KP0021KeyObjectJwsEs256Signature => None,
533            Self::KP0022KeyObjectJwsNotAssociated => None,
534            Self::KP0023KeyObjectJwsKeyRevoked => None,
535            Self::KP0024KeyObjectJwsInvalid => None,
536            Self::KP0025KeyProviderNotAvailable => None,
537            Self::KP0026KeyObjectNoSuchKey => None,
538            Self::KP0027KeyObjectPublicToDer => None,
539            Self::KP0028KeyObjectImportJwsEs256DerInvalid => None,
540            Self::KP0029KeyObjectSignerToVerifier => None,
541            Self::KP0030KeyObjectPublicToDer => None,
542            Self::KP0031KeyObjectNotFound => None,
543            Self::KP0032KeyProviderNoSuchKey => None,
544            Self::KP0033KeyProviderNoSuchKey => None,
545            Self::KP0034KeyProviderUnsupportedAlgorithm => None,
546            Self::KP0035KeyObjectJweA128GCMGeneration => None,
547            Self::KP0036KeyObjectPrivateToBytes => None,
548            Self::KP0037KeyObjectImportJweA128GCMInvalid => None,
549            Self::KP0038KeyObjectImportJweA128GCMInvalid => None,
550            Self::KP0039KeyObjectJweNotAssociated => None,
551            Self::KP0040KeyObjectJweInvalid => None,
552            Self::KP0041KeyObjectJweRevoked => None,
553            Self::KP0042KeyObjectNoActiveEncryptionKeys => None,
554            Self::KP0043KeyObjectJweA128GCMEncryption => None,
555            Self::KP0044KeyObjectJwsPublicJwk => None,
556
557            Self::KP0045KeyObjectImportJwsRs256DerInvalid => None,
558            Self::KP0046KeyObjectSignerToVerifier => None,
559            Self::KP0047KeyObjectPublicToDer => None,
560            Self::KP0048KeyObjectJwtRs256Generation => None,
561            Self::KP0049KeyObjectSignerToVerifier => None,
562            Self::KP0050KeyObjectPrivateToDer => None,
563            Self::KP0051KeyObjectPublicToDer => None,
564            Self::KP0052KeyObjectJwsRs256DerInvalid => None,
565            Self::KP0053KeyObjectSignerToVerifier => None,
566            Self::KP0054KeyObjectJwsRs256DerInvalid => None,
567            Self::KP0055KeyObjectJwsRs256DerInvalid => None,
568            Self::KP0056KeyObjectJwsRs256Signature => None,
569            Self::KP0057KeyObjectJwsNotAssociated => None,
570            Self::KP0058KeyObjectJwsInvalid => None,
571            Self::KP0059KeyObjectJwsKeyRevoked => None,
572            Self::KP0060KeyObjectJwsPublicJwk => None,
573            Self::KP0061KeyObjectNoActiveSigningKeys => None,
574            Self::KP0062KeyProviderNoSuchKey => None,
575            Self::KP0063KeyObjectJwsHs256DerInvalid => None,
576            Self::KP0064KeyObjectSignerToVerifier => None,
577            Self::KP0065KeyObjectJwtHs256Generation => None,
578            Self::KP0066KeyObjectJwsHs256DerInvalid => None,
579            Self::KP0067KeyObjectSignerToVerifier => None,
580            Self::KP0068KeyObjectJwsHs256DerInvalid => None,
581            Self::KP0069KeyObjectNoActiveSigningKeys => None,
582            Self::KP0070KeyObjectJwsHs256Signature => None,
583            Self::KP0071KeyObjectPrivateToDer => None,
584            Self::KP0072KeyObjectHs256Invalid => None,
585            Self::KP0073KeyObjectHs256Invalid => None,
586            Self::KP0074KeyObjectNoActiveSigningKeys => None,
587            Self::KP0075KeyObjectHmacInvalidLength => None,
588            Self::KP0076KeyObjectHkdfOutputLengthInvalid => None,
589            Self::KP0077KeyProviderNoSuchKey => None,
590            Self::KP0078KeyObjectNotFound => None,
591            Self::KP0079KeyObjectNotFound => None,
592            Self::KP0080KeyProviderNoSuchKey => None,
593
594            Self::KP0081KeyObjectImportJweA256GCMInvalid => None,
595            Self::KP0082KeyObjectImportJweA256GCMInvalid => None,
596            Self::KP0083KeyObjectJweNotAssociated => None,
597            Self::KP0084KeyObjectJweInvalid => None,
598            Self::KP0085KeyObjectJweRevoked => None,
599            Self::KP0086KeyObjectNoActiveEncryptionKeys => None,
600            Self::KP0087KeyObjectJweA256GCMEncryption => None,
601            Self::KP0088KeyProviderNoSuchKey => None,
602
603            Self::KU001InitWhileSessionActive => Some("The session was active when the init function was called.".into()),
604            Self::KU002ContinueWhileSessionInActive => Some("Attempted to continue auth session while current session is inactive".into()),
605            Self::KU003PamAuthFailed => Some("Failed PAM account authentication step".into()),
606            Self::KU004PamInitFailed => Some("Failed to initialise PAM authentication".into()),
607            Self::KU005ErrorCheckingAccount => Some("Error checking account".into()),
608            Self::KU006OnlyRootAllowed => Some("Only root is allowed to perform this operation".into()),
609            Self::LD0001AnonymousNotAllowed => Some("Anonymous is not allowed to access LDAP with this method.".into()),
610            Self::MG0001InvalidReMigrationLevel => None,
611            Self::MG0002RaiseDomainLevelExceedsMaximum => None,
612            Self::MG0003ServerPhaseInvalidForMigration => None,
613            Self::MG0004DomainLevelInDevelopment => None,
614            Self::MG0005GidConstraintsNotMet => None,
615            Self::MG0006SKConstraintsNotMet => Some("Migration Constraints Not Met - Security Keys should not be present.".into()),
616            Self::MG0007Oauth2StrictConstraintsNotMet => Some("Migration Constraints Not Met - All OAuth2 clients must have strict-redirect-uri mode enabled.".into()),
617            Self::MG0008SkipUpgradeAttempted => Some("Skip Upgrade Attempted.".into()),
618            Self::MG0009InvalidTargetLevelForBootstrap => Some("The request target domain level was not valid for bootstrapping a new server instance".into()),
619            Self::MG0010DowngradeNotAllowed => Some("Downgrade Attempted".into()),
620            Self::PL0001GidOverlapsSystemRange => None,
621            Self::SC0001IncomingSshPublicKey => None,
622            Self::SC0002ReferenceSyntaxInvalid => Some("A SCIM Reference Set contained invalid syntax and can not be processed.".into()),
623            Self::SC0003MailSyntaxInvalid => Some("A SCIM Mail Address contained invalid syntax".into()),
624            Self::SC0004UuidSyntaxInvalid => Some("A SCIM Uuid contained invalid syntax".into()),
625            Self::SC0005BoolSyntaxInvalid => Some("A SCIM boolean contained invalid syntax".into()),
626            Self::SC0006Uint32SyntaxInvalid => Some("A SCIM Uint32 contained invalid syntax".into()),
627            Self::SC0007UrlSyntaxInvalid => Some("A SCIM Url contained invalid syntax".into()),
628            Self::SC0008SyntaxTypeSyntaxInvalid => Some("A SCIM SyntaxType contained invalid syntax".into()),
629            Self::SC0009IndexTypeSyntaxInvalid => Some("A SCIM IndexType contained invalid syntax".into()),
630            Self::SC0010DateTimeSyntaxInvalid => Some("A SCIM DateTime contained invalid syntax".into()),
631
632            Self::SC0011AddressSyntaxInvalid => Some("A SCIM Address contained invalid syntax".into()),
633            Self::SC0012CertificateSyntaxInvalid => Some("A SCIM Certificate contained invalid binary data".into()),
634            Self::SC0013CertificateInvalidDer => Some("A SCIM Certificate did not contain valid DER".into()),
635            Self::SC0014CertificateInvalidDigest => Some("A SCIM Certificate was unable to be digested".into()),
636            Self::SC0015CredentialTypeSyntaxInvalid => Some("A SCIM CredentialType contained invalid syntax".into()),
637            Self::SC0016InameSyntaxInvalid => Some("A SCIM Iname string contained invalid syntax".into()),
638            Self::SC0017Iutf8SyntaxInvalid => Some("A SCIM Iutf8 string contained invalid syntax".into()),
639            Self::SC0018NsUniqueIdSyntaxInvalid => Some("A SCIM NsUniqueID contained invalid syntax".into()),
640            Self::SC0019Oauth2ScopeSyntaxInvalid => Some("A SCIM Oauth2 Scope contained invalid syntax".into()),
641            Self::SC0020Oauth2ScopeMapSyntaxInvalid => Some("A SCIM Oauth2 Scope Map contained invalid syntax".into()),
642            Self::SC0021Oauth2ScopeMapMissingGroupIdentifier => Some("A SCIM Oauth2 Scope Map was missing a group name or uuid".into()),
643            Self::SC0022Oauth2ClaimMapSyntaxInvalid => Some("A SCIM Oauth2 Claim Map contained invalid syntax".into()),
644            Self::SC0023Oauth2ClaimMapMissingGroupIdentifier => Some("A SCIM Claim Map was missing a group name or uuid".into()),
645            Self::SC0024SshPublicKeySyntaxInvalid => Some("A SCIM Ssh Public Key contained invalid syntax".into()),
646            Self::SC0025UiHintSyntaxInvalid => Some("A SCIM UiHint contained invalid syntax".into()),
647            Self::SC0026Utf8SyntaxInvalid => Some("A SCIM Utf8 String Scope Map contained invalid syntax".into()),
648            Self::SC0027ClassSetInvalid => Some("The internal set of class templates used in this create operation was invalid. THIS IS A BUG.".into()),
649            Self::SC0028CreatedUuidsInvalid => Some("The internal create query did not return the set of created UUIDs. THIS IS A BUG".into()),
650            Self::SC0029PaginationOutOfBounds => Some("The requested range for pagination was out of bounds of the result set".into()),
651            Self::SC0030Sha256SyntaxInvalid => Some("A SCIM SHA256 hex string was invalid.".into()),
652            Self::SC0031Int64SyntaxInvalid => Some("A SCIM Int64 contained invalid syntax".into()),
653            Self::SC0032Uint64SyntaxInvalid => Some("A SCIM Uint64 contained invalid syntax".into()),
654            Self::SC0033AssertionContainsDuplicateUuids => Some("SCIM assertion contains duplicate entry ids, unable to proceed.".into()),
655            Self::SC0034UuidSyntaxInvalid => Some("A SCIM Uuid contained invalid syntax".into()),
656            Self::UI0001ChallengeSerialisation => Some("The WebAuthn challenge was unable to be serialised.".into()),
657            Self::UI0002InvalidState => Some("The credential update process returned an invalid state transition.".into()),
658            Self::UI0003InvalidOauth2Resume => Some("The server attempted to resume OAuth2, but no OAuth2 session is in progress.".into()),
659            Self::UI0004MemberAlreadyExists => Some("The target is already a member.".into()),
660            Self::UI0005PersonAlreadyExists => Some("A person with this username already exists.".into()),
661            Self::UI0006MissingDisplayName => Some("A display name is required for every user.".into()),
662            Self::UI0007DuplicateEmail => Some("Another user with the same email address already exists.".into()),
663            Self::UI0008InvalidUserName => Some("Invalid username.".into()),
664            Self::UI0009GroupAlreadyExists => Some("A group with this name already exists.".into()),
665            Self::UI0010MissingGroupName => Some("A name is required for every group.".into()),
666            Self::UI0011InvalidGroupName => Some("Invalid group name.".into()),
667            Self::VL0001ValueSshPublicKeyString => None,
668            Self::VS0001IncomingReplSshPublicKey => None,
669            Self::VS0002CertificatePublicKeyDigest |
670            Self::VS0003CertificateDerDecode => Some("Decoding the stored certificate from DER failed.".into()),
671            Self::VS0004CertificatePublicKeyDigest |
672            Self::VS0005CertificatePublicKeyDigest => Some("The certificates public key is unable to be digested.".into()),
673
674        }
675    }
676}
677
678#[test]
679fn test_operationerror_as_nice_string() {
680    assert_eq!(
681        OperationError::CU0001WebauthnAttestationNotTrusted.to_string(),
682        "CU0001WebauthnAttestationNotTrusted".to_string()
683    );
684    assert_eq!(
685        OperationError::CU0003WebauthnUserNotVerified.to_string(),
686        "CU0003WebauthnUserNotVerified - User Verification bit not set while registering credential, you may need to configure a PIN on this device.".to_string()
687    );
688    assert_eq!(
689        OperationError::SessionExpired.to_string(),
690        "SessionExpired".to_string()
691    );
692    assert_eq!(
693        OperationError::CorruptedEntry(12345).to_string(),
694        "CorruptedEntry(12345)".to_string()
695    );
696}