mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-22 21:47:08 +00:00
a1009d0dac
* Add protocol requirements * Load auth settings. * Updates. * Update preview store * Add lock icon
80 lines
2.0 KiB
Swift
80 lines
2.0 KiB
Swift
import Foundation
|
|
import SecretKit
|
|
|
|
enum Preview {}
|
|
|
|
extension Preview {
|
|
|
|
struct Secret: SecretKit.Secret {
|
|
|
|
let id = UUID().uuidString
|
|
let name: String
|
|
let algorithm = Algorithm.ellipticCurve
|
|
let keySize = 256
|
|
let requiresAuthentication: Bool = false
|
|
let publicKey = UUID().uuidString.data(using: .utf8)!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
extension Preview {
|
|
|
|
class Store: SecretStore, ObservableObject {
|
|
|
|
let isAvailable = true
|
|
let id = UUID()
|
|
var name: String { "Preview Store" }
|
|
@Published var secrets: [Secret] = []
|
|
|
|
init(secrets: [Secret]) {
|
|
self.secrets.append(contentsOf: secrets)
|
|
}
|
|
|
|
init(numberOfRandomSecrets: Int = 5) {
|
|
let new = (0..<numberOfRandomSecrets).map { Secret(name: String(describing: $0)) }
|
|
self.secrets.append(contentsOf: new)
|
|
}
|
|
|
|
func sign(data: Data, with secret: Preview.Secret, for provenance: SigningRequestProvenance) throws -> Data {
|
|
return data
|
|
}
|
|
|
|
func existingPersistedAuthenticationContext(secret: Preview.Secret) -> PersistedAuthenticationContext? {
|
|
nil
|
|
}
|
|
|
|
func persistAuthentication(secret: Preview.Secret, forDuration duration: TimeInterval) throws {
|
|
}
|
|
|
|
}
|
|
|
|
class StoreModifiable: Store, SecretStoreModifiable {
|
|
override var name: String { "Modifiable Preview Store" }
|
|
|
|
func create(name: String, requiresAuthentication: Bool) throws {
|
|
}
|
|
|
|
func delete(secret: Preview.Secret) throws {
|
|
}
|
|
|
|
func update(secret: Preview.Secret, name: String) throws {
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
}
|