Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
2b3834b3c1
commit
974d67571e
@ -45,13 +45,17 @@ actor KeychainHelper {
|
||||
let status = SecItemAdd(addQuery as CFDictionary, nil)
|
||||
|
||||
if status == errSecDuplicateItem {
|
||||
// Item exists, update it
|
||||
let updateStatus = SecItemUpdate(
|
||||
query as CFDictionary,
|
||||
[kSecValueData as String: data] as CFDictionary
|
||||
)
|
||||
if updateStatus != errSecSuccess {
|
||||
throw StorageError.keychainError(updateStatus)
|
||||
// Item exists - delete and re-add to update both data and security attributes.
|
||||
// SecItemUpdate cannot change accessibility or access control, so we must
|
||||
// delete the existing item and add a new one with the desired attributes.
|
||||
let deleteStatus = SecItemDelete(query as CFDictionary)
|
||||
if deleteStatus != errSecSuccess && deleteStatus != errSecItemNotFound {
|
||||
throw StorageError.keychainError(deleteStatus)
|
||||
}
|
||||
|
||||
let readdStatus = SecItemAdd(addQuery as CFDictionary, nil)
|
||||
if readdStatus != errSecSuccess {
|
||||
throw StorageError.keychainError(readdStatus)
|
||||
}
|
||||
} else if status != errSecSuccess {
|
||||
throw StorageError.keychainError(status)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user