From 0b1d83cdc3c05d1189523526b9795db00f9ba0f3 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Sat, 22 Feb 2025 13:42:14 -0800 Subject: [PATCH] signature: relax `Sized` requirements on rng --- signature/src/signer.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/signature/src/signer.rs b/signature/src/signer.rs index 22f2e6aa0..1ff236007 100644 --- a/signature/src/signer.rs +++ b/signature/src/signer.rs @@ -86,7 +86,7 @@ pub trait DigestSigner { #[cfg(feature = "rand_core")] pub trait RandomizedSigner { /// Sign the given message and return a digital signature - fn sign_with_rng(&self, rng: &mut R, msg: &[u8]) -> S { + fn sign_with_rng(&self, rng: &mut R, msg: &[u8]) -> S { self.try_sign_with_rng(rng, msg) .expect("signature operation failed") } @@ -96,7 +96,11 @@ pub trait RandomizedSigner { /// /// The main intended use case for signing errors is when communicating /// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens. - fn try_sign_with_rng(&self, rng: &mut R, msg: &[u8]) -> Result; + fn try_sign_with_rng( + &self, + rng: &mut R, + msg: &[u8], + ) -> Result; } /// Combination of [`DigestSigner`] and [`RandomizedSigner`] with support for @@ -106,15 +110,18 @@ pub trait RandomizedDigestSigner { /// Sign the given prehashed message `Digest`, returning a signature. /// /// Panics in the event of a signing error. - fn sign_digest_with_rng(&self, rng: &mut R, digest: D) -> S { + fn sign_digest_with_rng(&self, rng: &mut R, digest: D) -> S { self.try_sign_digest_with_rng(rng, digest) .expect("signature operation failed") } /// Attempt to sign the given prehashed message `Digest`, returning a /// digital signature on success, or an error if something went wrong. - fn try_sign_digest_with_rng(&self, rng: &mut R, digest: D) - -> Result; + fn try_sign_digest_with_rng( + &self, + rng: &mut R, + digest: D, + ) -> Result; } /// Sign the provided message bytestring using `&mut Self` (e.g. an evolving @@ -123,7 +130,7 @@ pub trait RandomizedDigestSigner { #[cfg(feature = "rand_core")] pub trait RandomizedSignerMut { /// Sign the given message, update the state, and return a digital signature. - fn sign_with_rng(&mut self, rng: &mut R, msg: &[u8]) -> S { + fn sign_with_rng(&mut self, rng: &mut R, msg: &[u8]) -> S { self.try_sign_with_rng(rng, msg) .expect("signature operation failed") } @@ -133,13 +140,21 @@ pub trait RandomizedSignerMut { /// /// Signing can fail, e.g., if the number of time periods allowed by the /// current key is exceeded. - fn try_sign_with_rng(&mut self, rng: &mut R, msg: &[u8]) -> Result; + fn try_sign_with_rng( + &mut self, + rng: &mut R, + msg: &[u8], + ) -> Result; } /// Blanket impl of [`RandomizedSignerMut`] for all [`RandomizedSigner`] types. #[cfg(feature = "rand_core")] impl> RandomizedSignerMut for T { - fn try_sign_with_rng(&mut self, rng: &mut R, msg: &[u8]) -> Result { + fn try_sign_with_rng( + &mut self, + rng: &mut R, + msg: &[u8], + ) -> Result { T::try_sign_with_rng(self, rng, msg) } }