Skip to content

Commit 3323016

Browse files
committed
Allow explicitly set identifiers on all systems
1 parent 58ad73e commit 3323016

File tree

3 files changed

+2
-29
lines changed

3 files changed

+2
-29
lines changed

Sources/Valet/Internal/Service.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ import Foundation
2020
enum Service: CustomStringConvertible, Equatable, Sendable {
2121
case standard(Identifier, Configuration)
2222
case sharedGroup(SharedGroupIdentifier, Identifier?, Configuration)
23-
24-
#if os(macOS)
2523
case standardOverride(service: Identifier, Configuration)
2624
case sharedGroupOverride(service: SharedGroupIdentifier, Configuration)
27-
#endif
2825

2926
// MARK: Equatable
3027

@@ -77,14 +74,12 @@ enum Service: CustomStringConvertible, Equatable, Sendable {
7774
baseQuery[kSecAttrAccessGroup as String] = groupIdentifier.description
7875
configuration = desiredConfiguration
7976

80-
#if os(macOS)
8177
case let .standardOverride(_, desiredConfiguration):
8278
configuration = desiredConfiguration
8379

8480
case let .sharedGroupOverride(identifier, desiredConfiguration):
8581
baseQuery[kSecAttrAccessGroup as String] = identifier.description
8682
configuration = desiredConfiguration
87-
#endif
8883
}
8984

9085
switch configuration {
@@ -113,12 +108,10 @@ enum Service: CustomStringConvertible, Equatable, Sendable {
113108
service = Service.standard(with: configuration, identifier: identifier, accessibilityDescription: configuration.accessibility.description)
114109
case let .sharedGroup(groupIdentifier, identifier, configuration):
115110
service = Service.sharedGroup(with: configuration, groupIdentifier: groupIdentifier, identifier: identifier, accessibilityDescription: configuration.accessibility.description)
116-
#if os(macOS)
117111
case let .standardOverride(identifier, _):
118112
service = identifier.description
119113
case let .sharedGroupOverride(identifier, _):
120114
service = identifier.groupIdentifier
121-
#endif
122115
}
123116

124117
switch self {
@@ -136,11 +129,9 @@ enum Service: CustomStringConvertible, Equatable, Sendable {
136129

137130
return service
138131

139-
#if os(macOS)
140132
case .standardOverride,
141133
.sharedGroupOverride:
142134
return service
143-
#endif
144135
}
145136
}
146137
}

Sources/Valet/SecureEnclave.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@ public final class SecureEnclave: Sendable {
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 {
34-
#if os(macOS)
3534
case let .standardOverride(identifier, _):
3635
noPromptValet = .valet(with: identifier, accessibility: .whenPasscodeSetThisDeviceOnly)
37-
#endif
3836
case let .standard(identifier, _):
3937
noPromptValet = .valet(with: identifier, accessibility: .whenPasscodeSetThisDeviceOnly)
40-
#if os(macOS)
4138
case let .sharedGroupOverride(identifier, _):
4239
noPromptValet = .sharedGroupValet(withExplicitlySet: identifier, accessibility: .whenPasscodeSetThisDeviceOnly)
43-
#endif
4440
case let .sharedGroup(groupIdentifier, identifier, _):
4541
noPromptValet = .sharedGroupValet(with: groupIdentifier, identifier: identifier, accessibility: .whenPasscodeSetThisDeviceOnly)
4642
}

Sources/Valet/Valet.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public final class Valet: NSObject, Sendable {
5858
findOrCreate(groupIdentifier, identifier: identifier, configuration: .iCloud(accessibility))
5959
}
6060

61-
#if os(macOS)
6261
/// Creates a Valet with an explicitly set kSecAttrService.
6362
/// - Parameters:
6463
/// - identifier: A non-empty string that uniquely identifies a Valet. Must be unique relative to other Valet identifiers.
@@ -102,8 +101,7 @@ public final class Valet: NSObject, Sendable {
102101
public class func iCloudSharedGroupValet(withExplicitlySet identifier: SharedGroupIdentifier, accessibility: CloudAccessibility) -> Valet {
103102
findOrCreate(explicitlySet: identifier, configuration: .iCloud(accessibility))
104103
}
105-
#endif
106-
104+
107105
// MARK: Equatable
108106

109107
/// - Returns: `true` if lhs and rhs both read from and write to the same sandbox within the keychain.
@@ -144,7 +142,6 @@ public final class Valet: NSObject, Sendable {
144142
}
145143

146144

147-
#if os(macOS)
148145
private class func findOrCreate(explicitlySet identifier: Identifier, configuration: Configuration) -> Valet {
149146
let service: Service = .standardOverride(service: identifier, configuration)
150147
let key = service.description + configuration.description + configuration.accessibility.description + identifier.description
@@ -171,8 +168,7 @@ public final class Valet: NSObject, Sendable {
171168
}
172169
}
173170

174-
#endif
175-
171+
176172
// MARK: Initialization
177173

178174
@available(*, unavailable)
@@ -201,7 +197,6 @@ public final class Valet: NSObject, Sendable {
201197
accessibility = configuration.accessibility
202198
}
203199

204-
#if os(macOS)
205200
private init(overrideIdentifier: Identifier, configuration: Configuration) {
206201
self.identifier = overrideIdentifier
207202
self.configuration = configuration
@@ -215,7 +210,6 @@ public final class Valet: NSObject, Sendable {
215210
service = .sharedGroupOverride(service: identifier, configuration)
216211
accessibility = configuration.accessibility
217212
}
218-
#endif
219213

220214
// MARK: CustomStringConvertible
221215

@@ -424,12 +418,10 @@ public final class Valet: NSObject, Sendable {
424418
serviceAttribute = Service.sharedGroup(with: configuration, groupIdentifier: sharedGroupIdentifier, identifier: identifier, accessibilityDescription: accessibilityDescription)
425419
case .standard:
426420
serviceAttribute = Service.standard(with: configuration, identifier: identifier, accessibilityDescription: accessibilityDescription)
427-
#if os(macOS)
428421
case let .sharedGroupOverride(sharedGroupIdentifier, _):
429422
serviceAttribute = sharedGroupIdentifier.description
430423
case .standardOverride:
431424
serviceAttribute = identifier.description
432-
#endif
433425
}
434426
keychainQuery[kSecAttrService as String] = serviceAttribute
435427
try migrateObjects(matching: keychainQuery, removeOnCompletion: removeOnCompletion)
@@ -459,12 +451,10 @@ public final class Valet: NSObject, Sendable {
459451
serviceAttribute = Service.sharedGroup(with: configuration, groupIdentifier: groupIdentifier, identifier: identifier, accessibilityDescription: accessibilityDescription)
460452
case .standard:
461453
serviceAttribute = Service.standard(with: configuration, identifier: identifier, accessibilityDescription: accessibilityDescription)
462-
#if os(macOS)
463454
case .sharedGroupOverride:
464455
serviceAttribute = Service.sharedGroup(with: configuration, explicitlySetIdentifier: identifier, accessibilityDescription: accessibilityDescription)
465456
case .standardOverride:
466457
serviceAttribute = Service.standard(with: configuration, identifier: identifier, accessibilityDescription: accessibilityDescription)
467-
#endif
468458
}
469459
keychainQuery[kSecAttrService as String] = serviceAttribute
470460
try migrateObjects(matching: keychainQuery, removeOnCompletion: removeOnCompletion)
@@ -590,7 +580,6 @@ extension Valet {
590580
return iCloudSharedGroupValet(with: identifier, accessibility: accessibility)
591581
}
592582

593-
#if os(macOS)
594583
/// Creates a Valet with an explicitly set kSecAttrService.
595584
/// - Parameters:
596585
/// - identifier: A non-empty string that uniquely identifies a Valet. Must be unique relative to other Valet identifiers.
@@ -658,7 +647,6 @@ extension Valet {
658647
}
659648
return findOrCreate(explicitlySet: identifier, configuration: .iCloud(accessibility))
660649
}
661-
#endif
662650

663651
// MARK: Public Methods
664652

@@ -751,7 +739,6 @@ extension Valet {
751739
}
752740
}
753741

754-
#if os(macOS)
755742
class func permutations(withExplictlySet identifier: Identifier, shared: Bool = false) -> [Valet] {
756743
Accessibility.allCases.map { accessibility in
757744
.valet(withExplicitlySet: identifier, accessibility: accessibility)
@@ -775,6 +762,5 @@ extension Valet {
775762
.iCloudSharedGroupValet(withExplicitlySet: identifier, accessibility: cloudAccessibility)
776763
}
777764
}
778-
#endif
779765

780766
}

0 commit comments

Comments
 (0)