mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-30 05:47:24 +02:00
Cleanup of agent
This commit is contained in:
@@ -6,20 +6,20 @@ import SecretKit
|
||||
public class Agent {
|
||||
|
||||
fileprivate let storeList: SecretStoreList
|
||||
// fileprivate let notifier: Notifier
|
||||
fileprivate let witness: SigningWitness?
|
||||
fileprivate let writer = OpenSSHKeyWriter()
|
||||
|
||||
public init(storeList: SecretStoreList/*, notifier: Notifier*/) {
|
||||
public init(storeList: SecretStoreList, witness: SigningWitness? = nil) {
|
||||
os_log(.debug, "Agent is running")
|
||||
self.storeList = storeList
|
||||
// self.notifier = notifier
|
||||
self.witness = witness
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Agent {
|
||||
|
||||
public tfunc handle(fileHandle: FileHandle) {
|
||||
public func handle(fileHandle: FileHandle) {
|
||||
os_log(.debug, "Agent handling new data")
|
||||
let data = fileHandle.availableData
|
||||
guard !data.isEmpty else { return }
|
||||
@@ -78,12 +78,17 @@ extension Agent {
|
||||
let reader = OpenSSHReader(data: data)
|
||||
let hash = try reader.readNextChunk()
|
||||
guard let (store, secret) = secret(matching: hash) else {
|
||||
os_log(.debug, "Agent did not have a key matching %@", hash as NSData)
|
||||
throw AgentError.noMatchingKey
|
||||
}
|
||||
|
||||
if let witness = witness {
|
||||
try witness.witness(accessTo: secret)
|
||||
}
|
||||
|
||||
let dataToSign = try reader.readNextChunk()
|
||||
let derSignature = try store.sign(data: dataToSign, with: secret)
|
||||
// TODO: Move this
|
||||
// notifier.notify(accessTo: secret)
|
||||
|
||||
let curveData = writer.curveType(for: secret.algorithm, length: secret.keySize).data(using: .utf8)!
|
||||
|
||||
// Convert from DER formatted rep to raw (r||s)
|
||||
|
||||
8
SecretAgentKit/SigningWitness.swift
Normal file
8
SecretAgentKit/SigningWitness.swift
Normal file
@@ -0,0 +1,8 @@
|
||||
import Foundation
|
||||
import SecretKit
|
||||
|
||||
public protocol SigningWitness {
|
||||
|
||||
func witness(accessTo secret: AnySecret) throws
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user