From 06fae85e6709056a85ea143461e457e7aa0fd233 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Fri, 13 Mar 2026 14:18:46 +0100 Subject: [PATCH] crypto: `impl Signer` based on `Keypair` Since all signers implement `signature::Keypair`, we can simplify the implementations of `signature::Signer`. A blanket implementation is not possible, because we do not control `signature::Signer`. --- crates/radicle-crypto/Cargo.toml | 2 +- crates/radicle-crypto/src/ssh/agent.rs | 5 +++-- crates/radicle-crypto/src/ssh/keystore.rs | 5 +++-- crates/radicle-crypto/src/test/signer.rs | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/radicle-crypto/Cargo.toml b/crates/radicle-crypto/Cargo.toml index b9d0a1d3..d18d61db 100644 --- a/crates/radicle-crypto/Cargo.toml +++ b/crates/radicle-crypto/Cargo.toml @@ -27,7 +27,7 @@ git-ref-format-core = { workspace = true, optional = true } radicle-ssh = { workspace = true, optional = true } schemars = { workspace = true, optional = true, features = ["derive", "std"] } serde = { workspace = true, features = ["derive", "std"] } -signature = { workspace = true } +signature = { workspace = true, features = ["std"] } sqlite = { workspace = true, features = ["bundled"], optional = true } ssh-key = { version = "0.6.3", default-features = false, features = ["std", "encryption", "getrandom"], optional = true } thiserror = { workspace = true, default-features = true } diff --git a/crates/radicle-crypto/src/ssh/agent.rs b/crates/radicle-crypto/src/ssh/agent.rs index ab73fa37..901b0e62 100644 --- a/crates/radicle-crypto/src/ssh/agent.rs +++ b/crates/radicle-crypto/src/ssh/agent.rs @@ -65,9 +65,10 @@ impl signature::Signer for AgentSigner { impl signature::Signer for AgentSigner { fn try_sign(&self, msg: &[u8]) -> Result { + use signature::Keypair as _; Ok(ExtendedSignature { - key: self.public, - sig: Signer::try_sign(self, msg).map_err(signature::Error::from_source)?, + key: self.verifying_key(), + sig: self.try_sign(msg)?, }) } } diff --git a/crates/radicle-crypto/src/ssh/keystore.rs b/crates/radicle-crypto/src/ssh/keystore.rs index 84ab0d6f..5f768647 100644 --- a/crates/radicle-crypto/src/ssh/keystore.rs +++ b/crates/radicle-crypto/src/ssh/keystore.rs @@ -258,9 +258,10 @@ impl signature::Signer for MemorySigner { impl signature::Signer for MemorySigner { fn try_sign(&self, msg: &[u8]) -> Result { + use signature::Keypair as _; Ok(ExtendedSignature { - key: self.public, - sig: Signer::sign(self, msg), + key: self.verifying_key(), + sig: self.try_sign(msg)?, }) } } diff --git a/crates/radicle-crypto/src/test/signer.rs b/crates/radicle-crypto/src/test/signer.rs index 6881699a..dd036340 100644 --- a/crates/radicle-crypto/src/test/signer.rs +++ b/crates/radicle-crypto/src/test/signer.rs @@ -10,9 +10,10 @@ pub struct MockSigner { impl signature::Signer for MockSigner { fn try_sign(&self, msg: &[u8]) -> Result { + use signature::Keypair as _; Ok(ExtendedSignature { - key: self.pk, - sig: signature::Signer::::try_sign(self, msg)?, + key: self.verifying_key(), + sig: self.try_sign(msg)?, }) } }