mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-06 01:37:22 +01:00
Allow limited key validity window for authenticated keys (#252)
This commit is contained in:
@@ -8,7 +8,9 @@ public class AnySecretStore: SecretStore {
|
||||
private let _id: () -> UUID
|
||||
private let _name: () -> String
|
||||
private let _secrets: () -> [AnySecret]
|
||||
private let _sign: (Data, AnySecret, SigningRequestProvenance) throws -> Data
|
||||
private let _sign: (Data, AnySecret, SigningRequestProvenance) throws -> SignedData
|
||||
private let _persistAuthentication: (AnySecret, TimeInterval) throws -> Void
|
||||
|
||||
private var sink: AnyCancellable?
|
||||
|
||||
public init<SecretStoreType>(_ secretStore: SecretStoreType) where SecretStoreType: SecretStore {
|
||||
@@ -18,6 +20,7 @@ public class AnySecretStore: SecretStore {
|
||||
_id = { secretStore.id }
|
||||
_secrets = { secretStore.secrets.map { AnySecret($0) } }
|
||||
_sign = { try secretStore.sign(data: $0, with: $1.base as! SecretStoreType.SecretType, for: $2) }
|
||||
_persistAuthentication = { try secretStore.persistAuthentication(secret: $0.base as! SecretStoreType.SecretType, forDuration: $1) }
|
||||
sink = secretStore.objectWillChange.sink { _ in
|
||||
self.objectWillChange.send()
|
||||
}
|
||||
@@ -39,10 +42,14 @@ public class AnySecretStore: SecretStore {
|
||||
return _secrets()
|
||||
}
|
||||
|
||||
public func sign(data: Data, with secret: AnySecret, for provenance: SigningRequestProvenance) throws -> Data {
|
||||
public func sign(data: Data, with secret: AnySecret, for provenance: SigningRequestProvenance) throws -> SignedData {
|
||||
try _sign(data, secret, provenance)
|
||||
}
|
||||
|
||||
public func persistAuthentication(secret: AnySecret, forDuration duration: TimeInterval) throws {
|
||||
try _persistAuthentication(secret, duration)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AnySecretStoreModifiable: AnySecretStore, SecretStoreModifiable {
|
||||
@@ -69,4 +76,5 @@ public class AnySecretStoreModifiable: AnySecretStore, SecretStoreModifiable {
|
||||
public func update(secret: AnySecret, name: String) throws {
|
||||
try _update(secret, name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ public protocol SecretStore: ObservableObject, Identifiable {
|
||||
var name: String { get }
|
||||
var secrets: [SecretType] { get }
|
||||
|
||||
func sign(data: Data, with secret: SecretType, for provenance: SigningRequestProvenance) throws -> Data
|
||||
func sign(data: Data, with secret: SecretType, for provenance: SigningRequestProvenance) throws -> SignedData
|
||||
|
||||
func persistAuthentication(secret: SecretType, forDuration duration: TimeInterval) throws
|
||||
|
||||
}
|
||||
|
||||
|
||||
13
SecretKit/Common/Types/SignedData.swift
Normal file
13
SecretKit/Common/Types/SignedData.swift
Normal file
@@ -0,0 +1,13 @@
|
||||
import Foundation
|
||||
|
||||
public struct SignedData {
|
||||
|
||||
public let data: Data
|
||||
public let requiredAuthentication: Bool
|
||||
|
||||
public init(data: Data, requiredAuthentication: Bool) {
|
||||
self.data = data
|
||||
self.requiredAuthentication = requiredAuthentication
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user