Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Valet/Identifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct Identifier: CustomStringConvertible, Sendable {
// MARK: CustomStringConvertible

public var description: String {
return backingString
backingString
}

// MARK: Private Properties
Expand Down
8 changes: 4 additions & 4 deletions Sources/Valet/Internal/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
import Foundation


internal enum Configuration: CustomStringConvertible, Sendable {
enum Configuration: CustomStringConvertible, Sendable {
case valet(Accessibility)
case iCloud(CloudAccessibility)
case secureEnclave(SecureEnclaveAccessControl)
case singlePromptSecureEnclave(SecureEnclaveAccessControl)

// MARK: CustomStringConvertible

internal var description: String {
var description: String {
switch self {
case .valet:
return "VALValet"
Expand All @@ -40,7 +40,7 @@ internal enum Configuration: CustomStringConvertible, Sendable {

// MARK: Internal Properties

internal var accessibility: Accessibility {
var accessibility: Accessibility {
switch self {
case let .valet(accessibility):
return accessibility
Expand All @@ -51,7 +51,7 @@ internal enum Configuration: CustomStringConvertible, Sendable {
}
}

internal var prettyDescription: String {
var prettyDescription: String {
let configurationDescription: String = {
switch self {
case .valet:
Expand Down
26 changes: 13 additions & 13 deletions Sources/Valet/Internal/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation


internal final class Keychain {
final class Keychain {

// MARK: Private Static Properties

Expand All @@ -26,7 +26,7 @@ internal final class Keychain {

// MARK: Keychain Accessibility

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

// MARK: Getters

internal static func string(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) -> String {
static func string(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) -> String {
let data = try object(forKey: key, options: options)
if let string = String(data: data, encoding: .utf8) {
return string
Expand All @@ -61,7 +61,7 @@ internal final class Keychain {
}
}

internal static func object(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) -> Data {
static func object(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) -> Data {
guard !key.isEmpty else {
throw KeychainError.emptyKey
}
Expand All @@ -76,12 +76,12 @@ internal final class Keychain {

// MARK: Setters

internal static func setString(_ string: String, forKey key: String, options: [String: AnyHashable]) throws(KeychainError) {
static func setString(_ string: String, forKey key: String, options: [String: AnyHashable]) throws(KeychainError) {
let data = Data(string.utf8)
try setObject(data, forKey: key, options: options)
}

internal static func setObject(_ object: Data, forKey key: String, options: [String: AnyHashable]) throws(KeychainError) {
static func setObject(_ object: Data, forKey key: String, options: [String: AnyHashable]) throws(KeychainError) {
guard !key.isEmpty else {
throw KeychainError.emptyKey
}
Expand Down Expand Up @@ -110,7 +110,7 @@ internal final class Keychain {

// MARK: Removal

internal static func removeObject(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
static func removeObject(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
guard !key.isEmpty else {
throw KeychainError.emptyKey
}
Expand All @@ -121,13 +121,13 @@ internal final class Keychain {
try SecItem.deleteItems(matching: secItemQuery)
}

internal static func removeAllObjects(matching options: [String : AnyHashable]) throws(KeychainError) {
static func removeAllObjects(matching options: [String : AnyHashable]) throws(KeychainError) {
try SecItem.deleteItems(matching: options)
}

// MARK: Contains

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

// MARK: AllObjects

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

// MARK: Migration

internal static func migrateObjects(matching query: [String : AnyHashable], into destinationAttributes: [String : AnyHashable], compactMap: (MigratableKeyValuePair<AnyHashable>) throws -> MigratableKeyValuePair<String>?) throws {
static func migrateObjects(matching query: [String : AnyHashable], into destinationAttributes: [String : AnyHashable], compactMap: (MigratableKeyValuePair<AnyHashable>) throws -> MigratableKeyValuePair<String>?) throws {
guard !query.isEmpty else {
// Migration requires secItemQuery to contain values.
throw MigrationError.invalidQuery
Expand Down Expand Up @@ -317,7 +317,7 @@ internal final class Keychain {
}
}

internal static func migrateObjects(matching query: [String : AnyHashable], into destinationAttributes: [String : AnyHashable], removeOnCompletion: Bool) throws {
static func migrateObjects(matching query: [String : AnyHashable], into destinationAttributes: [String : AnyHashable], removeOnCompletion: Bool) throws {
// Capture the keys in the destination prior to migration beginning.
let keysInKeychainPreMigration = Set(try Keychain.allKeys(options: destinationAttributes))

Expand All @@ -343,7 +343,7 @@ internal final class Keychain {
}
}

internal static func revertMigration(into destinationAttributes: [String : AnyHashable], keysInKeychainPreMigration: Set<String>) {
static func revertMigration(into destinationAttributes: [String : AnyHashable], keysInKeychainPreMigration: Set<String>) {
if let allKeysPostPotentiallyPartialMigration = try? Keychain.allKeys(options: destinationAttributes) {
let migratedKeys = allKeysPostPotentiallyPartialMigration.subtracting(keysInKeychainPreMigration)
migratedKeys.forEach { migratedKey in
Expand Down
14 changes: 7 additions & 7 deletions Sources/Valet/Internal/SecItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation


internal func execute<ReturnType>(in lock: NSLock, block: () throws -> ReturnType) rethrows -> ReturnType {
func execute<ReturnType>(in lock: NSLock, block: () throws -> ReturnType) rethrows -> ReturnType {
lock.lock()
defer {
lock.unlock()
Expand All @@ -26,11 +26,11 @@ internal func execute<ReturnType>(in lock: NSLock, block: () throws -> ReturnTyp
}


internal final class SecItem {
final class SecItem {

// MARK: Internal Class Methods

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

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

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

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

internal static func deleteItems(matching query: [String : AnyHashable]) throws(KeychainError) {
static func deleteItems(matching query: [String : AnyHashable]) throws(KeychainError) {
if query.isEmpty {
assertionFailure("Must provide a query with at least one item")
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/Valet/Internal/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation


internal enum Service: CustomStringConvertible, Equatable, Sendable {
enum Service: CustomStringConvertible, Equatable, Sendable {
case standard(Identifier, Configuration)
case sharedGroup(SharedGroupIdentifier, Identifier?, Configuration)

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

// MARK: Equatable

internal static func ==(lhs: Service, rhs: Service) -> Bool {
static func ==(lhs: Service, rhs: Service) -> Bool {
lhs.description == rhs.description
}

// MARK: CustomStringConvertible

internal var description: String {
var description: String {
secService
}

// MARK: Internal Static Methods

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

internal static func sharedGroup(with configuration: Configuration, groupIdentifier: SharedGroupIdentifier, identifier: Identifier?, accessibilityDescription: String) -> String {
static func sharedGroup(with configuration: Configuration, groupIdentifier: SharedGroupIdentifier, identifier: Identifier?, accessibilityDescription: String) -> String {
if let identifier = identifier {
return "VAL_\(configuration.description)_initWithSharedAccessGroupIdentifier:accessibility:_\(groupIdentifier.groupIdentifier)_\(identifier)_\(accessibilityDescription)"
} else {
return "VAL_\(configuration.description)_initWithSharedAccessGroupIdentifier:accessibility:_\(groupIdentifier.groupIdentifier)_\(accessibilityDescription)"
}
}

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

// MARK: Internal Methods

internal func generateBaseQuery() -> [String : AnyHashable] {
func generateBaseQuery() -> [String : AnyHashable] {
var baseQuery: [String : AnyHashable] = [
kSecClass as String : kSecClassGenericPassword as String,
kSecAttrService as String : secService,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Valet/Internal/WeakStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import Foundation


internal final class WeakStorage<T: AnyObject>: @unchecked Sendable {
internal subscript(_ key: String) -> T? {
final class WeakStorage<T: AnyObject>: @unchecked Sendable {
subscript(_ key: String) -> T? {
get {
lock.withLock {
identifierToValetMap.object(forKey: key as NSString)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Valet/MigratableKeyValuePair.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final class ObjectiveCCompatibilityMigratableKeyValuePairInput: NSObject

// MARK: Initialization

internal init(key: Any, value: Data) {
init(key: Any, value: Data) {
self.key = key
self.value = value
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public class ObjectiveCCompatibilityMigratableKeyValuePairOutput: NSObject {

// MARK: Internal

internal fileprivate(set) var preventMigration: Bool
fileprivate(set) var preventMigration: Bool

}

Expand Down
16 changes: 8 additions & 8 deletions Sources/Valet/SecureEnclave.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class SecureEnclave: Sendable {
/// - Parameter service: The service of the keychain slice we want to check if we can access.
/// - Returns: `true` if the keychain is accessible for reading and writing, `false` otherwise.
/// - Note: Determined by writing a value to the keychain and then reading it back out.
internal static func canAccessKeychain(with service: Service) -> Bool {
static func canAccessKeychain(with service: Service) -> Bool {
// 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.
let noPromptValet: Valet
switch service {
Expand All @@ -53,7 +53,7 @@ public final class SecureEnclave: Sendable {
/// - key: A key that can be used to retrieve the `object` from the keychain.
/// - options: A base query used to scope the calls in the keychain.
/// - Throws: An error of type `KeychainError`.
internal static func setObject(_ object: Data, forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
static func setObject(_ object: Data, forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
// 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.
try Keychain.removeObject(forKey: key, options: options)

Expand All @@ -68,7 +68,7 @@ public final class SecureEnclave: Sendable {
/// - options: A base query used to scope the calls in the keychain.
/// - Returns: The data currently stored in the keychain for the provided key.
/// - Throws: An error of type `KeychainError`.
internal static func object(
static func object(
forKey key: String,
withPrompt userPrompt: String,
context: LAContext?,
Expand All @@ -88,7 +88,7 @@ public final class SecureEnclave: Sendable {
/// - options: A base query used to scope the calls in the keychain.
/// - Returns: The data currently stored in the keychain for the provided key.
/// - Throws: An error of type `KeychainError`.
internal static func object(
static func object(
forKey key: String,
options: [String : AnyHashable]
) throws(KeychainError) -> Data {
Expand All @@ -102,7 +102,7 @@ public final class SecureEnclave: Sendable {
/// - options: A base query used to scope the calls in the keychain.
/// - Returns: `true` if a value has been set for the given key, `false` otherwise.
/// - Throws: An error of type `KeychainError`.
internal static func containsObject(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) -> Bool {
static func containsObject(forKey key: String, options: [String : AnyHashable]) throws(KeychainError) -> Bool {
var secItemQuery = options
let context = LAContext()
context.interactionNotAllowed = true
Expand All @@ -127,7 +127,7 @@ public final class SecureEnclave: Sendable {
/// - key: A key that can be used to retrieve the `string` from the keychain.
/// - options: A base query used to scope the calls in the keychain.
/// - Throws: An error of type `KeychainError`.
internal static func setString(_ string: String, forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
static func setString(_ string: String, forKey key: String, options: [String : AnyHashable]) throws(KeychainError) {
// 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.
try Keychain.removeObject(forKey: key, options: options)

Expand All @@ -142,7 +142,7 @@ public final class SecureEnclave: Sendable {
/// - options: A base query used to scope the calls in the keychain.
/// - Returns: The string currently stored in the keychain for the provided key.
/// - Throws: An error of type `KeychainError`.
internal static func string(
static func string(
forKey key: String,
withPrompt userPrompt: String,
context: LAContext?,
Expand All @@ -162,7 +162,7 @@ public final class SecureEnclave: Sendable {
/// - options: A base query used to scope the calls in the keychain.
/// - Returns: The string currently stored in the keychain for the provided key.
/// - Throws: An error of type `KeychainError`.
internal static func string(
static func string(
forKey key: String,
options: [String : AnyHashable]
) throws(KeychainError) -> String {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Valet/SecureEnclaveAccessControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public enum SecureEnclaveAccessControl: Int, CustomStringConvertible, Equatable,

// MARK: Internal Properties

internal var secAccessControl: SecAccessControlCreateFlags {
var secAccessControl: SecAccessControlCreateFlags {
switch self {
case .userPresence:
.userPresence
Expand All @@ -73,7 +73,7 @@ public enum SecureEnclaveAccessControl: Int, CustomStringConvertible, Equatable,
}
}

internal static func allValues() -> [SecureEnclaveAccessControl] {
static func allValues() -> [SecureEnclaveAccessControl] {
[
.userPresence,
.devicePasscode,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Valet/SecureEnclaveValet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public final class SecureEnclaveValet: NSObject, Sendable {

// MARK: Internal Properties

internal let service: Service
let service: Service

// MARK: Private Properties

Expand Down
Loading