From f2ad54542e179e7560fc4be4842fd29b8e8e93bc Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Sun, 8 Mar 2026 09:49:32 +0100 Subject: [PATCH] crypto: `impl signature::KeypairRef` for Signers The various signers defined in `radicle-crypto` all allow borrowing the corresponding public key a.k.a. "verifying key". This is captured by implementing `signature::KeypairRef`, so implement it in addition to `signature::Signer`. --- crates/radicle-crypto/src/ssh/agent.rs | 10 ++++++++++ crates/radicle-crypto/src/ssh/keystore.rs | 10 ++++++++++ crates/radicle-crypto/src/test/signer.rs | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/crates/radicle-crypto/src/ssh/agent.rs b/crates/radicle-crypto/src/ssh/agent.rs index 05a6f956..ab73fa37 100644 --- a/crates/radicle-crypto/src/ssh/agent.rs +++ b/crates/radicle-crypto/src/ssh/agent.rs @@ -72,6 +72,16 @@ impl signature::Signer for AgentSigner { } } +impl AsRef for AgentSigner { + fn as_ref(&self) -> &PublicKey { + &self.public + } +} + +impl signature::KeypairRef for AgentSigner { + type VerifyingKey = PublicKey; +} + impl AgentSigner { pub fn new(agent: Agent, public: PublicKey) -> Self { let agent = RefCell::new(agent); diff --git a/crates/radicle-crypto/src/ssh/keystore.rs b/crates/radicle-crypto/src/ssh/keystore.rs index 49d241ec..84ab0d6f 100644 --- a/crates/radicle-crypto/src/ssh/keystore.rs +++ b/crates/radicle-crypto/src/ssh/keystore.rs @@ -265,6 +265,16 @@ impl signature::Signer for MemorySigner { } } +impl AsRef for MemorySigner { + fn as_ref(&self) -> &PublicKey { + &self.public + } +} + +impl signature::KeypairRef for MemorySigner { + type VerifyingKey = PublicKey; +} + impl Signer for MemorySigner { fn public_key(&self) -> &PublicKey { &self.public diff --git a/crates/radicle-crypto/src/test/signer.rs b/crates/radicle-crypto/src/test/signer.rs index 76c1fb2b..6881699a 100644 --- a/crates/radicle-crypto/src/test/signer.rs +++ b/crates/radicle-crypto/src/test/signer.rs @@ -23,6 +23,16 @@ impl signature::Signer for MockSigner { } } +impl AsRef for MockSigner { + fn as_ref(&self) -> &PublicKey { + &self.pk + } +} + +impl signature::KeypairRef for MockSigner { + type VerifyingKey = PublicKey; +} + impl MockSigner { pub fn new(rng: &mut fastrand::Rng) -> Self { let mut seed: [u8; 32] = [0; 32];