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