From bab76da2abce3d390bc24c80e167ebafd8b2b8c3 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sun, 5 Jan 2025 16:27:41 -0800 Subject: [PATCH] Revert "Backport mutex" This reverts commit 9b02afb20c027cf89b6cd93c1dcc06655728a97a. --- Sources/Packages/Package.swift | 18 ++++------- .../Packages/Sources/Backports/_Mutex.swift | 30 ------------------- Sources/Packages/Sources/Brief/Updater.swift | 3 +- .../OpenSSH/OpenSSHCertificateHandler.swift | 3 +- .../Sources/SecretKit/SecretStoreList.swift | 5 ++-- .../SecureEnclaveStore.swift | 7 ++--- .../SmartCardSecretKit/SmartCardStore.swift | 3 +- Sources/SecretAgent/Notifier.swift | 3 +- .../Preview Content/PreviewUpdater.swift | 3 +- 9 files changed, 15 insertions(+), 60 deletions(-) delete mode 100644 Sources/Packages/Sources/Backports/_Mutex.swift diff --git a/Sources/Packages/Package.swift b/Sources/Packages/Package.swift index a666ec0..1594580 100644 --- a/Sources/Packages/Package.swift +++ b/Sources/Packages/Package.swift @@ -27,26 +27,18 @@ let package = Package( .library( name: "Brief", targets: ["Brief"]), - .library( - name: "Backports", - targets: ["Backports"]), ], dependencies: [ ], targets: [ - .target( - name: "Backports", - dependencies: [], - swiftSettings: swiftSettings - ), .target( name: "SecretKit", - dependencies: ["Backports"], + dependencies: [], swiftSettings: swiftSettings ), .testTarget( name: "SecretKitTests", - dependencies: ["Backports", "SecretKit", "SecureEnclaveSecretKit", "SmartCardSecretKit"], + dependencies: ["SecretKit", "SecureEnclaveSecretKit", "SmartCardSecretKit"], swiftSettings: swiftSettings ), .target( @@ -56,12 +48,12 @@ let package = Package( ), .target( name: "SmartCardSecretKit", - dependencies: ["Backports", "SecretKit"], + dependencies: ["SecretKit"], swiftSettings: swiftSettings ), .target( name: "SecretAgentKit", - dependencies: ["Backports", "SecretKit", "SecretAgentKitHeaders"], + dependencies: ["SecretKit", "SecretAgentKitHeaders"], swiftSettings: swiftSettings ), .systemLibrary( @@ -73,7 +65,7 @@ let package = Package( , .target( name: "Brief", - dependencies: ["Backports"] + dependencies: [] ), .testTarget( name: "BriefTests", diff --git a/Sources/Packages/Sources/Backports/_Mutex.swift b/Sources/Packages/Sources/Backports/_Mutex.swift deleted file mode 100644 index b389a58..0000000 --- a/Sources/Packages/Sources/Backports/_Mutex.swift +++ /dev/null @@ -1,30 +0,0 @@ -import Foundation - -#if canImport(Synchronization) -import Synchronization -public typealias _Mutex = Mutex -#else - -import os - -public final class _Mutex: @unchecked Sendable { - - private var value: Value - private var lock = OSAllocatedUnfairLock() - - public init(_ value: consuming sending Value) { - self.value = value - } - - public borrowing func withLock(_ body: (inout sending Value) throws(E) -> sending Result) throws(E) -> sending Result where E : Error, Result : ~Copyable { - lock.lock() - defer { - lock.unlock() - } - return try body(&value) - } - - -} - -#endif diff --git a/Sources/Packages/Sources/Brief/Updater.swift b/Sources/Packages/Sources/Brief/Updater.swift index 315e779..334689d 100644 --- a/Sources/Packages/Sources/Brief/Updater.swift +++ b/Sources/Packages/Sources/Brief/Updater.swift @@ -1,7 +1,6 @@ import Foundation import Observation import Synchronization -import Backports /// A concrete implementation of ``UpdaterProtocol`` which considers the current release and OS version. @Observable public final class Updater: UpdaterProtocol, ObservableObject, Sendable { @@ -9,7 +8,7 @@ import Backports public var update: Release? { _update.withLock { $0 } } - private let _update: _Mutex = .init(nil) + private let _update: Mutex = .init(nil) public let testBuild: Bool /// The current OS version. diff --git a/Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHCertificateHandler.swift b/Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHCertificateHandler.swift index fe0243c..d8345ba 100644 --- a/Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHCertificateHandler.swift +++ b/Sources/Packages/Sources/SecretKit/OpenSSH/OpenSSHCertificateHandler.swift @@ -1,7 +1,6 @@ import Foundation import OSLog import Synchronization -import Backports /// Manages storage and lookup for OpenSSH certificates. public final class OpenSSHCertificateHandler: Sendable { @@ -9,7 +8,7 @@ public final class OpenSSHCertificateHandler: Sendable { private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: NSHomeDirectory()) private let logger = Logger(subsystem: "com.maxgoedjen.secretive.secretagent", category: "OpenSSHCertificateHandler") private let writer = OpenSSHKeyWriter() - private let keyBlobsAndNames: _Mutex<[AnySecret: (Data, Data)]> = .init([:]) + private let keyBlobsAndNames: Mutex<[AnySecret: (Data, Data)]> = .init([:]) /// Initializes an OpenSSHCertificateHandler. public init() { diff --git a/Sources/Packages/Sources/SecretKit/SecretStoreList.swift b/Sources/Packages/Sources/SecretKit/SecretStoreList.swift index be01ed5..b2ef3b2 100644 --- a/Sources/Packages/Sources/SecretKit/SecretStoreList.swift +++ b/Sources/Packages/Sources/SecretKit/SecretStoreList.swift @@ -1,7 +1,6 @@ import Foundation import Observation import Synchronization -import Backports /// A "Store Store," which holds a list of type-erased stores. @Observable public final class SecretStoreList: Sendable { @@ -10,13 +9,13 @@ import Backports public var stores: [AnySecretStore] { __stores.withLock { $0 } } - private let __stores: _Mutex<[AnySecretStore]> = .init([]) + private let __stores: Mutex<[AnySecretStore]> = .init([]) /// A modifiable store, if one is available. public var modifiableStore: AnySecretStoreModifiable? { __modifiableStore.withLock { $0 } } - private let __modifiableStore: _Mutex = .init(nil) + private let __modifiableStore: Mutex = .init(nil) /// Initializes a SecretStoreList. public init() { diff --git a/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift b/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift index c37b596..371cdd5 100644 --- a/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift +++ b/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift @@ -5,7 +5,6 @@ import CryptoKit import LocalAuthentication import SecretKit import Synchronization -import Backports extension SecureEnclave { @@ -20,9 +19,9 @@ extension SecureEnclave { public var secrets: [Secret] { _secrets.withLock { $0 } } - private let _secrets: _Mutex<[Secret]> = .init([]) + private let _secrets: Mutex<[Secret]> = .init([]) - private let persistedAuthenticationContexts: _Mutex<[Secret: PersistentAuthenticationContext]> = .init([:]) + private let persistedAuthenticationContexts: Mutex<[Secret: PersistentAuthenticationContext]> = .init([:]) /// Initializes a Store. public init() { @@ -106,7 +105,7 @@ extension SecureEnclave { } public func sign(data: Data, with secret: Secret, for provenance: SigningRequestProvenance) throws -> Data { - let context: _Mutex + let context: Mutex // if let existing = persistedAuthenticationContexts.withLock({ $0 })[secret], existing.valid { // context = existing.context // } else { diff --git a/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift b/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift index d561605..199e4cd 100644 --- a/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift +++ b/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift @@ -5,7 +5,6 @@ import Security import CryptoTokenKit import LocalAuthentication import SecretKit -import Backports extension SmartCard { @@ -20,7 +19,7 @@ extension SmartCard { /// An implementation of Store backed by a Smart Card. @Observable public final class Store: SecretStore { - private let state: _Mutex = .init(.init()) + private let state: Mutex = .init(.init()) public var isAvailable: Bool { state.withLock { $0.isAvailable } } diff --git a/Sources/SecretAgent/Notifier.swift b/Sources/SecretAgent/Notifier.swift index ff1d147..2f0e15a 100644 --- a/Sources/SecretAgent/Notifier.swift +++ b/Sources/SecretAgent/Notifier.swift @@ -5,7 +5,6 @@ import SecretKit import SecretAgentKit import Brief import Synchronization -import Backports final class Notifier: Sendable { @@ -152,7 +151,7 @@ final class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate, Se fileprivate var pendingPersistableSecrets: [String: AnySecret] = [:] } - fileprivate let state: _Mutex = .init(.init()) + fileprivate let state: Mutex = .init(.init()) func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) { diff --git a/Sources/Secretive/Preview Content/PreviewUpdater.swift b/Sources/Secretive/Preview Content/PreviewUpdater.swift index 04c6658..6979615 100644 --- a/Sources/Secretive/Preview Content/PreviewUpdater.swift +++ b/Sources/Secretive/Preview Content/PreviewUpdater.swift @@ -2,14 +2,13 @@ import Foundation import Synchronization import Observation import Brief -import Backports @Observable class PreviewUpdater: UpdaterProtocol { var update: Release? { _update.withLock { $0 } } - let _update: _Mutex = .init(nil) + let _update: Mutex = .init(nil) let testBuild = false