mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-08-31 01:20:57 +00:00
Merge branch 'main' into filehandle_session
This commit is contained in:
commit
ca18ee0333
@ -61,13 +61,13 @@ open class AnySecretStore: SecretStore, @unchecked Sendable {
|
|||||||
|
|
||||||
public final class AnySecretStoreModifiable: AnySecretStore, SecretStoreModifiable, @unchecked Sendable {
|
public final class AnySecretStoreModifiable: AnySecretStore, SecretStoreModifiable, @unchecked Sendable {
|
||||||
|
|
||||||
private let _create: @Sendable (String, Attributes) async throws -> SecretType
|
private let _create: @Sendable (String, Attributes) async throws -> AnySecret
|
||||||
private let _delete: @Sendable (AnySecret) async throws -> Void
|
private let _delete: @Sendable (AnySecret) async throws -> Void
|
||||||
private let _update: @Sendable (AnySecret, String, Attributes) async throws -> Void
|
private let _update: @Sendable (AnySecret, String, Attributes) async throws -> Void
|
||||||
private let _supportedKeyTypes: @Sendable () -> [KeyType]
|
private let _supportedKeyTypes: @Sendable () -> [KeyType]
|
||||||
|
|
||||||
public init<SecretStoreType>(_ secretStore: SecretStoreType) where SecretStoreType: SecretStoreModifiable {
|
public init<SecretStoreType>(_ secretStore: SecretStoreType) where SecretStoreType: SecretStoreModifiable {
|
||||||
_create = { try await secretStore.create(name: $0, attributes: $1) as! SecretType }
|
_create = { AnySecret(try await secretStore.create(name: $0, attributes: $1)) }
|
||||||
_delete = { try await secretStore.delete(secret: $0.base as! SecretStoreType.SecretType) }
|
_delete = { try await secretStore.delete(secret: $0.base as! SecretStoreType.SecretType) }
|
||||||
_update = { try await secretStore.update(secret: $0.base as! SecretStoreType.SecretType, name: $1, attributes: $2) }
|
_update = { try await secretStore.update(secret: $0.base as! SecretStoreType.SecretType, name: $1, attributes: $2) }
|
||||||
_supportedKeyTypes = { secretStore.supportedKeyTypes }
|
_supportedKeyTypes = { secretStore.supportedKeyTypes }
|
||||||
|
@ -23,7 +23,11 @@ extension SecureEnclave {
|
|||||||
@MainActor public init() {
|
@MainActor public init() {
|
||||||
loadSecrets()
|
loadSecrets()
|
||||||
Task {
|
Task {
|
||||||
for await _ in DistributedNotificationCenter.default().notifications(named: .secretStoreUpdated) {
|
for await note in DistributedNotificationCenter.default().notifications(named: .secretStoreUpdated) {
|
||||||
|
guard Constants.notificationToken != (note.object as? String) else {
|
||||||
|
// Don't reload if we're the ones triggering this by reloading.
|
||||||
|
return
|
||||||
|
}
|
||||||
reloadSecrets()
|
reloadSecrets()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +97,13 @@ extension SecureEnclave {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@MainActor public func reloadSecrets() {
|
@MainActor public func reloadSecrets() {
|
||||||
reloadSecretsInternal(notifyAgent: false)
|
let before = secrets
|
||||||
|
secrets.removeAll()
|
||||||
|
loadSecrets()
|
||||||
|
if secrets != before {
|
||||||
|
NotificationCenter.default.post(name: .secretStoreReloaded, object: self)
|
||||||
|
DistributedNotificationCenter.default().postNotificationName(.secretStoreUpdated, object: Constants.notificationToken, deliverImmediately: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: SecretStoreModifiable
|
// MARK: SecretStoreModifiable
|
||||||
@ -194,18 +204,6 @@ extension SecureEnclave {
|
|||||||
|
|
||||||
extension SecureEnclave.Store {
|
extension SecureEnclave.Store {
|
||||||
|
|
||||||
@MainActor private func reloadSecretsInternal(notifyAgent: Bool = true) {
|
|
||||||
let before = secrets
|
|
||||||
secrets.removeAll()
|
|
||||||
loadSecrets()
|
|
||||||
if secrets != before {
|
|
||||||
NotificationCenter.default.post(name: .secretStoreReloaded, object: self)
|
|
||||||
if notifyAgent {
|
|
||||||
DistributedNotificationCenter.default().postNotificationName(.secretStoreUpdated, object: nil, deliverImmediately: true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Loads all secrets from the store.
|
/// Loads all secrets from the store.
|
||||||
@MainActor private func loadSecrets() {
|
@MainActor private func loadSecrets() {
|
||||||
let queryAttributes = KeychainDictionary([
|
let queryAttributes = KeychainDictionary([
|
||||||
@ -286,6 +284,7 @@ extension SecureEnclave.Store {
|
|||||||
enum Constants {
|
enum Constants {
|
||||||
static let keyClass = kSecClassGenericPassword as String
|
static let keyClass = kSecClassGenericPassword as String
|
||||||
static let keyTag = Data("com.maxgoedjen.secretive.secureenclave.key".utf8)
|
static let keyTag = Data("com.maxgoedjen.secretive.secureenclave.key".utf8)
|
||||||
|
static let notificationToken = UUID().uuidString
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UnsupportedAlgorithmError: Error {}
|
struct UnsupportedAlgorithmError: Error {}
|
||||||
|
@ -96,7 +96,8 @@ extension Preview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func create(name: String, attributes: Attributes) throws {
|
func create(name: String, attributes: Attributes) throws -> Secret {
|
||||||
|
fatalError()
|
||||||
}
|
}
|
||||||
|
|
||||||
func delete(secret: Preview.Secret) throws {
|
func delete(secret: Preview.Secret) throws {
|
||||||
|
Loading…
Reference in New Issue
Block a user