Update Services
Summary: - Sources: Services Stats: - 1 file changed, 11 insertions(+), 7 deletions(-)
This commit is contained in:
parent
a79191450c
commit
d287c55b79
@ -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