Skip to content

Commit 5de4289

Browse files
authored
Revert "fix(Auth): Use correct queries when getting and setting keychain items (#2965)" (#2975)
1 parent b5ab2a9 commit 5de4289

File tree

3 files changed

+6
-82
lines changed

3 files changed

+6
-82
lines changed

AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStore.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public struct KeychainStore: KeychainStoreBehavior {
9999
/// - Parameter key: A String key use to look up the value in the Keychain
100100
/// - Returns: A data value
101101
public func _getData(_ key: String) throws -> Data {
102-
var query = attributes.defaultGetQuery()
102+
var query = attributes.query()
103103

104104
query[Constants.MatchLimit] = Constants.MatchLimitOne
105105
query[Constants.ReturnData] = kCFBooleanTrue
@@ -142,7 +142,7 @@ public struct KeychainStore: KeychainStoreBehavior {
142142
/// - value: A data value to store in Keychain
143143
/// - key: A String key for the value to store in the Keychain
144144
public func _set(_ value: Data, key: String) throws {
145-
var query = attributes.defaultSetQuery()
145+
var query = attributes.query()
146146
query[Constants.AttributeAccount] = key
147147

148148
let fetchStatus = SecItemCopyMatching(query as CFDictionary, nil)
@@ -173,7 +173,7 @@ public struct KeychainStore: KeychainStoreBehavior {
173173
/// This System Programming Interface (SPI) may have breaking changes in future updates.
174174
/// - Parameter key: A String key to delete the key-value pair
175175
public func _remove(_ key: String) throws {
176-
var query = attributes.defaultGetQuery()
176+
var query = attributes.query()
177177
query[Constants.AttributeAccount] = key
178178

179179
let status = SecItemDelete(query as CFDictionary)
@@ -186,7 +186,7 @@ public struct KeychainStore: KeychainStoreBehavior {
186186
/// Removes all key-value pair in the Keychain.
187187
/// This System Programming Interface (SPI) may have breaking changes in future updates.
188188
public func _removeAll() throws {
189-
var query = attributes.defaultGetQuery()
189+
var query = attributes.query()
190190
#if !os(iOS) && !os(watchOS) && !os(tvOS)
191191
query[Constants.MatchLimit] = Constants.MatchLimitAll
192192
#endif

AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreAttributes.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@ struct KeychainStoreAttributes {
1919

2020
extension KeychainStoreAttributes {
2121

22-
func defaultGetQuery() -> [String: Any] {
22+
func query() -> [String: Any] {
2323
var query: [String: Any] = [
2424
KeychainStore.Constants.Class: itemClass,
2525
KeychainStore.Constants.AttributeService: service
2626
]
2727
if let accessGroup = accessGroup {
2828
query[KeychainStore.Constants.AttributeAccessGroup] = accessGroup
2929
}
30-
return query
31-
}
32-
33-
func defaultSetQuery() -> [String: Any] {
34-
var query: [String: Any] = defaultGetQuery()
3530
query[KeychainStore.Constants.AttributeAccessible] = KeychainStore.Constants.AttributeAccessibleAfterFirstUnlockThisDeviceOnly
3631
query[KeychainStore.Constants.UseDataProtectionKeyChain] = kCFBooleanTrue
3732
return query
@@ -42,7 +37,7 @@ extension KeychainStoreAttributes {
4237
var attributes: [String: Any]
4338

4439
if key != nil {
45-
attributes = defaultGetQuery()
40+
attributes = query()
4641
attributes[KeychainStore.Constants.AttributeAccount] = key
4742
} else {
4843
attributes = [String: Any]()

AmplifyPlugins/Core/AWSPluginsCoreTests/Keychain/KeychainStoreAttributesTests.swift

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)