row editing
This commit is contained in:
@@ -74,17 +74,53 @@ enum PasswordStore {
|
||||
return ""
|
||||
}
|
||||
|
||||
static func save(_ password: String, id: UUID) {
|
||||
@discardableResult
|
||||
static func save(_ password: String, id: UUID) -> Bool {
|
||||
let query: [String: Any] = [
|
||||
kSecClass as String: kSecClassGenericPassword,
|
||||
kSecAttrService as String: service,
|
||||
kSecAttrAccount as String: id.uuidString
|
||||
]
|
||||
SecItemDelete(query as CFDictionary)
|
||||
guard !password.isEmpty else { return }
|
||||
var attributes = query
|
||||
attributes[kSecValueData as String] = Data(password.utf8)
|
||||
SecItemAdd(attributes as CFDictionary, nil)
|
||||
|
||||
if password.isEmpty {
|
||||
let status = SecItemDelete(query as CFDictionary)
|
||||
return status == errSecSuccess || status == errSecItemNotFound
|
||||
}
|
||||
|
||||
let data = Data(password.utf8)
|
||||
|
||||
let update: [String: Any] = [
|
||||
kSecValueData as String: data
|
||||
]
|
||||
|
||||
let updateStatus = SecItemUpdate(
|
||||
query as CFDictionary,
|
||||
update as CFDictionary
|
||||
)
|
||||
|
||||
if updateStatus == errSecSuccess {
|
||||
return true
|
||||
}
|
||||
|
||||
if updateStatus == errSecItemNotFound {
|
||||
var attributes = query
|
||||
attributes[kSecValueData as String] = data
|
||||
|
||||
let addStatus = SecItemAdd(
|
||||
attributes as CFDictionary,
|
||||
nil
|
||||
)
|
||||
|
||||
if addStatus == errSecSuccess {
|
||||
return true
|
||||
}
|
||||
|
||||
NSLog("DBSyn Keychain add failed: %d", addStatus)
|
||||
return false
|
||||
}
|
||||
|
||||
NSLog("DBSyn Keychain update failed: %d", updateStatus)
|
||||
return false
|
||||
}
|
||||
|
||||
static func delete(_ id: UUID) {
|
||||
|
||||
Reference in New Issue
Block a user