This commit is contained in:
Max Goedjen 2025-01-04 23:16:47 -08:00
parent c09ad3ecc1
commit e332b7cb9d
No known key found for this signature in database
4 changed files with 9 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import Combine
/// Type eraser for SecretStore. /// Type eraser for SecretStore.
public class AnySecretStore: SecretStore, @unchecked Sendable { public class AnySecretStore: SecretStore, @unchecked Sendable {
let base: Any
private let _isAvailable: @Sendable () -> Bool private let _isAvailable: @Sendable () -> Bool
private let _id: @Sendable () -> UUID private let _id: @Sendable () -> UUID
private let _name: @Sendable () -> String private let _name: @Sendable () -> String
@ -15,6 +16,7 @@ public class AnySecretStore: SecretStore, @unchecked Sendable {
private let _reloadSecrets: @Sendable () async -> Void private let _reloadSecrets: @Sendable () async -> Void
public init<SecretStoreType>(_ secretStore: SecretStoreType) where SecretStoreType: SecretStore { public init<SecretStoreType>(_ secretStore: SecretStoreType) where SecretStoreType: SecretStore {
base = secretStore
_isAvailable = { secretStore.isAvailable } _isAvailable = { secretStore.isAvailable }
_name = { secretStore.name } _name = { secretStore.name }
_id = { secretStore.id } _id = { secretStore.id }

View File

@ -35,7 +35,7 @@ class AgentTests: XCTestCase {
// XCTAssertEqual(stubWriter.data, Constants.Responses.requestFailure) // XCTAssertEqual(stubWriter.data, Constants.Responses.requestFailure)
} }
func testSignature() async { func testSignature() async throws {
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature) let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
let requestReader = OpenSSHReader(data: Constants.Requests.requestSignature[5...]) let requestReader = OpenSSHReader(data: Constants.Requests.requestSignature[5...])
_ = requestReader.readNextChunk() _ = requestReader.readNextChunk()
@ -63,10 +63,10 @@ class AgentTests: XCTestCase {
let signature = try! P256.Signing.ECDSASignature(rawRepresentation: rs) let signature = try! P256.Signing.ECDSASignature(rawRepresentation: rs)
let referenceValid = try! P256.Signing.PublicKey(x963Representation: Constants.Secrets.ecdsa256Secret.publicKey).isValidSignature(signature, for: dataToSign) let referenceValid = try! P256.Signing.PublicKey(x963Representation: Constants.Secrets.ecdsa256Secret.publicKey).isValidSignature(signature, for: dataToSign)
let store = list.stores.first! let store = list.stores.first!
let derVerifies = try! store.verify(signature: signature.derRepresentation, for: dataToSign, with: AnySecret(Constants.Secrets.ecdsa256Secret)) let derVerifies = try await store.verify(signature: signature.derRepresentation, for: dataToSign, with: AnySecret(Constants.Secrets.ecdsa256Secret))
let invalidRandomSignature = try? store.verify(signature: "invalid".data(using: .utf8)!, for: dataToSign, with: AnySecret(Constants.Secrets.ecdsa256Secret)) let invalidRandomSignature = try await store.verify(signature: "invalid".data(using: .utf8)!, for: dataToSign, with: AnySecret(Constants.Secrets.ecdsa256Secret))
let invalidRandomData = try? store.verify(signature: signature.derRepresentation, for: "invalid".data(using: .utf8)!, with: AnySecret(Constants.Secrets.ecdsa256Secret)) let invalidRandomData = try await store.verify(signature: signature.derRepresentation, for: "invalid".data(using: .utf8)!, with: AnySecret(Constants.Secrets.ecdsa256Secret))
let invalidWrongKey = try? store.verify(signature: signature.derRepresentation, for: dataToSign, with: AnySecret(Constants.Secrets.ecdsa384Secret)) let invalidWrongKey = try await store.verify(signature: signature.derRepresentation, for: dataToSign, with: AnySecret(Constants.Secrets.ecdsa384Secret))
XCTAssertTrue(referenceValid) XCTAssertTrue(referenceValid)
XCTAssertTrue(derVerifies) XCTAssertTrue(derVerifies)
XCTAssert(invalidRandomSignature == false) XCTAssert(invalidRandomSignature == false)

View File

@ -1,7 +1,7 @@
import Foundation import Foundation
import SecretAgentKit import SecretAgentKit
class StubFileHandleWriter: FileHandleWriter { class StubFileHandleWriter: FileHandleWriter, @unchecked Sendable {
var data = Data() var data = Data()

View File

@ -6,7 +6,7 @@ struct Stub {}
extension Stub { extension Stub {
public final class Store: SecretStore { public final class Store: SecretStore, @unchecked Sendable {
public let isAvailable = true public let isAvailable = true
public let id = UUID() public let id = UUID()