|
3 | 3 | use crate::error::Error; |
4 | 4 |
|
5 | 5 | #[cfg(feature = "digest")] |
6 | | -use crate::digest::Digest; |
| 6 | +use crate::{PrehashSignature, digest::Digest}; |
7 | 7 |
|
8 | 8 | #[cfg(feature = "rand_core")] |
9 | 9 | use crate::rand_core::{CryptoRng, TryCryptoRng}; |
@@ -82,6 +82,17 @@ pub trait DigestSigner<D: Digest, S> { |
82 | 82 | fn try_sign_digest(&self, digest: D) -> Result<S, Error>; |
83 | 83 | } |
84 | 84 |
|
| 85 | +#[cfg(feature = "digest")] |
| 86 | +impl<S, T> Signer<S> for T |
| 87 | +where |
| 88 | + S: PrehashSignature, |
| 89 | + T: DigestSigner<S::Digest, S>, |
| 90 | +{ |
| 91 | + fn try_sign(&self, msg: &[u8]) -> Result<S, Error> { |
| 92 | + self.try_sign_digest(S::Digest::new_with_prefix(msg)) |
| 93 | + } |
| 94 | +} |
| 95 | + |
85 | 96 | /// Sign the given message using the provided external randomness source. |
86 | 97 | #[cfg(feature = "rand_core")] |
87 | 98 | pub trait RandomizedSigner<S> { |
@@ -124,6 +135,21 @@ pub trait RandomizedDigestSigner<D: Digest, S> { |
124 | 135 | ) -> Result<S, Error>; |
125 | 136 | } |
126 | 137 |
|
| 138 | +#[cfg(all(feature = "digest", feature = "rand_core"))] |
| 139 | +impl<S, T> RandomizedSigner<S> for T |
| 140 | +where |
| 141 | + S: PrehashSignature, |
| 142 | + T: RandomizedDigestSigner<S::Digest, S>, |
| 143 | +{ |
| 144 | + fn try_sign_with_rng<R: TryCryptoRng + ?Sized>( |
| 145 | + &self, |
| 146 | + rng: &mut R, |
| 147 | + msg: &[u8], |
| 148 | + ) -> Result<S, Error> { |
| 149 | + self.try_sign_digest_with_rng(rng, S::Digest::new_with_prefix(msg)) |
| 150 | + } |
| 151 | +} |
| 152 | + |
127 | 153 | /// Sign the provided message bytestring using `&mut Self` (e.g. an evolving |
128 | 154 | /// cryptographic key such as a stateful hash-based signature), and a per-signature |
129 | 155 | /// randomizer, returning a digital signature. |
|
0 commit comments