Skip to content

Commit 29bea84

Browse files
authored
Code cleanup, Remove "internal" access modifiers from code (#340)
* Remove "internal" access modifiers from code #339 * Code cleanup: remove unnecessary return statements
1 parent 036197f commit 29bea84

14 files changed

+57
-57
lines changed

Sources/Valet/Identifier.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public struct Identifier: CustomStringConvertible, Sendable {
3232
// MARK: CustomStringConvertible
3333

3434
public var description: String {
35-
return backingString
35+
backingString
3636
}
3737

3838
// MARK: Private Properties

Sources/Valet/Internal/Configuration.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
import Foundation
1818

1919

20-
internal enum Configuration: CustomStringConvertible, Sendable {
20+
enum Configuration: CustomStringConvertible, Sendable {
2121
case valet(Accessibility)
2222
case iCloud(CloudAccessibility)
2323
case secureEnclave(SecureEnclaveAccessControl)
2424
case singlePromptSecureEnclave(SecureEnclaveAccessControl)
2525

2626
// MARK: CustomStringConvertible
2727

28-
internal var description: String {
28+
var description: String {
2929
switch self {
3030
case .valet:
3131
return "VALValet"
@@ -40,7 +40,7 @@ internal enum Configuration: CustomStringConvertible, Sendable {
4040

4141
// MARK: Internal Properties
4242

43-
internal var accessibility: Accessibility {
43+
var accessibility: Accessibility {
4444
switch self {
4545
case let .valet(accessibility):
4646
return accessibility
@@ -51,7 +51,7 @@ internal enum Configuration: CustomStringConvertible, Sendable {
5151
}
5252
}
5353

54-
internal var prettyDescription: String {
54+
var prettyDescription: String {
5555
let configurationDescription: String = {
5656
switch self {
5757
case .valet:

Sources/Valet/Internal/Keychain.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import Foundation
1818

1919

20-
internal final class Keychain {
20+
final class Keychain {
2121

2222
// MARK: Private Static Properties
2323

@@ -26,7 +26,7 @@ internal final class Keychain {
2626

2727
// MARK: Keychain Accessibility
2828

29-
internal static func canAccess(attributes: [String : AnyHashable]) -> Bool {
29+
static func canAccess(attributes: [String : AnyHashable]) -> Bool {
3030
func isCanaryValueInKeychain() -> Bool {
3131
do {
3232
let retrievedCanaryValue = try string(forKey: canaryKey, options: attributes)
@@ -52,7 +52,7 @@ internal final class Keychain {
5252

5353
// MARK: Getters
5454

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 {
5656
let data = try object(forKey: key, options: options)
5757
if let string = String(data: data, encoding: .utf8) {
5858
return string
@@ -61,7 +61,7 @@ internal final class Keychain {
6161
}
6262
}
6363

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 {
6565
guard !key.isEmpty else {
6666
throw KeychainError.emptyKey
6767
}
@@ -76,12 +76,12 @@ internal final class Keychain {
7676

7777
// MARK: Setters
7878

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) {
8080
let data = Data(string.utf8)
8181
try setObject(data, forKey: key, options: options)
8282
}
8383

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) {
8585
guard !key.isEmpty else {
8686
throw KeychainError.emptyKey
8787
}
@@ -110,7 +110,7 @@ internal final class Keychain {
110110

111111
// MARK: Removal
112112

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) {
114114
guard !key.isEmpty else {
115115
throw KeychainError.emptyKey
116116
}
@@ -121,13 +121,13 @@ internal final class Keychain {
121121
try SecItem.deleteItems(matching: secItemQuery)
122122
}
123123

124-
internal static func removeAllObjects(matching options: [String : AnyHashable]) throws(KeychainError) {
124+
static func removeAllObjects(matching options: [String : AnyHashable]) throws(KeychainError) {
125125
try SecItem.deleteItems(matching: options)
126126
}
127127

128128
// MARK: Contains
129129

130-
internal static func performCopy(forKey key: String, options: [String : AnyHashable]) -> OSStatus {
130+
static func performCopy(forKey key: String, options: [String : AnyHashable]) -> OSStatus {
131131
guard !key.isEmpty else {
132132
return errSecParam
133133
}
@@ -140,7 +140,7 @@ internal final class Keychain {
140140

141141
// MARK: AllObjects
142142

143-
internal static func allKeys(options: [String: AnyHashable]) throws(KeychainError) -> Set<String> {
143+
static func allKeys(options: [String: AnyHashable]) throws(KeychainError) -> Set<String> {
144144
var secItemQuery = options
145145
secItemQuery[kSecMatchLimit as String] = kSecMatchLimitAll
146146
secItemQuery[kSecReturnAttributes as String] = true
@@ -171,7 +171,7 @@ internal final class Keychain {
171171

172172
// MARK: Migration
173173

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 {
175175
guard !query.isEmpty else {
176176
// Migration requires secItemQuery to contain values.
177177
throw MigrationError.invalidQuery
@@ -317,7 +317,7 @@ internal final class Keychain {
317317
}
318318
}
319319

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 {
321321
// Capture the keys in the destination prior to migration beginning.
322322
let keysInKeychainPreMigration = Set(try Keychain.allKeys(options: destinationAttributes))
323323

@@ -343,7 +343,7 @@ internal final class Keychain {
343343
}
344344
}
345345

346-
internal static func revertMigration(into destinationAttributes: [String : AnyHashable], keysInKeychainPreMigration: Set<String>) {
346+
static func revertMigration(into destinationAttributes: [String : AnyHashable], keysInKeychainPreMigration: Set<String>) {
347347
if let allKeysPostPotentiallyPartialMigration = try? Keychain.allKeys(options: destinationAttributes) {
348348
let migratedKeys = allKeysPostPotentiallyPartialMigration.subtracting(keysInKeychainPreMigration)
349349
migratedKeys.forEach { migratedKey in

Sources/Valet/Internal/SecItem.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import Foundation
1818

1919

20-
internal func execute<ReturnType>(in lock: NSLock, block: () throws -> ReturnType) rethrows -> ReturnType {
20+
func execute<ReturnType>(in lock: NSLock, block: () throws -> ReturnType) rethrows -> ReturnType {
2121
lock.lock()
2222
defer {
2323
lock.unlock()
@@ -26,11 +26,11 @@ internal func execute<ReturnType>(in lock: NSLock, block: () throws -> ReturnTyp
2626
}
2727

2828

29-
internal final class SecItem {
29+
final class SecItem {
3030

3131
// MARK: Internal Class Methods
3232

33-
internal static func copy<DesiredType>(matching query: [String : AnyHashable]) throws(KeychainError) -> DesiredType {
33+
static func copy<DesiredType>(matching query: [String : AnyHashable]) throws(KeychainError) -> DesiredType {
3434
if query.isEmpty {
3535
assertionFailure("Must provide a query with at least one item")
3636
}
@@ -56,7 +56,7 @@ internal final class SecItem {
5656
}
5757
}
5858

59-
internal static func performCopy(matching query: [String : AnyHashable]) -> OSStatus {
59+
static func performCopy(matching query: [String : AnyHashable]) -> OSStatus {
6060
guard !query.isEmpty else {
6161
// Must provide a query with at least one item
6262
return errSecParam
@@ -70,7 +70,7 @@ internal final class SecItem {
7070
return status
7171
}
7272

73-
internal static func add(attributes: [String : AnyHashable]) throws(KeychainError) {
73+
static func add(attributes: [String : AnyHashable]) throws(KeychainError) {
7474
if attributes.isEmpty {
7575
assertionFailure("Must provide attributes with at least one item")
7676
}
@@ -90,7 +90,7 @@ internal final class SecItem {
9090
}
9191
}
9292

93-
internal static func update(attributes: [String : AnyHashable], forItemsMatching query: [String : AnyHashable]) throws(KeychainError) {
93+
static func update(attributes: [String : AnyHashable], forItemsMatching query: [String : AnyHashable]) throws(KeychainError) {
9494
if attributes.isEmpty {
9595
assertionFailure("Must provide attributes with at least one item")
9696
}
@@ -113,7 +113,7 @@ internal final class SecItem {
113113
}
114114
}
115115

116-
internal static func deleteItems(matching query: [String : AnyHashable]) throws(KeychainError) {
116+
static func deleteItems(matching query: [String : AnyHashable]) throws(KeychainError) {
117117
if query.isEmpty {
118118
assertionFailure("Must provide a query with at least one item")
119119
}

Sources/Valet/Internal/Service.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import Foundation
1818

1919

20-
internal enum Service: CustomStringConvertible, Equatable, Sendable {
20+
enum Service: CustomStringConvertible, Equatable, Sendable {
2121
case standard(Identifier, Configuration)
2222
case sharedGroup(SharedGroupIdentifier, Identifier?, Configuration)
2323

@@ -28,37 +28,37 @@ internal enum Service: CustomStringConvertible, Equatable, Sendable {
2828

2929
// MARK: Equatable
3030

31-
internal static func ==(lhs: Service, rhs: Service) -> Bool {
31+
static func ==(lhs: Service, rhs: Service) -> Bool {
3232
lhs.description == rhs.description
3333
}
3434

3535
// MARK: CustomStringConvertible
3636

37-
internal var description: String {
37+
var description: String {
3838
secService
3939
}
4040

4141
// MARK: Internal Static Methods
4242

43-
internal static func standard(with configuration: Configuration, identifier: Identifier, accessibilityDescription: String) -> String {
43+
static func standard(with configuration: Configuration, identifier: Identifier, accessibilityDescription: String) -> String {
4444
"VAL_\(configuration.description)_initWithIdentifier:accessibility:_\(identifier)_\(accessibilityDescription)"
4545
}
4646

47-
internal static func sharedGroup(with configuration: Configuration, groupIdentifier: SharedGroupIdentifier, identifier: Identifier?, accessibilityDescription: String) -> String {
47+
static func sharedGroup(with configuration: Configuration, groupIdentifier: SharedGroupIdentifier, identifier: Identifier?, accessibilityDescription: String) -> String {
4848
if let identifier = identifier {
4949
return "VAL_\(configuration.description)_initWithSharedAccessGroupIdentifier:accessibility:_\(groupIdentifier.groupIdentifier)_\(identifier)_\(accessibilityDescription)"
5050
} else {
5151
return "VAL_\(configuration.description)_initWithSharedAccessGroupIdentifier:accessibility:_\(groupIdentifier.groupIdentifier)_\(accessibilityDescription)"
5252
}
5353
}
5454

55-
internal static func sharedGroup(with configuration: Configuration, explicitlySetIdentifier identifier: Identifier, accessibilityDescription: String) -> String {
55+
static func sharedGroup(with configuration: Configuration, explicitlySetIdentifier identifier: Identifier, accessibilityDescription: String) -> String {
5656
"VAL_\(configuration.description)_initWithSharedAccessGroupIdentifier:accessibility:_\(identifier)_\(accessibilityDescription)"
5757
}
5858

5959
// MARK: Internal Methods
6060

61-
internal func generateBaseQuery() -> [String : AnyHashable] {
61+
func generateBaseQuery() -> [String : AnyHashable] {
6262
var baseQuery: [String : AnyHashable] = [
6363
kSecClass as String : kSecClassGenericPassword as String,
6464
kSecAttrService as String : secService,

Sources/Valet/Internal/WeakStorage.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import Foundation
1818

1919

20-
internal final class WeakStorage<T: AnyObject>: @unchecked Sendable {
21-
internal subscript(_ key: String) -> T? {
20+
final class WeakStorage<T: AnyObject>: @unchecked Sendable {
21+
subscript(_ key: String) -> T? {
2222
get {
2323
lock.withLock {
2424
identifierToValetMap.object(forKey: key as NSString)

Sources/Valet/MigratableKeyValuePair.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public final class ObjectiveCCompatibilityMigratableKeyValuePairInput: NSObject
5454

5555
// MARK: Initialization
5656

57-
internal init(key: Any, value: Data) {
57+
init(key: Any, value: Data) {
5858
self.key = key
5959
self.value = value
6060
}
@@ -116,7 +116,7 @@ public class ObjectiveCCompatibilityMigratableKeyValuePairOutput: NSObject {
116116

117117
// MARK: Internal
118118

119-
internal fileprivate(set) var preventMigration: Bool
119+
fileprivate(set) var preventMigration: Bool
120120

121121
}
122122

Sources/Valet/SecureEnclave.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public final class SecureEnclave: Sendable {
2727
/// - Parameter service: The service of the keychain slice we want to check if we can access.
2828
/// - Returns: `true` if the keychain is accessible for reading and writing, `false` otherwise.
2929
/// - Note: Determined by writing a value to the keychain and then reading it back out.
30-
internal static func canAccessKeychain(with service: Service) -> Bool {
30+
static func canAccessKeychain(with service: Service) -> Bool {
3131
// To avoid prompting the user for Touch ID or passcode, create a Valet with our identifier and accessibility and ask it if it can access the keychain.
3232
let noPromptValet: Valet
3333
switch service {
@@ -53,7 +53,7 @@ public final class SecureEnclave: Sendable {
5353
/// - key: A key that can be used to retrieve the `object` from the keychain.
5454
/// - options: A base query used to scope the calls in the keychain.
5555
/// - Throws: An error of type `KeychainError`.
56-
internal static func setObject(_ object: Data, forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
56+
static func setObject(_ object: Data, forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
5757
// Remove the key before trying to set it. This will prevent us from calling SecItemUpdate on an item stored on the Secure Enclave, which would cause iOS to prompt the user for authentication.
5858
try Keychain.removeObject(forKey: key, options: options)
5959

@@ -68,7 +68,7 @@ public final class SecureEnclave: Sendable {
6868
/// - options: A base query used to scope the calls in the keychain.
6969
/// - Returns: The data currently stored in the keychain for the provided key.
7070
/// - Throws: An error of type `KeychainError`.
71-
internal static func object(
71+
static func object(
7272
forKey key: String,
7373
withPrompt userPrompt: String,
7474
context: LAContext?,
@@ -88,7 +88,7 @@ public final class SecureEnclave: Sendable {
8888
/// - options: A base query used to scope the calls in the keychain.
8989
/// - Returns: The data currently stored in the keychain for the provided key.
9090
/// - Throws: An error of type `KeychainError`.
91-
internal static func object(
91+
static func object(
9292
forKey key: String,
9393
options: [String : AnyHashable]
9494
) throws(KeychainError) -> Data {
@@ -102,7 +102,7 @@ public final class SecureEnclave: Sendable {
102102
/// - options: A base query used to scope the calls in the keychain.
103103
/// - Returns: `true` if a value has been set for the given key, `false` otherwise.
104104
/// - Throws: An error of type `KeychainError`.
105-
internal static func containsObject(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) -> Bool {
105+
static func containsObject(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) -> Bool {
106106
var secItemQuery = options
107107
let context = LAContext()
108108
context.interactionNotAllowed = true
@@ -127,7 +127,7 @@ public final class SecureEnclave: Sendable {
127127
/// - key: A key that can be used to retrieve the `string` from the keychain.
128128
/// - options: A base query used to scope the calls in the keychain.
129129
/// - Throws: An error of type `KeychainError`.
130-
internal static func setString(_ string: String, forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
130+
static func setString(_ string: String, forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
131131
// Remove the key before trying to set it. This will prevent us from calling SecItemUpdate on an item stored on the Secure Enclave, which would cause iOS to prompt the user for authentication.
132132
try Keychain.removeObject(forKey: key, options: options)
133133

@@ -142,7 +142,7 @@ public final class SecureEnclave: Sendable {
142142
/// - options: A base query used to scope the calls in the keychain.
143143
/// - Returns: The string currently stored in the keychain for the provided key.
144144
/// - Throws: An error of type `KeychainError`.
145-
internal static func string(
145+
static func string(
146146
forKey key: String,
147147
withPrompt userPrompt: String,
148148
context: LAContext?,
@@ -162,7 +162,7 @@ public final class SecureEnclave: Sendable {
162162
/// - options: A base query used to scope the calls in the keychain.
163163
/// - Returns: The string currently stored in the keychain for the provided key.
164164
/// - Throws: An error of type `KeychainError`.
165-
internal static func string(
165+
static func string(
166166
forKey key: String,
167167
options: [String : AnyHashable]
168168
) throws(KeychainError) -> String {

Sources/Valet/SecureEnclaveAccessControl.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public enum SecureEnclaveAccessControl: Int, CustomStringConvertible, Equatable,
5252

5353
// MARK: Internal Properties
5454

55-
internal var secAccessControl: SecAccessControlCreateFlags {
55+
var secAccessControl: SecAccessControlCreateFlags {
5656
switch self {
5757
case .userPresence:
5858
.userPresence
@@ -73,7 +73,7 @@ public enum SecureEnclaveAccessControl: Int, CustomStringConvertible, Equatable,
7373
}
7474
}
7575

76-
internal static func allValues() -> [SecureEnclaveAccessControl] {
76+
static func allValues() -> [SecureEnclaveAccessControl] {
7777
[
7878
.userPresence,
7979
.devicePasscode,

Sources/Valet/SecureEnclaveValet.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public final class SecureEnclaveValet: NSObject, Sendable {
283283

284284
// MARK: Internal Properties
285285

286-
internal let service: Service
286+
let service: Service
287287

288288
// MARK: Private Properties
289289

0 commit comments

Comments
 (0)