kanidm_proto/internal/
error.rs

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