mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-04-18 05:22:11 +00:00
Extract key selection.
This commit is contained in:
parent
aa52da2c04
commit
9c0bcda47c
@ -8,6 +8,7 @@ class Agent {
|
|||||||
|
|
||||||
fileprivate let storeList: SecretStoreList
|
fileprivate let storeList: SecretStoreList
|
||||||
fileprivate let notifier: Notifier
|
fileprivate let notifier: Notifier
|
||||||
|
fileprivate let writer = OpenSSHKeyWriter()
|
||||||
|
|
||||||
public init(storeList: SecretStoreList, notifier: Notifier) {
|
public init(storeList: SecretStoreList, notifier: Notifier) {
|
||||||
os_log(.debug, "Agent is running")
|
os_log(.debug, "Agent is running")
|
||||||
@ -76,18 +77,8 @@ extension Agent {
|
|||||||
|
|
||||||
func sign(data: Data) throws -> Data {
|
func sign(data: Data) throws -> Data {
|
||||||
let reader = OpenSSHReader(data: data)
|
let reader = OpenSSHReader(data: data)
|
||||||
let writer = OpenSSHKeyWriter()
|
|
||||||
let hash = try reader.readNextChunk()
|
let hash = try reader.readNextChunk()
|
||||||
let matching = storeList.stores.compactMap { store -> (AnySecretStore, AnySecret)? in
|
guard let (store, secret) = secret(matching: hash) else {
|
||||||
let allMatching = store.secrets.filter { secret in
|
|
||||||
hash == writer.data(secret: secret)
|
|
||||||
}
|
|
||||||
if let matching = allMatching.first {
|
|
||||||
return (store, matching)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
guard let (store, secret) = matching.first else {
|
|
||||||
throw AgentError.noMatchingKey
|
throw AgentError.noMatchingKey
|
||||||
}
|
}
|
||||||
let dataToSign = try reader.readNextChunk()
|
let dataToSign = try reader.readNextChunk()
|
||||||
@ -130,6 +121,22 @@ extension Agent {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Agent {
|
||||||
|
|
||||||
|
func secret(matching hash: Data) -> (AnySecretStore, AnySecret)? {
|
||||||
|
storeList.stores.compactMap { store -> (AnySecretStore, AnySecret)? in
|
||||||
|
let allMatching = store.secrets.filter { secret in
|
||||||
|
hash == writer.data(secret: secret)
|
||||||
|
}
|
||||||
|
if let matching = allMatching.first {
|
||||||
|
return (store, matching)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}.first
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extension Agent {
|
extension Agent {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user