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)
|
let status = SecItemAdd(addQuery as CFDictionary, nil)
|
||||||
|
|
||||||
if status == errSecDuplicateItem {
|
if status == errSecDuplicateItem {
|
||||||
// Item exists, update it
|
// Item exists - delete and re-add to update both data and security attributes.
|
||||||
let updateStatus = SecItemUpdate(
|
// SecItemUpdate cannot change accessibility or access control, so we must
|
||||||
query as CFDictionary,
|
// delete the existing item and add a new one with the desired attributes.
|
||||||
[kSecValueData as String: data] as CFDictionary
|
let deleteStatus = SecItemDelete(query as CFDictionary)
|
||||||
)
|
if deleteStatus != errSecSuccess && deleteStatus != errSecItemNotFound {
|
||||||
if updateStatus != errSecSuccess {
|
throw StorageError.keychainError(deleteStatus)
|
||||||
throw StorageError.keychainError(updateStatus)
|
}
|
||||||
|
|
||||||
|
let readdStatus = SecItemAdd(addQuery as CFDictionary, nil)
|
||||||
|
if readdStatus != errSecSuccess {
|
||||||
|
throw StorageError.keychainError(readdStatus)
|
||||||
}
|
}
|
||||||
} else if status != errSecSuccess {
|
} else if status != errSecSuccess {
|
||||||
throw StorageError.keychainError(status)
|
throw StorageError.keychainError(status)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user