From 9e3f5ec97faf6a96c0bad7756402c940db240066 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sun, 1 Jun 2025 08:37:53 +0200 Subject: [PATCH 1/5] `signature`: use `&[&[u8]]` for messages --- async-signature/tests/mock_impl.rs | 4 ++-- signature/src/signer.rs | 30 +++++++++++++++--------------- signature/src/verifier.rs | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/async-signature/tests/mock_impl.rs b/async-signature/tests/mock_impl.rs index d8e17ea45..ef6d3d597 100644 --- a/async-signature/tests/mock_impl.rs +++ b/async-signature/tests/mock_impl.rs @@ -11,7 +11,7 @@ struct Signature; struct MockSigner; impl AsyncSigner for MockSigner { - async fn sign_async(&self, _msg: &[u8]) -> Result { + async fn sign_async(&self, _msg: &[&[u8]]) -> Result { unimplemented!("just meant to check compilation") } } @@ -33,7 +33,7 @@ impl async_signature::AsyncRandomizedSigner for MockSigner { >( &self, _rng: &mut R, - _msg: &[u8], + _msg: &[&[u8]], ) -> Result { unimplemented!("just meant to check compilation") } diff --git a/signature/src/signer.rs b/signature/src/signer.rs index 02ffe0f9c..094beb82d 100644 --- a/signature/src/signer.rs +++ b/signature/src/signer.rs @@ -12,7 +12,7 @@ use crate::rand_core::{CryptoRng, TryCryptoRng}; /// or connection to an HSM), returning a digital signature. pub trait Signer { /// Sign the given message and return a digital signature - fn sign(&self, msg: &[u8]) -> S { + fn sign(&self, msg: &[&[u8]]) -> S { self.try_sign(msg).expect("signature operation failed") } @@ -21,7 +21,7 @@ pub trait Signer { /// /// 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(&self, msg: &[u8]) -> Result; + fn try_sign(&self, msg: &[&[u8]]) -> Result; } /// Sign the provided message bytestring using `&mut Self` (e.g. an evolving @@ -29,7 +29,7 @@ pub trait Signer { /// digital signature. pub trait SignerMut { /// Sign the given message, update the state, and return a digital signature. - fn sign(&mut self, msg: &[u8]) -> S { + fn sign(&mut self, msg: &[&[u8]]) -> S { self.try_sign(msg).expect("signature operation failed") } @@ -38,12 +38,12 @@ pub trait SignerMut { /// /// Signing can fail, e.g., if the number of time periods allowed by the /// current key is exceeded. - fn try_sign(&mut self, msg: &[u8]) -> Result; + fn try_sign(&mut self, msg: &[&[u8]]) -> Result; } /// Blanket impl of [`SignerMut`] for all [`Signer`] types. impl> SignerMut for T { - fn try_sign(&mut self, msg: &[u8]) -> Result { + fn try_sign(&mut self, msg: &[&[u8]]) -> Result { T::try_sign(self, msg) } } @@ -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") } @@ -99,7 +99,7 @@ pub trait RandomizedSigner { fn try_sign_with_rng( &self, rng: &mut R, - msg: &[u8], + msg: &[&[u8]], ) -> Result; } @@ -130,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") } @@ -143,7 +143,7 @@ pub trait RandomizedSignerMut { fn try_sign_with_rng( &mut self, rng: &mut R, - msg: &[u8], + msg: &[&[u8]], ) -> Result; } @@ -153,7 +153,7 @@ impl> RandomizedSignerMut for T { fn try_sign_with_rng( &mut self, rng: &mut R, - msg: &[u8], + msg: &[&[u8]], ) -> Result { T::try_sign_with_rng(self, rng, msg) } @@ -169,14 +169,14 @@ pub trait AsyncSigner { /// /// The main intended use case for signing errors is when communicating /// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens. - async fn sign_async(&self, msg: &[u8]) -> Result; + async fn sign_async(&self, msg: &[&[u8]]) -> Result; } impl AsyncSigner for T where T: Signer, { - async fn sign_async(&self, msg: &[u8]) -> Result { + async fn sign_async(&self, msg: &[&[u8]]) -> Result { self.try_sign(msg) } } @@ -198,7 +198,7 @@ where #[cfg(feature = "rand_core")] pub trait AsyncRandomizedSigner { /// Sign the given message and return a digital signature - async fn sign_with_rng_async(&self, rng: &mut R, msg: &[u8]) -> S { + async fn sign_with_rng_async(&self, rng: &mut R, msg: &[&[u8]]) -> S { self.try_sign_with_rng_async(rng, msg) .await .expect("signature operation failed") @@ -212,7 +212,7 @@ pub trait AsyncRandomizedSigner { async fn try_sign_with_rng_async( &self, rng: &mut R, - msg: &[u8], + msg: &[&[u8]], ) -> Result; } @@ -224,7 +224,7 @@ where async fn try_sign_with_rng_async( &self, rng: &mut R, - msg: &[u8], + msg: &[&[u8]], ) -> Result { self.try_sign_with_rng(rng, msg) } diff --git a/signature/src/verifier.rs b/signature/src/verifier.rs index 65409a929..7954b6a36 100644 --- a/signature/src/verifier.rs +++ b/signature/src/verifier.rs @@ -11,7 +11,7 @@ pub trait Verifier { /// bytestring is authentic. /// /// Returns `Error` if it is inauthentic, or otherwise returns `()`. - fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error>; + fn verify(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error>; } /// Verify the provided signature for the given prehashed message [`Digest`] From 93906b08aee79105c88e17227f174ad03c0c88c5 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sun, 1 Jun 2025 20:02:53 +0200 Subject: [PATCH 2/5] Move into separate `MultiPart*` trait --- async-signature/tests/mock_impl.rs | 4 +- signature/src/signer.rs | 106 +++++++++++++++++++++++++---- signature/src/verifier.rs | 6 ++ 3 files changed, 101 insertions(+), 15 deletions(-) diff --git a/async-signature/tests/mock_impl.rs b/async-signature/tests/mock_impl.rs index ef6d3d597..d8e17ea45 100644 --- a/async-signature/tests/mock_impl.rs +++ b/async-signature/tests/mock_impl.rs @@ -11,7 +11,7 @@ struct Signature; struct MockSigner; impl AsyncSigner for MockSigner { - async fn sign_async(&self, _msg: &[&[u8]]) -> Result { + async fn sign_async(&self, _msg: &[u8]) -> Result { unimplemented!("just meant to check compilation") } } @@ -33,7 +33,7 @@ impl async_signature::AsyncRandomizedSigner for MockSigner { >( &self, _rng: &mut R, - _msg: &[&[u8]], + _msg: &[u8], ) -> Result { unimplemented!("just meant to check compilation") } diff --git a/signature/src/signer.rs b/signature/src/signer.rs index 094beb82d..bf6cb1cd2 100644 --- a/signature/src/signer.rs +++ b/signature/src/signer.rs @@ -12,7 +12,7 @@ use crate::rand_core::{CryptoRng, TryCryptoRng}; /// or connection to an HSM), returning a digital signature. pub trait Signer { /// Sign the given message and return a digital signature - fn sign(&self, msg: &[&[u8]]) -> S { + fn sign(&self, msg: &[u8]) -> S { self.try_sign(msg).expect("signature operation failed") } @@ -21,6 +21,17 @@ pub trait Signer { /// /// 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(&self, msg: &[u8]) -> Result; +} + +/// Equivalent of [`Signer`] but the message is provided in non-contiguous byte slices. +pub trait MultiPartSigner { + /// See [`Signer::sign()`]. + fn sign(&self, msg: &[&[u8]]) -> S { + self.try_sign(msg).expect("signature operation failed") + } + + /// See [`Signer::try_sign()`]. fn try_sign(&self, msg: &[&[u8]]) -> Result; } @@ -29,7 +40,7 @@ pub trait Signer { /// digital signature. pub trait SignerMut { /// Sign the given message, update the state, and return a digital signature. - fn sign(&mut self, msg: &[&[u8]]) -> S { + fn sign(&mut self, msg: &[u8]) -> S { self.try_sign(msg).expect("signature operation failed") } @@ -38,16 +49,27 @@ pub trait SignerMut { /// /// Signing can fail, e.g., if the number of time periods allowed by the /// current key is exceeded. - fn try_sign(&mut self, msg: &[&[u8]]) -> Result; + fn try_sign(&mut self, msg: &[u8]) -> Result; } /// Blanket impl of [`SignerMut`] for all [`Signer`] types. impl> SignerMut for T { - fn try_sign(&mut self, msg: &[&[u8]]) -> Result { + fn try_sign(&mut self, msg: &[u8]) -> Result { T::try_sign(self, msg) } } +/// Equivalent of [`SignerMut`] but the message is provided in non-contiguous byte slices. +pub trait MultiPartSignerMut { + /// See [`SignerMut::sign()`]. + fn sign(&mut self, msg: &[&[u8]]) -> S { + self.try_sign(msg).expect("signature operation failed") + } + + /// See [`SignerMut::try_sign()`]. + fn try_sign(&mut self, msg: &[&[u8]]) -> Result; +} + /// Sign the given prehashed message [`Digest`] using `Self`. /// /// ## Notes @@ -86,7 +108,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,6 +118,23 @@ 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; +} + +/// Equivalent of [`RandomizedSigner`] but the message is provided in non-contiguous byte slices. +#[cfg(feature = "rand_core")] +pub trait RandomizedMultiPartSigner { + /// See [`RandomizedSigner::sign_with_rng()`]. + fn sign_with_rng(&self, rng: &mut R, msg: &[&[u8]]) -> S { + self.try_sign_with_rng(rng, msg) + .expect("signature operation failed") + } + + /// See [`RandomizedSigner::try_sign_with_rng()`]. fn try_sign_with_rng( &self, rng: &mut R, @@ -130,7 +169,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") } @@ -143,7 +182,7 @@ pub trait RandomizedSignerMut { fn try_sign_with_rng( &mut self, rng: &mut R, - msg: &[&[u8]], + msg: &[u8], ) -> Result; } @@ -153,12 +192,29 @@ impl> RandomizedSignerMut for T { fn try_sign_with_rng( &mut self, rng: &mut R, - msg: &[&[u8]], + msg: &[u8], ) -> Result { T::try_sign_with_rng(self, rng, msg) } } +/// Equivalent of [`RandomizedSignerMut`] but the message is provided in non-contiguous byte slices. +#[cfg(feature = "rand_core")] +pub trait RandomizedMultiPartSignerMut { + /// See [`RandomizedSignerMut::sign_with_rng()`]. + fn sign_with_rng(&mut self, rng: &mut R, msg: &[u8]) -> S { + self.try_sign_with_rng(rng, msg) + .expect("signature operation failed") + } + + /// See [`RandomizedSignerMut::try_sign_with_rng()`]. + fn try_sign_with_rng( + &mut self, + rng: &mut R, + msg: &[u8], + ) -> Result; +} + /// Asynchronously sign the provided message bytestring using `Self` /// (e.g. client for a Cloud KMS or HSM), returning a digital signature. /// @@ -169,18 +225,24 @@ pub trait AsyncSigner { /// /// The main intended use case for signing errors is when communicating /// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens. - async fn sign_async(&self, msg: &[&[u8]]) -> Result; + async fn sign_async(&self, msg: &[u8]) -> Result; } impl AsyncSigner for T where T: Signer, { - async fn sign_async(&self, msg: &[&[u8]]) -> Result { + async fn sign_async(&self, msg: &[u8]) -> Result { self.try_sign(msg) } } +/// Equivalent of [`AsyncSigner`] but the message is provided in non-contiguous byte slices. +pub trait AsyncMultiPartSigner { + /// See [`AsyncSigner::sign_async()`]. + async fn sign_async(&self, msg: &[&[u8]]) -> Result; +} + /// Asynchronously sign the given prehashed message [`Digest`] using `Self`. /// /// This trait is an async equivalent of the [`DigestSigner`] trait. @@ -198,7 +260,7 @@ where #[cfg(feature = "rand_core")] pub trait AsyncRandomizedSigner { /// Sign the given message and return a digital signature - async fn sign_with_rng_async(&self, rng: &mut R, msg: &[&[u8]]) -> S { + async fn sign_with_rng_async(&self, rng: &mut R, msg: &[u8]) -> S { self.try_sign_with_rng_async(rng, msg) .await .expect("signature operation failed") @@ -212,7 +274,7 @@ pub trait AsyncRandomizedSigner { async fn try_sign_with_rng_async( &self, rng: &mut R, - msg: &[&[u8]], + msg: &[u8], ) -> Result; } @@ -224,8 +286,26 @@ where async fn try_sign_with_rng_async( &self, rng: &mut R, - msg: &[&[u8]], + msg: &[u8], ) -> Result { self.try_sign_with_rng(rng, msg) } } + +/// Equivalent of [`AsyncRandomizedSigner`] but the message is provided in non-contiguous byte slices. +#[cfg(feature = "rand_core")] +pub trait AsyncRandomizedMultiPartSigner { + /// See [`AsyncRandomizedSigner::sign_with_rng_async()`]. + async fn sign_with_rng_async(&self, rng: &mut R, msg: &[&[u8]]) -> S { + self.try_sign_with_rng_async(rng, msg) + .await + .expect("signature operation failed") + } + + /// See [`AsyncRandomizedSigner::try_sign_with_rng_async()`]. + async fn try_sign_with_rng_async( + &self, + rng: &mut R, + msg: &[&[u8]], + ) -> Result; +} diff --git a/signature/src/verifier.rs b/signature/src/verifier.rs index 7954b6a36..bb3fcac7a 100644 --- a/signature/src/verifier.rs +++ b/signature/src/verifier.rs @@ -11,6 +11,12 @@ pub trait Verifier { /// bytestring is authentic. /// /// Returns `Error` if it is inauthentic, or otherwise returns `()`. + fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error>; +} + +/// Equivalent of [`Verifier`] but the message is provided in non-contiguous byte slices. +pub trait MultiPartVerifier { + /// See [`Verifier::verify()`]. fn verify(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error>; } From ce4a05bc4266dd1d4c7c713fb7f9c211c76375ec Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sun, 1 Jun 2025 20:35:58 +0200 Subject: [PATCH 3/5] Remove unneeded traits and add `multi_part_*` to method names --- signature/src/signer.rs | 65 +++++---------------------------------- signature/src/verifier.rs | 2 +- 2 files changed, 8 insertions(+), 59 deletions(-) diff --git a/signature/src/signer.rs b/signature/src/signer.rs index bf6cb1cd2..44cc3f2da 100644 --- a/signature/src/signer.rs +++ b/signature/src/signer.rs @@ -27,12 +27,13 @@ pub trait Signer { /// Equivalent of [`Signer`] but the message is provided in non-contiguous byte slices. pub trait MultiPartSigner { /// See [`Signer::sign()`]. - fn sign(&self, msg: &[&[u8]]) -> S { - self.try_sign(msg).expect("signature operation failed") + fn multi_part_sign(&self, msg: &[&[u8]]) -> S { + self.try_multi_part_sign(msg) + .expect("signature operation failed") } /// See [`Signer::try_sign()`]. - fn try_sign(&self, msg: &[&[u8]]) -> Result; + fn try_multi_part_sign(&self, msg: &[&[u8]]) -> Result; } /// Sign the provided message bytestring using `&mut Self` (e.g. an evolving @@ -59,17 +60,6 @@ impl> SignerMut for T { } } -/// Equivalent of [`SignerMut`] but the message is provided in non-contiguous byte slices. -pub trait MultiPartSignerMut { - /// See [`SignerMut::sign()`]. - fn sign(&mut self, msg: &[&[u8]]) -> S { - self.try_sign(msg).expect("signature operation failed") - } - - /// See [`SignerMut::try_sign()`]. - fn try_sign(&mut self, msg: &[&[u8]]) -> Result; -} - /// Sign the given prehashed message [`Digest`] using `Self`. /// /// ## Notes @@ -129,13 +119,13 @@ pub trait RandomizedSigner { #[cfg(feature = "rand_core")] pub trait RandomizedMultiPartSigner { /// See [`RandomizedSigner::sign_with_rng()`]. - fn sign_with_rng(&self, rng: &mut R, msg: &[&[u8]]) -> S { - self.try_sign_with_rng(rng, msg) + fn multi_part_sign_with_rng(&self, rng: &mut R, msg: &[&[u8]]) -> S { + self.try_multi_part_sign_with_rng(rng, msg) .expect("signature operation failed") } /// See [`RandomizedSigner::try_sign_with_rng()`]. - fn try_sign_with_rng( + fn try_multi_part_sign_with_rng( &self, rng: &mut R, msg: &[&[u8]], @@ -198,23 +188,6 @@ impl> RandomizedSignerMut for T { } } -/// Equivalent of [`RandomizedSignerMut`] but the message is provided in non-contiguous byte slices. -#[cfg(feature = "rand_core")] -pub trait RandomizedMultiPartSignerMut { - /// See [`RandomizedSignerMut::sign_with_rng()`]. - fn sign_with_rng(&mut self, rng: &mut R, msg: &[u8]) -> S { - self.try_sign_with_rng(rng, msg) - .expect("signature operation failed") - } - - /// See [`RandomizedSignerMut::try_sign_with_rng()`]. - fn try_sign_with_rng( - &mut self, - rng: &mut R, - msg: &[u8], - ) -> Result; -} - /// Asynchronously sign the provided message bytestring using `Self` /// (e.g. client for a Cloud KMS or HSM), returning a digital signature. /// @@ -237,12 +210,6 @@ where } } -/// Equivalent of [`AsyncSigner`] but the message is provided in non-contiguous byte slices. -pub trait AsyncMultiPartSigner { - /// See [`AsyncSigner::sign_async()`]. - async fn sign_async(&self, msg: &[&[u8]]) -> Result; -} - /// Asynchronously sign the given prehashed message [`Digest`] using `Self`. /// /// This trait is an async equivalent of the [`DigestSigner`] trait. @@ -291,21 +258,3 @@ where self.try_sign_with_rng(rng, msg) } } - -/// Equivalent of [`AsyncRandomizedSigner`] but the message is provided in non-contiguous byte slices. -#[cfg(feature = "rand_core")] -pub trait AsyncRandomizedMultiPartSigner { - /// See [`AsyncRandomizedSigner::sign_with_rng_async()`]. - async fn sign_with_rng_async(&self, rng: &mut R, msg: &[&[u8]]) -> S { - self.try_sign_with_rng_async(rng, msg) - .await - .expect("signature operation failed") - } - - /// See [`AsyncRandomizedSigner::try_sign_with_rng_async()`]. - async fn try_sign_with_rng_async( - &self, - rng: &mut R, - msg: &[&[u8]], - ) -> Result; -} diff --git a/signature/src/verifier.rs b/signature/src/verifier.rs index bb3fcac7a..0c0088185 100644 --- a/signature/src/verifier.rs +++ b/signature/src/verifier.rs @@ -17,7 +17,7 @@ pub trait Verifier { /// Equivalent of [`Verifier`] but the message is provided in non-contiguous byte slices. pub trait MultiPartVerifier { /// See [`Verifier::verify()`]. - fn verify(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error>; + fn multi_part_verify(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error>; } /// Verify the provided signature for the given prehashed message [`Digest`] From f05989fadee8bb73d2c278f40c7ba943b0582977 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sun, 1 Jun 2025 21:27:09 +0200 Subject: [PATCH 4/5] Address review --- signature/src/signer.rs | 28 ++++++++++++++++------------ signature/src/verifier.rs | 7 ++++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/signature/src/signer.rs b/signature/src/signer.rs index 44cc3f2da..7360d3fb8 100644 --- a/signature/src/signer.rs +++ b/signature/src/signer.rs @@ -25,15 +25,17 @@ pub trait Signer { } /// Equivalent of [`Signer`] but the message is provided in non-contiguous byte slices. -pub trait MultiPartSigner { - /// See [`Signer::sign()`]. - fn multi_part_sign(&self, msg: &[&[u8]]) -> S { - self.try_multi_part_sign(msg) +pub trait MultipartSigner { + /// Equivalent of [`Signer::sign()`] but the message + /// is provided in non-contiguous byte slices. + fn multipart_sign(&self, msg: &[&[u8]]) -> S { + self.try_multipart_sign(msg) .expect("signature operation failed") } - /// See [`Signer::try_sign()`]. - fn try_multi_part_sign(&self, msg: &[&[u8]]) -> Result; + /// Equivalent of [`Signer::try_sign()`] but the + /// message is provided in non-contiguous byte slices. + fn try_multipart_sign(&self, msg: &[&[u8]]) -> Result; } /// Sign the provided message bytestring using `&mut Self` (e.g. an evolving @@ -117,15 +119,17 @@ pub trait RandomizedSigner { /// Equivalent of [`RandomizedSigner`] but the message is provided in non-contiguous byte slices. #[cfg(feature = "rand_core")] -pub trait RandomizedMultiPartSigner { - /// See [`RandomizedSigner::sign_with_rng()`]. - fn multi_part_sign_with_rng(&self, rng: &mut R, msg: &[&[u8]]) -> S { - self.try_multi_part_sign_with_rng(rng, msg) +pub trait RandomizedMultipartSigner { + /// Equivalent of [`RandomizedSigner::sign_with_rng()`] but + /// the message is provided in non-contiguous byte slices. + fn multipart_sign_with_rng(&self, rng: &mut R, msg: &[&[u8]]) -> S { + self.try_multipart_sign_with_rng(rng, msg) .expect("signature operation failed") } - /// See [`RandomizedSigner::try_sign_with_rng()`]. - fn try_multi_part_sign_with_rng( + /// Equivalent of [`RandomizedSigner::try_sign_with_rng()`] but + /// the message is provided in non-contiguous byte slices. + fn try_multipart_sign_with_rng( &self, rng: &mut R, msg: &[&[u8]], diff --git a/signature/src/verifier.rs b/signature/src/verifier.rs index 0c0088185..7c824f72d 100644 --- a/signature/src/verifier.rs +++ b/signature/src/verifier.rs @@ -15,9 +15,10 @@ pub trait Verifier { } /// Equivalent of [`Verifier`] but the message is provided in non-contiguous byte slices. -pub trait MultiPartVerifier { - /// See [`Verifier::verify()`]. - fn multi_part_verify(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error>; +pub trait MultipartVerifier { + /// Equivalent of [`Verifier::verify()`] but the + /// message is provided in non-contiguous byte slices. + fn multipart_verify(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error>; } /// Verify the provided signature for the given prehashed message [`Digest`] From 33d3c531068dd25c9ac237bf3cdd17e399e63c81 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Mon, 2 Jun 2025 09:21:14 +0200 Subject: [PATCH 5/5] Add `RandomizedMultipartSignerMut`Split into separate method --- signature/src/signer.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/signature/src/signer.rs b/signature/src/signer.rs index 7360d3fb8..b9eec6eab 100644 --- a/signature/src/signer.rs +++ b/signature/src/signer.rs @@ -180,6 +180,25 @@ pub trait RandomizedSignerMut { ) -> Result; } +/// Equivalent of [`RandomizedSignerMut`] but the message is provided in non-contiguous byte slices. +#[cfg(feature = "rand_core")] +pub trait RandomizedMultipartSignerMut { + /// Equivalent of [`RandomizedSignerMut::sign_with_rng()`] but + /// the message is provided in non-contiguous byte slices. + fn multipart_sign_with_rng(&mut self, rng: &mut R, msg: &[&[u8]]) -> S { + self.try_multipart_sign_with_rng(rng, msg) + .expect("signature operation failed") + } + + /// Equivalent of [`RandomizedSignerMut::try_sign_with_rng()`] + /// but the message is provided in non-contiguous byte slices. + fn try_multipart_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 {