This commit is contained in:
Max Goedjen
2025-09-06 14:54:03 -07:00
parent 2994861f45
commit 30bb29d153
7 changed files with 240 additions and 245 deletions

View File

@@ -34,9 +34,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
logger.debug("SecretAgent finished launching")
Task {
let inputParser = try XPCAgentInputParser()
for await session in socketController.sessions {
Task {
let inputParser = SSHAgentInputParser()
do {
for await message in session.messages {
let request = try await inputParser.parse(data: message)

View File

@@ -1,10 +1,41 @@
import Foundation
import SecretAgentKit
struct XPCAgentInputParser: SSHAgentInputParserProtocol {
public final class XPCAgentInputParser: SSHAgentInputParserProtocol {
func parse(data: Data) async throws -> SSHAgent.Request {
fatalError()
private let session: XPCSession
public init() throws {
if #available(macOS 26.0, *) {
session = try XPCSession(xpcService: "com.maxgoedjen.Secretive.AgentRequestParser", requirement: .isFromSameTeam())
} else {
session = try XPCSession(xpcService: "com.maxgoedjen.Secretive.AgentRequestParser")
}
}
public func parse(data: Data) async throws -> SSHAgent.Request {
try await withCheckedThrowingContinuation { continuation in
do {
try session.send(data) { result in
switch result {
case .success(let result):
do {
continuation.resume(returning: try result.decode(as: SSHAgent.Request.self))
} catch {
continuation.resume(throwing: error)
}
case .failure(let error):
continuation.resume(throwing: error)
}
}
} catch {
continuation.resume(throwing: error)
}
}
}
deinit {
session.cancel(reason: "Done")
}
}