17
17
import Foundation
18
18
19
19
20
- internal final class Keychain {
20
+ final class Keychain {
21
21
22
22
// MARK: Private Static Properties
23
23
@@ -26,7 +26,7 @@ internal final class Keychain {
26
26
27
27
// MARK: Keychain Accessibility
28
28
29
- internal static func canAccess( attributes: [ String : AnyHashable ] ) -> Bool {
29
+ static func canAccess( attributes: [ String : AnyHashable ] ) -> Bool {
30
30
func isCanaryValueInKeychain( ) -> Bool {
31
31
do {
32
32
let retrievedCanaryValue = try string ( forKey: canaryKey, options: attributes)
@@ -52,7 +52,7 @@ internal final class Keychain {
52
52
53
53
// MARK: Getters
54
54
55
- internal static func string( forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) -> String {
55
+ static func string( forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) -> String {
56
56
let data = try object ( forKey: key, options: options)
57
57
if let string = String ( data: data, encoding: . utf8) {
58
58
return string
@@ -61,7 +61,7 @@ internal final class Keychain {
61
61
}
62
62
}
63
63
64
- internal static func object( forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) -> Data {
64
+ static func object( forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) -> Data {
65
65
guard !key. isEmpty else {
66
66
throw KeychainError . emptyKey
67
67
}
@@ -76,12 +76,12 @@ internal final class Keychain {
76
76
77
77
// MARK: Setters
78
78
79
- internal static func setString( _ string: String , forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) {
79
+ static func setString( _ string: String , forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) {
80
80
let data = Data ( string. utf8)
81
81
try setObject ( data, forKey: key, options: options)
82
82
}
83
83
84
- internal static func setObject( _ object: Data , forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) {
84
+ static func setObject( _ object: Data , forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) {
85
85
guard !key. isEmpty else {
86
86
throw KeychainError . emptyKey
87
87
}
@@ -110,7 +110,7 @@ internal final class Keychain {
110
110
111
111
// MARK: Removal
112
112
113
- internal static func removeObject( forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) {
113
+ static func removeObject( forKey key: String , options: [ String : AnyHashable ] ) throws ( KeychainError) {
114
114
guard !key. isEmpty else {
115
115
throw KeychainError . emptyKey
116
116
}
@@ -121,13 +121,13 @@ internal final class Keychain {
121
121
try SecItem . deleteItems ( matching: secItemQuery)
122
122
}
123
123
124
- internal static func removeAllObjects( matching options: [ String : AnyHashable ] ) throws ( KeychainError) {
124
+ static func removeAllObjects( matching options: [ String : AnyHashable ] ) throws ( KeychainError) {
125
125
try SecItem . deleteItems ( matching: options)
126
126
}
127
127
128
128
// MARK: Contains
129
129
130
- internal static func performCopy( forKey key: String , options: [ String : AnyHashable ] ) -> OSStatus {
130
+ static func performCopy( forKey key: String , options: [ String : AnyHashable ] ) -> OSStatus {
131
131
guard !key. isEmpty else {
132
132
return errSecParam
133
133
}
@@ -140,7 +140,7 @@ internal final class Keychain {
140
140
141
141
// MARK: AllObjects
142
142
143
- internal static func allKeys( options: [ String : AnyHashable ] ) throws ( KeychainError) -> Set < String > {
143
+ static func allKeys( options: [ String : AnyHashable ] ) throws ( KeychainError) -> Set < String > {
144
144
var secItemQuery = options
145
145
secItemQuery [ kSecMatchLimit as String ] = kSecMatchLimitAll
146
146
secItemQuery [ kSecReturnAttributes as String ] = true
@@ -171,7 +171,7 @@ internal final class Keychain {
171
171
172
172
// MARK: Migration
173
173
174
- internal static func migrateObjects( matching query: [ String : AnyHashable ] , into destinationAttributes: [ String : AnyHashable ] , compactMap: ( MigratableKeyValuePair < AnyHashable > ) throws -> MigratableKeyValuePair < String > ? ) throws {
174
+ static func migrateObjects( matching query: [ String : AnyHashable ] , into destinationAttributes: [ String : AnyHashable ] , compactMap: ( MigratableKeyValuePair < AnyHashable > ) throws -> MigratableKeyValuePair < String > ? ) throws {
175
175
guard !query. isEmpty else {
176
176
// Migration requires secItemQuery to contain values.
177
177
throw MigrationError . invalidQuery
@@ -317,7 +317,7 @@ internal final class Keychain {
317
317
}
318
318
}
319
319
320
- internal static func migrateObjects( matching query: [ String : AnyHashable ] , into destinationAttributes: [ String : AnyHashable ] , removeOnCompletion: Bool ) throws {
320
+ static func migrateObjects( matching query: [ String : AnyHashable ] , into destinationAttributes: [ String : AnyHashable ] , removeOnCompletion: Bool ) throws {
321
321
// Capture the keys in the destination prior to migration beginning.
322
322
let keysInKeychainPreMigration = Set ( try Keychain . allKeys ( options: destinationAttributes) )
323
323
@@ -343,7 +343,7 @@ internal final class Keychain {
343
343
}
344
344
}
345
345
346
- internal static func revertMigration( into destinationAttributes: [ String : AnyHashable ] , keysInKeychainPreMigration: Set < String > ) {
346
+ static func revertMigration( into destinationAttributes: [ String : AnyHashable ] , keysInKeychainPreMigration: Set < String > ) {
347
347
if let allKeysPostPotentiallyPartialMigration = try ? Keychain . allKeys ( options: destinationAttributes) {
348
348
let migratedKeys = allKeysPostPotentiallyPartialMigration. subtracting ( keysInKeychainPreMigration)
349
349
migratedKeys. forEach { migratedKey in
0 commit comments