Procházet zdrojové kódy

throw explicit exception if keychain was accessed too early

cyberta před 3 roky
rodič
revize
346d7cc1f8
1 změnil soubory, kde provedl 7 přidání a 3 odebrání
  1. 7 3
      DcCore/DcCore/Helper/KeychainManager.swift

+ 7 - 3
DcCore/DcCore/Helper/KeychainManager.swift

@@ -66,10 +66,14 @@ public class KeychainManager {
                                     kSecReturnData as String: true]
         var item: CFTypeRef?
         let status = SecItemCopyMatching(query as CFDictionary, &item)
-        guard status != errSecItemNotFound else {
+        switch status {
+        case errSecSuccess:
+            break
+        case errSecItemNotFound:
             throw KeychainError.noPassword
-        }
-        guard status == errSecSuccess else {
+        case errSecInteractionNotAllowed:
+            throw KeychainError.unhandledError(message: "Keychain not yet available.", status: status)
+        default:
             throw KeychainError.unhandledError(message: "Unknown error while querying secret for account \(id):",
                                                status: status)
         }