-
-
Save fitomad/9b291baf4f8e7579c2f9405bb6e49163 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ejecutamos la búqueda | |
let status = SecItemCopyMatching(query as CFDictionary, &item) | |
// Comprobamos si no aparece el elemento... | |
if status == errSecItemNotFound | |
{ | |
return Result.failure(KeychainError.passwordNotFound) | |
} | |
// ...y en caso de encontrarlos lo procesamos | |
if status == errSecSuccess | |
{ | |
guard let existingItem = item as? [String : Any], | |
let passwordData = existingItem[kSecValueData as String] as? Data, | |
let password = String(data: passwordData, encoding: .utf8), | |
let account = existingItem[kSecAttrAccount as String] as? String | |
else | |
{ | |
return Result.failure(KeychainError.malformedData) | |
} | |
let user = User(named: account, withPassword: password) | |
return Result.success(user) | |
} | |
else | |
{ | |
return Result.failure(KeychainError.unknown(status: status)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment