2020-02-19 04:52:00 +00:00
|
|
|
import Foundation
|
|
|
|
import SecretKit
|
|
|
|
|
|
|
|
enum Preview {}
|
|
|
|
|
|
|
|
extension Preview {
|
|
|
|
|
|
|
|
struct Secret: SecretKit.Secret {
|
|
|
|
|
|
|
|
let id = UUID().uuidString
|
2020-03-04 07:14:38 +00:00
|
|
|
let name: String
|
2020-03-09 05:17:59 +00:00
|
|
|
let algorithm = Algorithm.ellipticCurve
|
|
|
|
let keySize = 256
|
2022-02-25 06:59:35 +00:00
|
|
|
let requiresAuthentication: Bool = false
|
2020-03-04 07:14:38 +00:00
|
|
|
let publicKey = UUID().uuidString.data(using: .utf8)!
|
2020-02-19 04:52:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Preview {
|
|
|
|
|
|
|
|
class Store: SecretStore, ObservableObject {
|
|
|
|
|
2020-03-07 23:42:40 +00:00
|
|
|
let isAvailable = true
|
2020-03-09 03:03:40 +00:00
|
|
|
let id = UUID()
|
2020-03-11 07:02:17 +00:00
|
|
|
var name: String { "Preview Store" }
|
2020-02-19 04:52:00 +00:00
|
|
|
@Published var secrets: [Secret] = []
|
|
|
|
|
|
|
|
init(secrets: [Secret]) {
|
|
|
|
self.secrets.append(contentsOf: secrets)
|
|
|
|
}
|
|
|
|
|
2020-03-11 07:02:17 +00:00
|
|
|
init(numberOfRandomSecrets: Int = 5) {
|
|
|
|
let new = (0..<numberOfRandomSecrets).map { Secret(name: String(describing: $0)) }
|
2020-02-19 04:52:00 +00:00
|
|
|
self.secrets.append(contentsOf: new)
|
|
|
|
}
|
|
|
|
|
2022-02-25 06:59:35 +00:00
|
|
|
func sign(data: Data, with secret: Preview.Secret, for provenance: SigningRequestProvenance) throws -> Data {
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2023-03-12 01:00:27 +00:00
|
|
|
func verify(signature data: Data, for signature: Data, with secret: Preview.Secret) throws -> Bool {
|
2023-03-12 00:21:09 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2022-02-25 06:59:35 +00:00
|
|
|
func existingPersistedAuthenticationContext(secret: Preview.Secret) -> PersistedAuthenticationContext? {
|
|
|
|
nil
|
2021-11-08 01:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func persistAuthentication(secret: Preview.Secret, forDuration duration: TimeInterval) throws {
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 07:16:56 +00:00
|
|
|
func reloadSecrets() {
|
|
|
|
}
|
|
|
|
|
2020-03-11 07:02:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class StoreModifiable: Store, SecretStoreModifiable {
|
|
|
|
override var name: String { "Modifiable Preview Store" }
|
|
|
|
|
|
|
|
func create(name: String, requiresAuthentication: Bool) throws {
|
|
|
|
}
|
|
|
|
|
2020-03-04 07:14:38 +00:00
|
|
|
func delete(secret: Preview.Secret) throws {
|
|
|
|
}
|
|
|
|
|
2021-06-01 06:20:38 +00:00
|
|
|
func update(secret: Preview.Secret, name: String) throws {
|
|
|
|
}
|
|
|
|
}
|
2020-03-11 07:02:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Preview {
|
|
|
|
|
|
|
|
static func storeList(stores: [Store] = [], modifiableStores: [StoreModifiable] = []) -> SecretStoreList {
|
|
|
|
let list = SecretStoreList()
|
|
|
|
for store in stores {
|
|
|
|
list.add(store: store)
|
|
|
|
}
|
|
|
|
for storeModifiable in modifiableStores {
|
|
|
|
list.add(store: storeModifiable)
|
|
|
|
}
|
|
|
|
return list
|
2020-02-19 04:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|