From ad4e699ce12c55b429ae97b2d751f1290bc9a9d2 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Sat, 21 Nov 2020 15:21:04 -0800 Subject: [PATCH] Fix push issues --- Keychain/Sources/Keychain/Keychain.swift | 10 +++++++++- .../ServiceLayer/Services/AllIdentitiesService.swift | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Keychain/Sources/Keychain/Keychain.swift b/Keychain/Sources/Keychain/Keychain.swift index 65b1eca..dbd1598 100644 --- a/Keychain/Sources/Keychain/Keychain.swift +++ b/Keychain/Sources/Keychain/Keychain.swift @@ -19,7 +19,13 @@ extension LiveKeychain: Keychain { query[kSecValueData as String] = data - let status = SecItemAdd(query as CFDictionary, nil) + var status = SecItemAdd(query as CFDictionary, nil) + + if status == errSecDuplicateItem { + status = SecItemUpdate( + genericPasswordQueryDictionary(account: account, service: service) as CFDictionary, + [kSecValueData as String: data] as CFDictionary) + } if status != errSecSuccess { throw NSError(status: status) @@ -54,6 +60,8 @@ extension LiveKeychain: Keychain { } public static func generateKeyAndReturnPublicKey(applicationTag: String, attributes: [String: Any]) throws -> Data { + try? deleteKey(applicationTag: applicationTag) + var attributes = attributes var error: Unmanaged? diff --git a/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift b/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift index d925dc8..a5e8dd4 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift @@ -124,6 +124,7 @@ public extension AllIdentitiesService { } } .map(Publishers.MergeMany.init) + .flatMap { $0 } .ignoreOutput() .eraseToAnyPublisher() }