Skip to content

Commit cf99e60

Browse files
committed
signature: use &mut impl CryptoRngCore RNG arguments
`rand_core` v0.6.4 added an auto-impl'd `CryptoRngCore` marker trait for types which impl `CryptoRng + RngCore` which is slightly more convenient and less verbose. This commit changes to using `&mut impl CryptoRngCore` as proposed in #1087. This hopefully strikes a balance between least surprise and minimal required syntax, namely &mut references are reusable and don't require knowledge of the blanket impl of `RngCore` for `&mut R: RngCore`
1 parent 796894f commit cf99e60

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

signature/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ categories = ["cryptography", "no-std"]
1414

1515
[dependencies]
1616
digest = { version = "0.10.3", optional = true, default-features = false }
17-
rand_core = { version = "0.6", optional = true, default-features = false }
17+
rand_core = { version = "0.6.4", optional = true, default-features = false }
1818
derive = { package = "signature_derive", version = "=2.0.0-pre.0", optional = true, path = "derive" }
1919

2020
[dev-dependencies]

signature/src/signer.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::error::Error;
66
use crate::digest::Digest;
77

88
#[cfg(feature = "rand-preview")]
9-
use crate::rand_core::{CryptoRng, RngCore};
9+
use crate::rand_core::CryptoRngCore;
1010

1111
/// Sign the provided message bytestring using `Self` (e.g. a cryptographic key
1212
/// or connection to an HSM), returning a digital signature.
@@ -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: impl CryptoRng + RngCore, msg: &[u8]) -> S {
90+
fn sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S {
9191
self.try_sign_with_rng(rng, msg)
9292
.expect("signature operation failed")
9393
}
@@ -97,7 +97,7 @@ 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: impl CryptoRng + RngCore, msg: &[u8]) -> Result<S, Error>;
100+
fn try_sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> Result<S, Error>;
101101
}
102102

103103
/// Combination of [`DigestSigner`] and [`RandomizedSigner`] with support for
@@ -109,16 +109,13 @@ pub trait RandomizedDigestSigner<D: Digest, S> {
109109
/// Sign the given prehashed message `Digest`, returning a signature.
110110
///
111111
/// Panics in the event of a signing error.
112-
fn sign_digest_with_rng(&self, rng: impl CryptoRng + RngCore, digest: D) -> S {
112+
fn sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, digest: D) -> S {
113113
self.try_sign_digest_with_rng(rng, digest)
114114
.expect("signature operation failed")
115115
}
116116

117117
/// Attempt to sign the given prehashed message `Digest`, returning a
118118
/// digital signature on success, or an error if something went wrong.
119-
fn try_sign_digest_with_rng(
120-
&self,
121-
rng: impl CryptoRng + RngCore,
122-
digest: D,
123-
) -> Result<S, Error>;
119+
fn try_sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, digest: D)
120+
-> Result<S, Error>;
124121
}

0 commit comments

Comments
 (0)