From af8a4345772228e10b381d006932ee80be2c85e9 Mon Sep 17 00:00:00 2001 From: bramkolkman Date: Mon, 23 Feb 2026 13:03:28 +0000 Subject: [PATCH] SecError * Added the SecError to throw when interacting with the Keychain * Added the SecError.Code to wrap the status codes thrown by interacting with the Keychain Co-authored-by: Bram Kolkman Reviewed-on: https://git.thinkerium.nl/bramkolkman/Keychain/pulls/2 --- .gitignore | 5 +- .../Keychain/Error/SecError+Code.swift | 763 ++++++++++++++++++ .../Sources/Keychain/Error/SecError.swift | 24 + 3 files changed, 790 insertions(+), 2 deletions(-) create mode 100644 Keychain/Sources/Keychain/Error/SecError+Code.swift create mode 100644 Keychain/Sources/Keychain/Error/SecError.swift diff --git a/.gitignore b/.gitignore index 65b929d..f68c9b5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,8 @@ xcuserdata/ .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* @@ -60,7 +61,7 @@ playground.xcworkspace # # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata # hence it is not needed unless you have added a package configuration file to your project -# .swiftpm +.swiftpm .build/ diff --git a/Keychain/Sources/Keychain/Error/SecError+Code.swift b/Keychain/Sources/Keychain/Error/SecError+Code.swift new file mode 100644 index 0000000..035bd04 --- /dev/null +++ b/Keychain/Sources/Keychain/Error/SecError+Code.swift @@ -0,0 +1,763 @@ +// +// SecError+Code.swift +// Keychain +// +// Created by Bram Kolkman on 23/02/2026. +// + +import Security + +extension SecError { + /// Security error codes. + public enum Code: OSStatus, Hashable, Sendable { // swiftlint:disable:this type_body_length + /// Function or operation not implemented. + case unimplemented = -4 + /// The disk is full. + case diskFull = -34 + /// I/O error. + case io = -36 // swiftlint:disable:this identifier_name + /// File already open with write permission. + case opWr = -49 + /// One or more parameters passed to a function were not valid. + case param = -50 + /// Write permissions error. + case wrPerm = -61 + /// Failed to allocate memory. + case allocate = -108 + /// User canceled the operation. + case userCanceled = -128 + /// Bad parameter or invalid state for operation. + case badReq = -909 + case internalComponent = -2070 + case coreFoundationUnknown = -4960 + /// A required entitlement isn't present. + case missingEntitlement = -34018 + /// Client is restricted and is not permitted to perform this operation. + case restrictedAPI = -34020 + /// No keychain is available. You may need to restart your computer. + case notAvailable = -25291 + /// This keychain cannot be modified. + case readOnly = -25292 + /// The user name or passphrase you entered is not correct. + case authFailed = -25293 + /// The specified keychain could not be found. + case noSuchKeychain = -25294 + /// The specified keychain is not a valid keychain file. + case invalidKeychain = -25295 + /// A keychain with the same name already exists. + case duplicateKeychain = -25296 + /// The specified callback function is already installed. + case duplicateCallback = -25297 + /// The specified callback function is not valid. + case invalidCallback = -25298 + /// The specified item already exists in the keychain. + case duplicateItem = -25299 + /// The specified item could not be found in the keychain. + case itemNotFound = -25300 + /// There is not enough memory available to use the specified item. + case bufferTooSmall = -25301 + /// This item contains information which is too large or in a format that cannot be displayed. + case dataTooLarge = -25302 + /// The specified attribute does not exist. + case noSuchAttr = -25303 + /// The specified item is no longer valid. It may have been deleted from the keychain. + case invalidItemRef = -25304 + /// Unable to search the current keychain. + case invalidSearchRef = -25305 + /// The specified item does not appear to be a valid keychain item. + case noSuchClass = -25306 + /// A default keychain could not be found. + case noDefaultKeychain = -25307 + /// User interaction is not allowed. + case interactionNotAllowed = -25308 + /// The specified attribute could not be modified. + case readOnlyAttr = -25309 + /// This keychain was created by a different version of the system software and cannot be opened. + case wrongSecVersion = -25310 + /// This item specifies a key size which is too large or too small. + case keySizeNotAllowed = -25311 + /// A required component (data storage module) could not be loaded. You may need to restart your computer. + case noStorageModule = -25312 + /// A required component (certificate module) could not be loaded. You may need to restart your computer. + case noCertificateModule = -25313 + /// A required component (policy module) could not be loaded. You may need to restart your computer. + case noPolicyModule = -25314 + /// User interaction is required, but is currently not allowed. + case interactionRequired = -25315 + /// The contents of this item cannot be retrieved. + case dataNotAvailable = -25316 + /// The contents of this item cannot be modified. + case dataNotModifiable = -25317 + /// One or more certificates required to validate this certificate cannot be found. + case createChainFailed = -25318 + /// The specified preferences domain is not valid. + case invalidPrefsDomain = -25319 + /// In dark wake, no UI possible. + case inDarkWake = -25320 + /// The specified access control list is not in standard (simple) form. + case aclNotSimple = -25240 + /// The specified policy cannot be found. + case policyNotFound = -25241 + /// The specified trust setting is invalid. + case invalidTrustSetting = -25242 + /// The specified item has no access control. + case noAccessForItem = -25243 + /// Invalid attempt to change the owner of this item. + case invalidOwnerEdit = -25244 + /// No trust results are available. + case trustNotAvailable = -25245 + /// Import/Export format unsupported. + case unsupportedFormat = -25256 + /// Unknown format in import. + case unknownFormat = -25257 + /// Key material must be wrapped for export. + case keyIsSensitive = -25258 + /// An attempt was made to import multiple private keys. + case multiplePrivKeys = -25259 + /// Passphrase is required for import/export. + case passphraseRequired = -25260 + /// The password reference was invalid. + case invalidPasswordRef = -25261 + /// The Trust Settings Record was corrupted. + case invalidTrustSettings = -25262 + /// No Trust Settings were found. + case noTrustSettings = -25263 + /// MAC verification failed during PKCS12 import (wrong password?) + case pkcs12VerifyFailure = -25264 + /// A certificate was not signed by its proposed parent. + case notSigner = -26267 + /// Unable to decode the provided data. + case decode = -26275 + /// The required service is not available. + case serviceNotAvailable = -67585 + /// The client ID is not correct. + case insufficientClientID = -67586 + /// A device reset has occurred. + case deviceReset = -67587 + /// A device failure has occurred. + case deviceFailed = -67588 + /// Adding an application ACL subject failed. + case appleAddAppACLSubject = -67589 + /// The public key is incomplete. + case applePublicKeyIncomplete = -67590 + /// A signature mismatch has occurred. + case appleSignatureMismatch = -67591 + /// The specified key has an invalid start date. + case appleInvalidKeyStartDate = -67592 + /// The specified key has an invalid end date. + case appleInvalidKeyEndDate = -67593 + /// A conversion error has occurred. + case conversionError = -67594 + /// A SSLv2 rollback error has occurred. + case appleSSLv2Rollback = -67595 + /// The quota was exceeded. + case quotaExceeded = -67596 + /// The file is too big. + case fileTooBig = -67597 + /// The specified database has an invalid blob. + case invalidDatabaseBlob = -67598 + /// The specified database has an invalid key blob. + case invalidKeyBlob = -67599 + /// The specified database has an incompatible blob. + case incompatibleDatabaseBlob = -67600 + /// The specified database has an incompatible key blob. + case incompatibleKeyBlob = -67601 + /// A host name mismatch has occurred. + case hostNameMismatch = -67602 + /// There is an unknown critical extension flag. + case unknownCriticalExtensionFlag = -67603 + /// No basic constraints were found. + case noBasicConstraints = -67604 + /// No basic CA constraints were found. + case noBasicConstraintsCA = -67605 + /// The authority key ID is not valid. + case invalidAuthorityKeyID = -67606 + /// The subject key ID is not valid. + case invalidSubjectKeyID = -67607 + /// The key usage is not valid for the specified policy. + case invalidKeyUsageForPolicy = -67608 + /// The extended key usage is not valid. + case invalidExtendedKeyUsage = -67609 + /// The ID linkage is not valid. + case invalidIDLinkage = -67610 + /// The path length constraint was exceeded. + case pathLengthConstraintExceeded = -67611 + /// The root or anchor certificate is not valid. + case invalidRoot = -67612 + /// The CRL has expired. + case crlExpired = -67613 + /// The CRL is not yet valid. + case crlNotValidYet = -67614 + /// The CRL was not found. + case crlNotFound = -67615 + /// The CRL server is down. + case crlServerDown = -67616 + /// The CRL has a bad Uniform Resource Identifier. + case crlBadURI = -67617 + /// An unknown certificate extension was encountered. + case unknownCertExtension = -67618 + /// An unknown CRL extension was encountered. + case unknownCRLExtension = -67619 + /// The CRL is not trusted. + case crlNotTrusted = -67620 + /// The CRL policy failed. + case crlPolicyFailed = -67621 + /// The issuing distribution point was not valid. + case idpFailure = -67622 + /// An email address mismatch was encountered. + case smimeEmailAddressesNotFound = -67623 + /// The appropriate extended key usage for SMIME was not found. + case smimeBadExtendedKeyUsage = -67624 + /// The key usage is not compatible with SMIME. + case smimeBadKeyUsage = -67625 + /// The key usage extension is not marked as critical. + case smimeKeyUsageNotCritical = -67626 + /// No email address was found in the certificate. + case smimeNoEmailAddress = -67627 + /// The subject alternative name extension is not marked as critical. + case smimeSubjAltNameNotCritical = -67628 + /// The appropriate extended key usage for SSL was not found. + case sslBadExtendedKeyUsage = -67629 + /// The OCSP response was incorrect or could not be parsed. + case ocspBadResponse = -67630 + /// The OCSP request was incorrect or could not be parsed. + case ocspBadRequest = -67631 + /// OCSP service is unavailable. + case ocspUnavailable = -67632 + /// The OCSP server did not recognize this certificate. + case ocspStatusUnrecognized = -67633 + /// An end-of-data was detected. + case endOfData = -67634 + /// An incomplete certificate revocation check occurred. + case incompleteCertRevocationCheck = -67635 + /// A network failure occurred. + case networkFailure = -67636 + /// The OCSP response was not trusted to a root or anchor certificate. + case ocspNotTrustedToAnchor = -67637 + /// The record was modified. + case recordModified = -67638 + /// The OCSP response had an invalid signature. + case ocspSignatureError = -67639 + /// The OCSP response had no signer. + case ocspNoSigner = -67640 + /// The OCSP responder was given a malformed request. + case ocspResponderMalformedReq = -67641 + /// The OCSP responder encountered an internal error. + case ocspResponderInternalError = -67642 + /// The OCSP responder is busy, try again later. + case ocspResponderTryLater = -67643 + /// The OCSP responder requires a signature. + case ocspResponderSignatureRequired = -67644 + /// The OCSP responder rejected this request as unauthorized. + case ocspResponderUnauthorized = -67645 + /// The OCSP response nonce did not match the request. + case ocspResponseNonceMismatch = -67646 + /// Code signing encountered an incorrect certificate chain length. + case codeSigningBadCertChainLength = -67647 + /// Code signing found no basic constraints. + case codeSigningNoBasicConstraints = -67648 + /// Code signing encountered an incorrect path length constraint. + case codeSigningBadPathLengthConstraint = -67649 + /// Code signing found no extended key usage. + case codeSigningNoExtendedKeyUsage = -67650 + /// Code signing indicated use of a development-only certificate. + case codeSigningDevelopment = -67651 + /// Resource signing has encountered an incorrect certificate chain length. + case resourceSignBadCertChainLength = -67652 + /// Resource signing has encountered an error in the extended key usage. + case resourceSignBadExtKeyUsage = -67653 + /// The trust setting for this policy was set to Deny. + case trustSettingDeny = -67654 + /// An invalid certificate subject name was encountered. + case invalidSubjectName = -67655 + /// An unknown qualified certificate statement was encountered. + case unknownQualifiedCertStatement = -67656 + case mobileMeRequestQueued = -67657 + case mobileMeRequestRedirected = -67658 + case mobileMeServerError = -67659 + case mobileMeServerNotAvailable = -67660 + case mobileMeServerAlreadyExists = -67661 + case mobileMeServerServiceErr = -67662 + case mobileMeRequestAlreadyPending = -67663 + case mobileMeNoRequestPending = -67664 + case mobileMeCSRVerifyFailure = -67665 + case mobileMeFailedConsistencyCheck = -67666 + /// A function was called without initializing CSSM. + case notInitialized = -67667 + /// The CSSM handle does not match with the service type. + case invalidHandleUsage = -67668 + /// A reference to the calling module was not found in the list of authorized callers. + case pvcReferentNotFound = -67669 + /// A function address was not within the verified module. + case functionIntegrityFail = -67670 + /// An internal error has occurred. + case internalError = -67671 + /// A memory error has occurred. + case memoryError = -67672 + /// Invalid data was encountered. + case invalidData = -67673 + /// A Module Directory Service error has occurred. + case mdsError = -67674 + /// An invalid pointer was encountered. + case invalidPointer = -67675 + /// Self-check has failed. + case selfCheckFailed = -67676 + /// A function has failed. + case functionFailed = -67677 + /// A module manifest verification failure has occurred. + case moduleManifestVerifyFailed = -67678 + /// An invalid GUID was encountered. + case invalidGUID = -67679 + /// An invalid handle was encountered. + case invalidHandle = -67680 + /// An invalid DB list was encountered. + case invalidDBList = -67681 + /// An invalid passthrough ID was encountered. + case invalidPassthroughID = -67682 + /// An invalid network address was encountered. + case invalidNetworkAddress = -67683 + /// The certificate revocation list is already signed. + case crlAlreadySigned = -67684 + /// An invalid number of fields were encountered. + case invalidNumberOfFields = -67685 + /// A verification failure occurred. + case verificationFailure = -67686 + /// An unknown tag was encountered. + case unknownTag = -67687 + /// An invalid signature was encountered. + case invalidSignature = -67688 + /// An invalid name was encountered. + case invalidName = -67689 + /// An invalid certificate reference was encountered. + case invalidCertificateRef = -67690 + /// An invalid certificate group was encountered. + case invalidCertificateGroup = -67691 + /// The specified tag was not found. + case tagNotFound = -67692 + /// The specified query was not valid. + case invalidQuery = -67693 + /// An invalid value was detected. + case invalidValue = -67694 + /// A callback has failed. + case callbackFailed = -67695 + /// An ACL delete operation has failed. + case aclDeleteFailed = -67696 + /// An ACL replace operation has failed. + case aclReplaceFailed = -67697 + /// An ACL add operation has failed. + case aclAddFailed = -67698 + /// An ACL change operation has failed. + case aclChangeFailed = -67699 + /// Invalid access credentials were encountered. + case invalidAccessCredentials = -67700 + /// An invalid record was encountered. + case invalidRecord = -67701 + /// An invalid ACL was encountered. + case invalidACL = -67702 + /// An invalid sample value was encountered. + case invalidSampleValue = -67703 + /// An incompatible version was encountered. + case incompatibleVersion = -67704 + /// The privilege was not granted. + case privilegeNotGranted = -67705 + /// An invalid scope was encountered. + case invalidScope = -67706 + /// The PVC is already configured. + case pvcAlreadyConfigured = -67707 + /// An invalid PVC was encountered. + case invalidPVC = -67708 + /// The EMM load has failed. + case emmLoadFailed = -67709 + /// The EMM unload has failed. + case emmUnloadFailed = -67710 + /// The add-in load operation has failed. + case addinLoadFailed = -67711 + /// An invalid key was encountered. + case invalidKeyRef = -67712 + /// An invalid key hierarchy was encountered. + case invalidKeyHierarchy = -67713 + /// The add-in unload operation has failed. + case addinUnloadFailed = -67714 + /// A library reference was not found. + case libraryReferenceNotFound = -67715 + /// An invalid add-in function table was encountered. + case invalidAddinFunctionTable = -67716 + /// An invalid service mask was encountered. + case invalidServiceMask = -67717 + /// A module was not loaded. + case moduleNotLoaded = -67718 + /// An invalid subservice ID was encountered. + case invalidSubServiceID = -67719 + /// An attribute was not in the context. + case attributeNotInContext = -67720 + /// A module failed to initialize. + case moduleManagerInitializeFailed = -67721 + /// A module was not found. + case moduleManagerNotFound = -67722 + /// An event notification callback was not found. + case eventNotificationCallbackNotFound = -67723 + /// An input length error was encountered. + case inputLengthError = -67724 + /// An output length error was encountered. + case outputLengthError = -67725 + /// The privilege is not supported. + case privilegeNotSupported = -67726 + /// A device error was encountered. + case deviceError = -67727 + /// The CSP handle was busy. + case attachHandleBusy = -67728 + /// You are not logged in. + case notLoggedIn = -67729 + /// An algorithm mismatch was encountered. + case algorithmMismatch = -67730 + /// The key usage is incorrect. + case keyUsageIncorrect = -67731 + /// The key blob type is incorrect. + case keyBlobTypeIncorrect = -67732 + /// The key header is inconsistent. + case keyHeaderInconsistent = -67733 + /// The key header format is not supported. + case unsupportedKeyFormat = -67734 + /// The key size is not supported. + case unsupportedKeySize = -67735 + /// The key usage mask is not valid. + case invalidKeyUsageMask = -67736 + /// The key usage mask is not supported. + case unsupportedKeyUsageMask = -67737 + /// The key attribute mask is not valid. + case invalidKeyAttributeMask = -67738 + /// The key attribute mask is not supported. + case unsupportedKeyAttributeMask = -67739 + /// The key label is not valid. + case invalidKeyLabel = -67740 + /// The key label is not supported. + case unsupportedKeyLabel = -67741 + /// The key format is not valid. + case invalidKeyFormat = -67742 + /// The vector of buffers is not supported. + case unsupportedVectorOfBuffers = -67743 + /// The input vector is not valid. + case invalidInputVector = -67744 + /// The output vector is not valid. + case invalidOutputVector = -67745 + /// An invalid context was encountered. + case invalidContext = -67746 + /// An invalid algorithm was encountered. + case invalidAlgorithm = -67747 + /// A key attribute was not valid. + case invalidAttributeKey = -67748 + /// A key attribute was missing. + case missingAttributeKey = -67749 + /// An init vector attribute was not valid. + case invalidAttributeInitVector = -67750 + /// An init vector attribute was missing. + case missingAttributeInitVector = -67751 + /// A salt attribute was not valid. + case invalidAttributeSalt = -67752 + /// A salt attribute was missing. + case missingAttributeSalt = -67753 + /// A padding attribute was not valid. + case invalidAttributePadding = -67754 + /// A padding attribute was missing. + case missingAttributePadding = -67755 + /// A random number attribute was not valid. + case invalidAttributeRandom = -67756 + /// A random number attribute was missing. + case missingAttributeRandom = -67757 + /// A seed attribute was not valid. + case invalidAttributeSeed = -67758 + /// A seed attribute was missing. + case missingAttributeSeed = -67759 + /// A passphrase attribute was not valid. + case invalidAttributePassphrase = -67760 + /// A passphrase attribute was missing. + case missingAttributePassphrase = -67761 + /// A key length attribute was not valid. + case invalidAttributeKeyLength = -67762 + /// A key length attribute was missing. + case missingAttributeKeyLength = -67763 + /// A block size attribute was not valid. + case invalidAttributeBlockSize = -67764 + /// A block size attribute was missing. + case missingAttributeBlockSize = -67765 + /// An output size attribute was not valid. + case invalidAttributeOutputSize = -67766 + /// An output size attribute was missing. + case missingAttributeOutputSize = -67767 + /// The number of rounds attribute was not valid. + case invalidAttributeRounds = -67768 + /// The number of rounds attribute was missing. + case missingAttributeRounds = -67769 + /// An algorithm parameters attribute was not valid. + case invalidAlgorithmParms = -67770 + /// An algorithm parameters attribute was missing. + case missingAlgorithmParms = -67771 + /// A label attribute was not valid. + case invalidAttributeLabel = -67772 + /// A label attribute was missing. + case missingAttributeLabel = -67773 + /// A key type attribute was not valid. + case invalidAttributeKeyType = -67774 + /// A key type attribute was missing. + case missingAttributeKeyType = -67775 + /// A mode attribute was not valid. + case invalidAttributeMode = -67776 + /// A mode attribute was missing. + case missingAttributeMode = -67777 + /// An effective bits attribute was not valid. + case invalidAttributeEffectiveBits = -67778 + /// An effective bits attribute was missing. + case missingAttributeEffectiveBits = -67779 + /// A start date attribute was not valid. + case invalidAttributeStartDate = -67780 + /// A start date attribute was missing. + case missingAttributeStartDate = -67781 + /// An end date attribute was not valid. + case invalidAttributeEndDate = -67782 + /// An end date attribute was missing. + case missingAttributeEndDate = -67783 + /// A version attribute was not valid. + case invalidAttributeVersion = -67784 + /// A version attribute was missing. + case missingAttributeVersion = -67785 + /// A prime attribute was not valid. + case invalidAttributePrime = -67786 + /// A prime attribute was missing. + case missingAttributePrime = -67787 + /// A base attribute was not valid. + case invalidAttributeBase = -67788 + /// A base attribute was missing. + case missingAttributeBase = -67789 + /// A subprime attribute was not valid. + case invalidAttributeSubprime = -67790 + /// A subprime attribute was missing. + case missingAttributeSubprime = -67791 + /// An iteration count attribute was not valid. + case invalidAttributeIterationCount = -67792 + /// An iteration count attribute was missing. + case missingAttributeIterationCount = -67793 + /// A database handle attribute was not valid. + case invalidAttributeDLDBHandle = -67794 + /// A database handle attribute was missing. + case missingAttributeDLDBHandle = -67795 + /// An access credentials attribute was not valid. + case invalidAttributeAccessCredentials = -67796 + /// An access credentials attribute was missing. + case missingAttributeAccessCredentials = -67797 + /// A public key format attribute was not valid. + case invalidAttributePublicKeyFormat = -67798 + /// A public key format attribute was missing. + case missingAttributePublicKeyFormat = -67799 + /// A private key format attribute was not valid. + case invalidAttributePrivateKeyFormat = -67800 + /// A private key format attribute was missing. + case missingAttributePrivateKeyFormat = -67801 + /// A symmetric key format attribute was not valid. + case invalidAttributeSymmetricKeyFormat = -67802 + /// A symmetric key format attribute was missing. + case missingAttributeSymmetricKeyFormat = -67803 + /// A wrapped key format attribute was not valid. + case invalidAttributeWrappedKeyFormat = -67804 + /// A wrapped key format attribute was missing. + case missingAttributeWrappedKeyFormat = -67805 + /// A staged operation is in progress. + case stagedOperationInProgress = -67806 + /// A staged operation was not started. + case stagedOperationNotStarted = -67807 + /// A cryptographic verification failure has occurred. + case verifyFailed = -67808 + /// The query size is unknown. + case querySizeUnknown = -67809 + /// A block size mismatch occurred. + case blockSizeMismatch = -67810 + /// The public key was inconsistent. + case publicKeyInconsistent = -67811 + /// A device verification failure has occurred. + case deviceVerifyFailed = -67812 + /// An invalid login name was detected. + case invalidLoginName = -67813 + /// The user is already logged in. + case alreadyLoggedIn = -67814 + /// An invalid digest algorithm was detected. + case invalidDigestAlgorithm = -67815 + /// An invalid CRL group was detected. + case invalidCRLGroup = -67816 + /// The certificate cannot operate. + case certificateCannotOperate = -67817 + /// An expired certificate was detected. + case certificateExpired = -67818 + /// The certificate is not yet valid. + case certificateNotValidYet = -67819 + /// The certificate was revoked. + case certificateRevoked = -67820 + /// The certificate was suspended. + case certificateSuspended = -67821 + /// Insufficient credentials were detected. + case insufficientCredentials = -67822 + /// The action was not valid. + case invalidAction = -67823 + /// The authority was not valid. + case invalidAuthority = -67824 + /// A verify action has failed. + case verifyActionFailed = -67825 + /// The certificate authority was not valid. + case invalidCertAuthority = -67826 + /// The CRL authority was not valid. + case invalidCRLAuthority = -67827 + /// The CRL encoding was not valid. + case invalidCRLEncoding = -67828 + /// The CRL type was not valid. + case invalidCRLType = -67829 + /// The CRL was not valid. + case invalidCRL = -67830 + /// The form type was not valid. + case invalidFormType = -67831 + /// The ID was not valid. + case invalidID = -67832 + /// The identifier was not valid. + case invalidIdentifier = -67833 + /// The index was not valid. + case invalidIndex = -67834 + /// The policy identifiers are not valid. + case invalidPolicyIdentifiers = -67835 + /// The time specified was not valid. + case invalidTimeString = -67836 + /// The trust policy reason was not valid. + case invalidReason = -67837 + /// The request inputs are not valid. + case invalidRequestInputs = -67838 + /// The response vector was not valid. + case invalidResponseVector = -67839 + /// The stop-on policy was not valid. + case invalidStopOnPolicy = -67840 + /// The tuple was not valid. + case invalidTuple = -67841 + /// Multiple values are not supported. + case multipleValuesUnsupported = -67842 + /// The certificate was not trusted. + case notTrusted = -67843 + /// No default authority was detected. + case noDefaultAuthority = -67844 + /// The trust policy had a rejected form. + case rejectedForm = -67845 + /// The request was lost. + case requestLost = -67846 + /// The request was rejected. + case requestRejected = -67847 + /// The address type is not supported. + case unsupportedAddressType = -67848 + /// The service is not supported. + case unsupportedService = -67849 + /// The tuple group was not valid. + case invalidTupleGroup = -67850 + /// The base ACLs are not valid. + case invalidBaseACLs = -67851 + /// The tuple credentials are not valid. + case invalidTupleCredentials = -67852 + /// The encoding was not valid. + case invalidEncoding = -67853 + /// The validity period was not valid. + case invalidValidityPeriod = -67854 + /// The requestor was not valid. + case invalidRequestor = -67855 + /// The request descriptor was not valid. + case requestDescriptor = -67856 + /// The bundle information was not valid. + case invalidBundleInfo = -67857 + /// The CRL index was not valid. + case invalidCRLIndex = -67858 + /// No field values were detected. + case noFieldValues = -67859 + /// The field format is not supported. + case unsupportedFieldFormat = -67860 + /// The index information is not supported. + case unsupportedIndexInfo = -67861 + /// The locality is not supported. + case unsupportedLocality = -67862 + /// The number of attributes is not supported. + case unsupportedNumAttributes = -67863 + /// The number of indexes is not supported. + case unsupportedNumIndexes = -67864 + /// The number of record types is not supported. + case unsupportedNumRecordTypes = -67865 + /// Too many fields were specified. + case fieldSpecifiedMultiple = -67866 + /// The field format was incompatible. + case incompatibleFieldFormat = -67867 + /// The parsing module was not valid. + case invalidParsingModule = -67868 + /// The database is locked. + case databaseLocked = -67869 + /// The data store is open. + case datastoreIsOpen = -67870 + /// A missing value was detected. + case missingValue = -67871 + /// The query limits are not supported. + case unsupportedQueryLimits = -67872 + /// The number of selection predicates is not supported. + case unsupportedNumSelectionPreds = -67873 + /// The operator is not supported. + case unsupportedOperator = -67874 + /// The database location is not valid. + case invalidDBLocation = -67875 + /// The access request is not valid. + case invalidAccessRequest = -67876 + /// The index information is not valid. + case invalidIndexInfo = -67877 + /// The new owner is not valid. + case invalidNewOwner = -67878 + /// The modify mode is not valid. + case invalidModifyMode = -67879 + /// A required certificate extension is missing. + case missingRequiredExtension = -67880 + /// The extended key usage extension was not marked critical. + case extendedKeyUsageNotCritical = -67881 + /// A timestamp was expected but was not found. + case timestampMissing = -67882 + /// The timestamp was not valid. + case timestampInvalid = -67883 + /// The timestamp was not trusted. + case timestampNotTrusted = -67884 + /// The timestamp service is not available. + case timestampServiceNotAvailable = -67885 + /// An unrecognized or unsupported Algorithm Identifier in timestamp. + case timestampBadAlg = -67886 + /// The timestamp transaction is not permitted or supported. + case timestampBadRequest = -67887 + /// The timestamp data submitted has the wrong format. + case timestampBadDataFormat = -67888 + /// The time source for the Timestamp Authority is not available. + case timestampTimeNotAvailable = -67889 + /// The requested policy is not supported by the Timestamp Authority. + case timestampUnacceptedPolicy = -67890 + /// The requested extension is not supported by the Timestamp Authority. + case timestampUnacceptedExtension = -67891 + /// The additional information requested is not available. + case timestampAddInfoNotAvailable = -67892 + /// The timestamp request cannot be handled due to system failure. + case timestampSystemFailure = -67893 + /// A signing time was expected but was not found. + case signingTimeMissing = -67894 + /// A timestamp transaction was rejected. + case timestampRejection = -67895 + /// A timestamp transaction is waiting. + case timestampWaiting = -67896 + /// A timestamp authority revocation warning was issued. + case timestampRevocationWarning = -67897 + /// A timestamp authority revocation notification was issued. + case timestampRevocationNotification = -67898 + /// The requested policy is not allowed for this certificate. + case certificatePolicyNotAllowed = -67899 + /// The requested name is not allowed for this certificate. + case certificateNameNotAllowed = -67900 + /// The validity period in the certificate exceeds the maximum allowed. + case certificateValidityPeriodTooLong = -67901 + /// The verified certificate is a CA rather than an end-entity. + case certificateIsCA = -67902 + /// The certificate contains multiple extensions with the same extension ID. + case certificateDuplicateExtension = -67903 + /// A qualified certificate statement was expected but missing. + case missingQualifiedCertStatement = -67904 + } +} +// swiftlint:disable:this file_length diff --git a/Keychain/Sources/Keychain/Error/SecError.swift b/Keychain/Sources/Keychain/Error/SecError.swift new file mode 100644 index 0000000..339b40c --- /dev/null +++ b/Keychain/Sources/Keychain/Error/SecError.swift @@ -0,0 +1,24 @@ +// +// SecError.swift +// Keychain +// +// Created by Bram Kolkman on 22/02/2026. +// + +import Foundation + +/// Describes errors within the security error domain. +public struct SecError: Error, Hashable, Sendable { + /// The error code. + public let code: Code + /// The description of the error. + public var errorDescription: String? { + SecCopyErrorMessageString(code.rawValue, nil) as? String + } + + /// Create the error. + /// - Parameter code: The error code. + init(_ code: Code) { + self.code = code + } +}