Skip to content

Commit f17b962

Browse files
authored
signature: relax Sized requirements on rng (#1765)
1 parent ad7adbb commit f17b962

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

signature/src/signer.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub trait DigestSigner<D: Digest, S> {
8686
#[cfg(feature = "rand_core")]
8787
pub trait RandomizedSigner<S> {
8888
/// Sign the given message and return a digital signature
89-
fn sign_with_rng<R: CryptoRng>(&self, rng: &mut R, msg: &[u8]) -> S {
89+
fn sign_with_rng<R: CryptoRng + ?Sized>(&self, rng: &mut R, msg: &[u8]) -> S {
9090
self.try_sign_with_rng(rng, msg)
9191
.expect("signature operation failed")
9292
}
@@ -96,7 +96,11 @@ pub trait RandomizedSigner<S> {
9696
///
9797
/// The main intended use case for signing errors is when communicating
9898
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
99-
fn try_sign_with_rng<R: TryCryptoRng>(&self, rng: &mut R, msg: &[u8]) -> Result<S, Error>;
99+
fn try_sign_with_rng<R: TryCryptoRng + ?Sized>(
100+
&self,
101+
rng: &mut R,
102+
msg: &[u8],
103+
) -> Result<S, Error>;
100104
}
101105

102106
/// Combination of [`DigestSigner`] and [`RandomizedSigner`] with support for
@@ -106,15 +110,18 @@ pub trait RandomizedDigestSigner<D: Digest, S> {
106110
/// Sign the given prehashed message `Digest`, returning a signature.
107111
///
108112
/// Panics in the event of a signing error.
109-
fn sign_digest_with_rng<R: CryptoRng>(&self, rng: &mut R, digest: D) -> S {
113+
fn sign_digest_with_rng<R: CryptoRng + ?Sized>(&self, rng: &mut R, digest: D) -> S {
110114
self.try_sign_digest_with_rng(rng, digest)
111115
.expect("signature operation failed")
112116
}
113117

114118
/// Attempt to sign the given prehashed message `Digest`, returning a
115119
/// digital signature on success, or an error if something went wrong.
116-
fn try_sign_digest_with_rng<R: TryCryptoRng>(&self, rng: &mut R, digest: D)
117-
-> Result<S, Error>;
120+
fn try_sign_digest_with_rng<R: TryCryptoRng + ?Sized>(
121+
&self,
122+
rng: &mut R,
123+
digest: D,
124+
) -> Result<S, Error>;
118125
}
119126

120127
/// Sign the provided message bytestring using `&mut Self` (e.g. an evolving
@@ -123,7 +130,7 @@ pub trait RandomizedDigestSigner<D: Digest, S> {
123130
#[cfg(feature = "rand_core")]
124131
pub trait RandomizedSignerMut<S> {
125132
/// Sign the given message, update the state, and return a digital signature.
126-
fn sign_with_rng<R: CryptoRng>(&mut self, rng: &mut R, msg: &[u8]) -> S {
133+
fn sign_with_rng<R: CryptoRng + ?Sized>(&mut self, rng: &mut R, msg: &[u8]) -> S {
127134
self.try_sign_with_rng(rng, msg)
128135
.expect("signature operation failed")
129136
}
@@ -133,13 +140,21 @@ pub trait RandomizedSignerMut<S> {
133140
///
134141
/// Signing can fail, e.g., if the number of time periods allowed by the
135142
/// current key is exceeded.
136-
fn try_sign_with_rng<R: TryCryptoRng>(&mut self, rng: &mut R, msg: &[u8]) -> Result<S, Error>;
143+
fn try_sign_with_rng<R: TryCryptoRng + ?Sized>(
144+
&mut self,
145+
rng: &mut R,
146+
msg: &[u8],
147+
) -> Result<S, Error>;
137148
}
138149

139150
/// Blanket impl of [`RandomizedSignerMut`] for all [`RandomizedSigner`] types.
140151
#[cfg(feature = "rand_core")]
141152
impl<S, T: RandomizedSigner<S>> RandomizedSignerMut<S> for T {
142-
fn try_sign_with_rng<R: TryCryptoRng>(&mut self, rng: &mut R, msg: &[u8]) -> Result<S, Error> {
153+
fn try_sign_with_rng<R: TryCryptoRng + ?Sized>(
154+
&mut self,
155+
rng: &mut R,
156+
msg: &[u8],
157+
) -> Result<S, Error> {
143158
T::try_sign_with_rng(self, rng, msg)
144159
}
145160
}

0 commit comments

Comments
 (0)