Skip to content

Commit 0c57eb4

Browse files
grdsdevdependabot[bot]Widcket
authored
feat: add errSecMissingEntitlement error (#224)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rita Zerrizuela <[email protected]>
1 parent cc9209d commit 0c57eb4

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

SimpleKeychain/SimpleKeychainError.swift

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public struct SimpleKeychainError: LocalizedError, CustomDebugStringConvertible
1212
case itemNotFound
1313
case interactionNotAllowed
1414
case decodeFailed
15+
case missingEntitlement
1516
case other(status: OSStatus)
1617
case unknown(message: String)
1718

@@ -26,6 +27,7 @@ public struct SimpleKeychainError: LocalizedError, CustomDebugStringConvertible
2627
case errSecItemNotFound: self = .itemNotFound
2728
case errSecInteractionNotAllowed: self = .interactionNotAllowed
2829
case errSecDecode: self = .decodeFailed
30+
case errSecMissingEntitlement: self = .missingEntitlement
2931
default: self = .other(status: rawValue)
3032
}
3133
}
@@ -41,6 +43,7 @@ public struct SimpleKeychainError: LocalizedError, CustomDebugStringConvertible
4143
case .itemNotFound: return errSecItemNotFound
4244
case .interactionNotAllowed: return errSecInteractionNotAllowed
4345
case .decodeFailed: return errSecDecode
46+
case .missingEntitlement: return errSecMissingEntitlement
4447
case let .other(status): return status
4548
case .unknown: return errSecSuccess // This is not a Keychain error
4649
}
@@ -91,6 +94,8 @@ public struct SimpleKeychainError: LocalizedError, CustomDebugStringConvertible
9194
return "errSecInteractionNotAllowed: Interaction with the Security Server is not allowed."
9295
case .decodeFailed:
9396
return "errSecDecode: Unable to decode the provided data."
97+
case .missingEntitlement:
98+
return "errSecMissingEntitlement: A required entitlement is missing."
9499
case .other:
95100
return "Unspecified Keychain error: \(self.status)."
96101
case let .unknown(message):
@@ -136,6 +141,10 @@ public struct SimpleKeychainError: LocalizedError, CustomDebugStringConvertible
136141
/// See [errSecDecode](https://developer.apple.com/documentation/security/errsecdecode).
137142
public static let decodeFailed: SimpleKeychainError = .init(code: .decodeFailed)
138143

144+
/// A required entitlement is missing.
145+
/// See [errSecMissingEntitlement](https://developer.apple.com/documentation/security/errsecmissingentitlement).
146+
public static let missingEntitlement: SimpleKeychainError = .init(code: .missingEntitlement)
147+
139148
/// Other Keychain error.
140149
/// The `OSStatus` of the Keychain operation can be accessed via the ``status`` property.
141150
public static let other: SimpleKeychainError = .init(code: .other(status: 0))

SimpleKeychainTests/SimpleKeychainErrorSpec.swift

+18-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ class SimpleKeychainErrorSpec: XCTestCase {
108108
let sut = SimpleKeychainError(code: .decodeFailed)
109109
XCTAssertEqual(sut.localizedDescription, message)
110110
}
111-
111+
112+
func testErrorMessage_shouldReturnMessageForMissingEntitlement() {
113+
let message = "errSecMissingEntitlement: A required entitlement is missing."
114+
let sut = SimpleKeychainError(code: .missingEntitlement)
115+
XCTAssertEqual(sut.localizedDescription, message)
116+
}
117+
112118
func testErrorMessage_shouldReturnMessageForOtherError() {
113119
let status: OSStatus = 123
114120
let message = "Unspecified Keychain error: \(status)."
@@ -167,7 +173,12 @@ class SimpleKeychainErrorSpec: XCTestCase {
167173
let sut = SimpleKeychainError.Code(rawValue: errSecDecode)
168174
XCTAssertEqual(sut, SimpleKeychainError.decodeFailed.code)
169175
}
170-
176+
177+
func testMapErrSecMissingEntitlement() {
178+
let sut = SimpleKeychainError.Code(rawValue: errSecMissingEntitlement)
179+
XCTAssertEqual(sut, SimpleKeychainError.missingEntitlement.code)
180+
}
181+
171182
func testMapOtherStatusValue() {
172183
let status: OSStatus = 1234
173184
let sut = SimpleKeychainError.Code(rawValue: status)
@@ -205,7 +216,11 @@ class SimpleKeychainErrorSpec: XCTestCase {
205216
func testMapDecodeFailed() {
206217
XCTAssertEqual(SimpleKeychainError.decodeFailed.code.rawValue, errSecDecode)
207218
}
208-
219+
220+
func testMapMissingEntitlement() {
221+
XCTAssertEqual(SimpleKeychainError.missingEntitlement.code.rawValue, errSecMissingEntitlement)
222+
}
223+
209224
func testMapOther() {
210225
let status: OSStatus = 1234
211226
XCTAssertEqual(SimpleKeychainError(code: .other(status: status)).status, status)

0 commit comments

Comments
 (0)