Skip to content

Commit 101f7c7

Browse files
committed
update returns Bool
1 parent d28d9e3 commit 101f7c7

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Sources/Basics/AuthorizationProvider.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,10 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
166166
let `protocol` = self.`protocol`(for: url)
167167

168168
do {
169-
try self.update(server: server, protocol: `protocol`, account: user, password: passwordData)
170-
callback(.success(()))
171-
} catch AuthorizationProviderError.notFound {
172-
do {
169+
if !(try self.update(server: server, protocol: `protocol`, account: user, password: passwordData)) {
173170
try self.create(server: server, protocol: `protocol`, account: user, password: passwordData)
174-
callback(.success(()))
175-
} catch {
176-
callback(.failure(error))
177171
}
172+
callback(.success(()))
178173
} catch {
179174
callback(.failure(error))
180175
}
@@ -219,7 +214,7 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
219214
}
220215
}
221216

222-
private func update(server: String, `protocol`: CFString, account: String, password: Data) throws {
217+
private func update(server: String, `protocol`: CFString, account: String, password: Data) throws -> Bool {
223218
let query: [String: Any] = [kSecClass as String: kSecClassInternetPassword,
224219
kSecAttrServer as String: server,
225220
kSecAttrProtocol as String: `protocol`]
@@ -228,11 +223,12 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
228223

229224
let status = SecItemUpdate(query as CFDictionary, attributes as CFDictionary)
230225
guard status != errSecItemNotFound else {
231-
throw AuthorizationProviderError.notFound
226+
return false
232227
}
233228
guard status == errSecSuccess else {
234229
throw AuthorizationProviderError.other("Failed to update credentials for server \(server) in keychain: status \(status)")
235230
}
231+
return true
236232
}
237233

238234
private func search(server: String, `protocol`: CFString) throws -> CFTypeRef? {

0 commit comments

Comments
 (0)