From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/signature/src/signer.rs | 64 +++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 41 deletions(-) (limited to 'vendor/signature/src/signer.rs') diff --git a/vendor/signature/src/signer.rs b/vendor/signature/src/signer.rs index c025711fe..b339ddf59 100644 --- a/vendor/signature/src/signer.rs +++ b/vendor/signature/src/signer.rs @@ -1,16 +1,16 @@ //! Traits for generating digital signatures -use crate::{error::Error, Signature}; +use crate::error::Error; -#[cfg(feature = "digest-preview")] +#[cfg(feature = "digest")] use crate::digest::Digest; -#[cfg(feature = "rand-preview")] -use crate::rand_core::{CryptoRng, RngCore}; +#[cfg(feature = "rand_core")] +use crate::rand_core::CryptoRngCore; /// Sign the provided message bytestring using `Self` (e.g. a cryptographic key /// or connection to an HSM), returning a digital signature. -pub trait Signer { +pub trait Signer { /// Sign the given message and return a digital signature fn sign(&self, msg: &[u8]) -> S { self.try_sign(msg).expect("signature operation failed") @@ -24,10 +24,11 @@ pub trait Signer { fn try_sign(&self, msg: &[u8]) -> Result; } -/// Sign the provided message bytestring using `&mut Self` (e.g., an evolving -/// cryptographic key), returning a digital signature. -pub trait SignerMut { - /// Sign the given message, update the state, and return a digital signature +/// Sign the provided message bytestring using `&mut Self` (e.g. an evolving +/// cryptographic key such as a stateful hash-based signature), returning a +/// digital signature. +pub trait SignerMut { + /// Sign the given message, update the state, and return a digital signature. fn sign(&mut self, msg: &[u8]) -> S { self.try_sign(msg).expect("signature operation failed") } @@ -40,12 +41,8 @@ pub trait SignerMut { fn try_sign(&mut self, msg: &[u8]) -> Result; } -// Blanket impl of SignerMut for all Signer types -impl SignerMut for T -where - T: Signer, - S: Signature, -{ +/// Blanket impl of [`SignerMut`] for all [`Signer`] types. +impl> SignerMut for T { fn try_sign(&mut self, msg: &[u8]) -> Result { T::try_sign(self, msg) } @@ -70,13 +67,8 @@ where /// API accepts a [`Digest`] instance, rather than a raw digest value. /// /// [Fiat-Shamir heuristic]: https://en.wikipedia.org/wiki/Fiat%E2%80%93Shamir_heuristic -#[cfg(feature = "digest-preview")] -#[cfg_attr(docsrs, doc(cfg(feature = "digest-preview")))] -pub trait DigestSigner -where - D: Digest, - S: Signature, -{ +#[cfg(feature = "digest")] +pub trait DigestSigner { /// Sign the given prehashed message [`Digest`], returning a signature. /// /// Panics in the event of a signing error. @@ -91,11 +83,10 @@ where } /// Sign the given message using the provided external randomness source. -#[cfg(feature = "rand-preview")] -#[cfg_attr(docsrs, doc(cfg(feature = "rand-preview")))] -pub trait RandomizedSigner { +#[cfg(feature = "rand_core")] +pub trait RandomizedSigner { /// Sign the given message and return a digital signature - fn sign_with_rng(&self, rng: impl CryptoRng + RngCore, msg: &[u8]) -> S { + fn sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S { self.try_sign_with_rng(rng, msg) .expect("signature operation failed") } @@ -105,32 +96,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: impl CryptoRng + RngCore, msg: &[u8]) -> Result; + fn try_sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> Result; } /// Combination of [`DigestSigner`] and [`RandomizedSigner`] with support for /// computing a signature over a digest which requires entropy from an RNG. -#[cfg(all(feature = "digest-preview", feature = "rand-preview"))] -#[cfg_attr(docsrs, doc(cfg(feature = "digest-preview")))] -#[cfg_attr(docsrs, doc(cfg(feature = "rand-preview")))] -pub trait RandomizedDigestSigner -where - D: Digest, - S: Signature, -{ +#[cfg(all(feature = "digest", feature = "rand_core"))] +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: impl CryptoRng + RngCore, digest: D) -> S { + fn sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, 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: impl CryptoRng + RngCore, - digest: D, - ) -> Result; + fn try_sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, digest: D) + -> Result; } -- cgit v1.2.3