Skip to content

Commit

Permalink
Base
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgoedjen committed Jan 5, 2025
1 parent c09ad3e commit e332b7c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Combine
/// Type eraser for SecretStore.
public class AnySecretStore: SecretStore, @unchecked Sendable {

let base: Any
private let _isAvailable: @Sendable () -> Bool
private let _id: @Sendable () -> UUID
private let _name: @Sendable () -> String
Expand All @@ -15,6 +16,7 @@ public class AnySecretStore: SecretStore, @unchecked Sendable {
private let _reloadSecrets: @Sendable () async -> Void

public init<SecretStoreType>(_ secretStore: SecretStoreType) where SecretStoreType: SecretStore {
base = secretStore
_isAvailable = { secretStore.isAvailable }
_name = { secretStore.name }
_id = { secretStore.id }
Expand Down
10 changes: 5 additions & 5 deletions Sources/Packages/Tests/SecretAgentKitTests/AgentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AgentTests: XCTestCase {
// XCTAssertEqual(stubWriter.data, Constants.Responses.requestFailure)
}

func testSignature() async {
func testSignature() async throws {
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
let requestReader = OpenSSHReader(data: Constants.Requests.requestSignature[5...])
_ = requestReader.readNextChunk()
Expand Down Expand Up @@ -63,10 +63,10 @@ class AgentTests: XCTestCase {
let signature = try! P256.Signing.ECDSASignature(rawRepresentation: rs)
let referenceValid = try! P256.Signing.PublicKey(x963Representation: Constants.Secrets.ecdsa256Secret.publicKey).isValidSignature(signature, for: dataToSign)
let store = list.stores.first!
let derVerifies = try! 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 invalidRandomData = try? 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 derVerifies = try await store.verify(signature: signature.derRepresentation, 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 await store.verify(signature: signature.derRepresentation, for: "invalid".data(using: .utf8)!, with: AnySecret(Constants.Secrets.ecdsa256Secret))
let invalidWrongKey = try await store.verify(signature: signature.derRepresentation, for: dataToSign, with: AnySecret(Constants.Secrets.ecdsa384Secret))
XCTAssertTrue(referenceValid)
XCTAssertTrue(derVerifies)
XCTAssert(invalidRandomSignature == false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SecretAgentKit

class StubFileHandleWriter: FileHandleWriter {
class StubFileHandleWriter: FileHandleWriter, @unchecked Sendable {

var data = Data()

Expand Down
2 changes: 1 addition & 1 deletion Sources/Packages/Tests/SecretAgentKitTests/StubStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct Stub {}

extension Stub {

public final class Store: SecretStore {
public final class Store: SecretStore, @unchecked Sendable {

public let isAvailable = true
public let id = UUID()
Expand Down

0 comments on commit e332b7c

Please sign in to comment.