Skip to content

Commit

Permalink
Remove SecItemDelete/SecItemAdd pair and change with SecItemUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
IldarAbdullin-okta committed Sep 25, 2020
1 parent a64c2c8 commit 179da11
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Sources/OktaSecureStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ open class OktaSecureStorage: NSObject {
if errorCode == noErr {
return
} else if errorCode == errSecDuplicateItem {

errorCode = SecItemDelete(query as CFDictionary)
if errorCode != noErr {
throw NSError(domain: OktaSecureStorage.keychainErrorDomain, code: Int(errorCode), userInfo: nil)
let searchQuery = findQuery(for: key, accessGroup: accessGroup)
query.removeValue(forKey: kSecClass as String)
query.removeValue(forKey: kSecAttrService as String)
if #available(macOS 10.15, iOS 13.0, *) {
query.removeValue(forKey: kSecUseDataProtectionKeychain as String)
}

errorCode = SecItemAdd(query as CFDictionary, nil)
errorCode = SecItemUpdate(searchQuery as CFDictionary, query as CFDictionary)
if errorCode != noErr {
throw NSError(domain: OktaSecureStorage.keychainErrorDomain, code: Int(errorCode), userInfo: nil)
}
Expand Down

0 comments on commit 179da11

Please sign in to comment.