Skip to content

Commit b12237e

Browse files
authored
signature: use R: CryptoRngCore + ?Sized for RNG params (#1167)
As discussed in #1148, adopts a generic paramater `R` for RNGs, and also adds a `?Sized` bound which permits the use of trait objects.
1 parent 28ec035 commit b12237e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

signature/src/hazmat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ pub trait RandomizedPrehashSigner<S> {
4848
///
4949
/// Allowed lengths are algorithm-dependent and up to a particular
5050
/// implementation to decide.
51-
fn sign_prehash_with_rng(
51+
fn sign_prehash_with_rng<R: CryptoRngCore + ?Sized>(
5252
&self,
53-
rng: &mut impl CryptoRngCore,
53+
rng: &mut R,
5454
prehash: &[u8],
5555
) -> Result<S, Error>;
5656
}

signature/src/signer.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub trait DigestSigner<D: Digest, S> {
8787
#[cfg_attr(docsrs, doc(cfg(feature = "rand-preview")))]
8888
pub trait RandomizedSigner<S> {
8989
/// Sign the given message and return a digital signature
90-
fn sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S {
90+
fn sign_with_rng<R: CryptoRngCore + ?Sized>(&self, rng: &mut R, msg: &[u8]) -> S {
9191
self.try_sign_with_rng(rng, msg)
9292
.expect("signature operation failed")
9393
}
@@ -97,7 +97,11 @@ pub trait RandomizedSigner<S> {
9797
///
9898
/// The main intended use case for signing errors is when communicating
9999
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
100-
fn try_sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> Result<S, Error>;
100+
fn try_sign_with_rng<R: CryptoRngCore + ?Sized>(
101+
&self,
102+
rng: &mut R,
103+
msg: &[u8],
104+
) -> Result<S, Error>;
101105
}
102106

103107
/// Combination of [`DigestSigner`] and [`RandomizedSigner`] with support for
@@ -109,13 +113,16 @@ pub trait RandomizedDigestSigner<D: Digest, S> {
109113
/// Sign the given prehashed message `Digest`, returning a signature.
110114
///
111115
/// Panics in the event of a signing error.
112-
fn sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, digest: D) -> S {
116+
fn sign_digest_with_rng<R: CryptoRngCore + ?Sized>(&self, rng: &mut R, digest: D) -> S {
113117
self.try_sign_digest_with_rng(rng, digest)
114118
.expect("signature operation failed")
115119
}
116120

117121
/// Attempt to sign the given prehashed message `Digest`, returning a
118122
/// digital signature on success, or an error if something went wrong.
119-
fn try_sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, digest: D)
120-
-> Result<S, Error>;
123+
fn try_sign_digest_with_rng<R: CryptoRngCore + ?Sized>(
124+
&self,
125+
rng: &mut R,
126+
digest: D,
127+
) -> Result<S, Error>;
121128
}

0 commit comments

Comments
 (0)