Skip to content

Commit 7b57fe2

Browse files
committed
signature: merge types from async-signature
1 parent 7eec720 commit 7b57fe2

File tree

5 files changed

+139
-115
lines changed

5 files changed

+139
-115
lines changed

async-signature/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
[![Project Chat][chat-image]][chat-link]
88
[![Build Status][build-image]][build-link]
99

10+
## Deprecated
11+
12+
This crate is now deprecated, all the types are available in [`signature`][signature-crate]
13+
1014
## Minimum Supported Rust Version
1115

1216
Rust **1.81** or higher.
@@ -41,3 +45,4 @@ dual licensed as above, without any additional terms or conditions.
4145
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260048-signatures
4246
[build-image]: https://github.com/RustCrypto/traits/workflows/async-signature/badge.svg?branch=master&event=push
4347
[build-link]: https://github.com/RustCrypto/traits/actions?query=workflow:async-signature
48+
[signature-crate]: https://crates.io/crates/signature

async-signature/src/hazmat.rs

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,15 @@
66
//! Using them incorrectly can introduce security vulnerabilities. Please
77
//! carefully read the documentation before attempting to use them.
88
9-
use signature::Error;
9+
#[deprecated(
10+
since = "0.6.0",
11+
note = "use `signature::hazmat::AsyncPrehashSigner` instead"
12+
)]
13+
pub use signature::hazmat::AsyncPrehashSigner;
1014

1115
#[cfg(feature = "rand_core")]
12-
use signature::rand_core::CryptoRngCore;
13-
14-
/// Asynchronously sign the provided message prehash, returning a digital signature.
15-
#[allow(async_fn_in_trait)]
16-
pub trait AsyncPrehashSigner<S> {
17-
/// Attempt to sign the given message digest, returning a digital signature
18-
/// on success, or an error if something went wrong.
19-
///
20-
/// The `prehash` parameter should be the output of a secure cryptographic
21-
/// hash function.
22-
///
23-
/// This API takes a `prehash` byte slice as there can potentially be many
24-
/// compatible lengths for the message digest for a given concrete signature
25-
/// algorithm.
26-
///
27-
/// Allowed lengths are algorithm-dependent and up to a particular
28-
/// implementation to decide.
29-
async fn sign_prehash_async(&self, prehash: &[u8]) -> Result<S, Error>;
30-
}
31-
32-
/// Asynchronously sign the provided message prehash using the provided external randomness source, returning a digital signature.
33-
#[cfg(feature = "rand_core")]
34-
#[allow(async_fn_in_trait)]
35-
pub trait AsyncRandomizedPrehashSigner<S> {
36-
/// Attempt to sign the given message digest, returning a digital signature
37-
/// on success, or an error if something went wrong.
38-
///
39-
/// The `prehash` parameter should be the output of a secure cryptographic
40-
/// hash function.
41-
///
42-
/// This API takes a `prehash` byte slice as there can potentially be many
43-
/// compatible lengths for the message digest for a given concrete signature
44-
/// algorithm.
45-
///
46-
/// Allowed lengths are algorithm-dependent and up to a particular
47-
/// implementation to decide.
48-
async fn sign_prehash_with_rng_async(
49-
&self,
50-
rng: &mut impl CryptoRngCore,
51-
prehash: &[u8],
52-
) -> Result<S, Error>;
53-
}
16+
#[deprecated(
17+
since = "0.6.0",
18+
note = "use `signature::hazmat::AsyncRandomizedPrehashSigner` instead"
19+
)]
20+
pub use signature::hazmat::AsyncRandomizedPrehashSigner;

async-signature/src/lib.rs

Lines changed: 9 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -20,79 +20,16 @@ pub use signature::{self, Error};
2020
#[cfg(feature = "digest")]
2121
pub use signature::digest::{self, Digest};
2222

23-
#[cfg(feature = "rand_core")]
24-
use signature::rand_core::CryptoRngCore;
25-
26-
/// Asynchronously sign the provided message bytestring using `Self`
27-
/// (e.g. client for a Cloud KMS or HSM), returning a digital signature.
28-
///
29-
/// This trait is an async equivalent of the [`signature::Signer`] trait.
30-
#[allow(async_fn_in_trait)]
31-
pub trait AsyncSigner<S> {
32-
/// Attempt to sign the given message, returning a digital signature on
33-
/// success, or an error if something went wrong.
34-
///
35-
/// The main intended use case for signing errors is when communicating
36-
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
37-
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error>;
38-
}
23+
#[deprecated(since = "0.6.0", note = "use `signature::AsyncSigner` instead")]
24+
pub use signature::AsyncSigner;
3925

40-
impl<S, T> AsyncSigner<S> for T
41-
where
42-
T: signature::Signer<S>,
43-
{
44-
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error> {
45-
self.try_sign(msg)
46-
}
47-
}
48-
49-
/// Asynchronously sign the given prehashed message [`Digest`] using `Self`.
50-
///
51-
/// This trait is an async equivalent of the [`signature::DigestSigner`] trait.
5226
#[cfg(feature = "digest")]
53-
#[allow(async_fn_in_trait)]
54-
pub trait AsyncDigestSigner<D, S>
55-
where
56-
D: Digest,
57-
{
58-
/// Attempt to sign the given prehashed message [`Digest`], returning a
59-
/// digital signature on success, or an error if something went wrong.
60-
async fn sign_digest_async(&self, digest: D) -> Result<S, Error>;
61-
}
27+
#[deprecated(since = "0.6.0", note = "use `signature::AsyncDigestSigner` instead")]
28+
pub use signature::AsyncDigestSigner;
6229

63-
/// Sign the given message using the provided external randomness source.
6430
#[cfg(feature = "rand_core")]
65-
#[allow(async_fn_in_trait)]
66-
pub trait AsyncRandomizedSigner<S> {
67-
/// Sign the given message and return a digital signature
68-
async fn sign_with_rng_async(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S {
69-
self.try_sign_with_rng_async(rng, msg)
70-
.await
71-
.expect("signature operation failed")
72-
}
73-
74-
/// Attempt to sign the given message, returning a digital signature on
75-
/// success, or an error if something went wrong.
76-
///
77-
/// The main intended use case for signing errors is when communicating
78-
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
79-
async fn try_sign_with_rng_async(
80-
&self,
81-
rng: &mut impl CryptoRngCore,
82-
msg: &[u8],
83-
) -> Result<S, Error>;
84-
}
85-
86-
#[cfg(feature = "rand_core")]
87-
impl<S, T> AsyncRandomizedSigner<S> for T
88-
where
89-
T: signature::RandomizedSigner<S>,
90-
{
91-
async fn try_sign_with_rng_async(
92-
&self,
93-
rng: &mut impl CryptoRngCore,
94-
msg: &[u8],
95-
) -> Result<S, Error> {
96-
self.try_sign_with_rng(rng, msg)
97-
}
98-
}
31+
#[deprecated(
32+
since = "0.6.0",
33+
note = "use `signature::AsyncRandomizedSigner` instead"
34+
)]
35+
pub use signature::AsyncRandomizedSigner;

signature/src/hazmat.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,44 @@ pub trait PrehashVerifier<S> {
6868
/// solving a system of linear equations.
6969
fn verify_prehash(&self, prehash: &[u8], signature: &S) -> Result<(), Error>;
7070
}
71+
72+
/// Asynchronously sign the provided message prehash, returning a digital signature.
73+
#[allow(async_fn_in_trait)]
74+
pub trait AsyncPrehashSigner<S> {
75+
/// Attempt to sign the given message digest, returning a digital signature
76+
/// on success, or an error if something went wrong.
77+
///
78+
/// The `prehash` parameter should be the output of a secure cryptographic
79+
/// hash function.
80+
///
81+
/// This API takes a `prehash` byte slice as there can potentially be many
82+
/// compatible lengths for the message digest for a given concrete signature
83+
/// algorithm.
84+
///
85+
/// Allowed lengths are algorithm-dependent and up to a particular
86+
/// implementation to decide.
87+
async fn sign_prehash_async(&self, prehash: &[u8]) -> Result<S, Error>;
88+
}
89+
90+
/// Asynchronously sign the provided message prehash using the provided external randomness source, returning a digital signature.
91+
#[cfg(feature = "rand_core")]
92+
#[allow(async_fn_in_trait)]
93+
pub trait AsyncRandomizedPrehashSigner<S> {
94+
/// Attempt to sign the given message digest, returning a digital signature
95+
/// on success, or an error if something went wrong.
96+
///
97+
/// The `prehash` parameter should be the output of a secure cryptographic
98+
/// hash function.
99+
///
100+
/// This API takes a `prehash` byte slice as there can potentially be many
101+
/// compatible lengths for the message digest for a given concrete signature
102+
/// algorithm.
103+
///
104+
/// Allowed lengths are algorithm-dependent and up to a particular
105+
/// implementation to decide.
106+
async fn sign_prehash_with_rng_async(
107+
&self,
108+
rng: &mut impl CryptoRngCore,
109+
prehash: &[u8],
110+
) -> Result<S, Error>;
111+
}

signature/src/signer.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,77 @@ impl<S, T: RandomizedSigner<S>> RandomizedSignerMut<S> for T {
143143
T::try_sign_with_rng(self, rng, msg)
144144
}
145145
}
146+
147+
/// Asynchronously sign the provided message bytestring using `Self`
148+
/// (e.g. client for a Cloud KMS or HSM), returning a digital signature.
149+
///
150+
/// This trait is an async equivalent of the [`signature::Signer`] trait.
151+
#[allow(async_fn_in_trait)]
152+
pub trait AsyncSigner<S> {
153+
/// Attempt to sign the given message, returning a digital signature on
154+
/// success, or an error if something went wrong.
155+
///
156+
/// The main intended use case for signing errors is when communicating
157+
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
158+
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error>;
159+
}
160+
161+
impl<S, T> AsyncSigner<S> for T
162+
where
163+
T: Signer<S>,
164+
{
165+
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error> {
166+
self.try_sign(msg)
167+
}
168+
}
169+
170+
/// Asynchronously sign the given prehashed message [`Digest`] using `Self`.
171+
///
172+
/// This trait is an async equivalent of the [`signature::DigestSigner`] trait.
173+
#[cfg(feature = "digest")]
174+
#[allow(async_fn_in_trait)]
175+
pub trait AsyncDigestSigner<D, S>
176+
where
177+
D: Digest,
178+
{
179+
/// Attempt to sign the given prehashed message [`Digest`], returning a
180+
/// digital signature on success, or an error if something went wrong.
181+
async fn sign_digest_async(&self, digest: D) -> Result<S, Error>;
182+
}
183+
184+
/// Sign the given message using the provided external randomness source.
185+
#[cfg(feature = "rand_core")]
186+
#[allow(async_fn_in_trait)]
187+
pub trait AsyncRandomizedSigner<S> {
188+
/// Sign the given message and return a digital signature
189+
async fn sign_with_rng_async(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S {
190+
self.try_sign_with_rng_async(rng, msg)
191+
.await
192+
.expect("signature operation failed")
193+
}
194+
195+
/// Attempt to sign the given message, returning a digital signature on
196+
/// success, or an error if something went wrong.
197+
///
198+
/// The main intended use case for signing errors is when communicating
199+
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
200+
async fn try_sign_with_rng_async(
201+
&self,
202+
rng: &mut impl CryptoRngCore,
203+
msg: &[u8],
204+
) -> Result<S, Error>;
205+
}
206+
207+
#[cfg(feature = "rand_core")]
208+
impl<S, T> AsyncRandomizedSigner<S> for T
209+
where
210+
T: RandomizedSigner<S>,
211+
{
212+
async fn try_sign_with_rng_async(
213+
&self,
214+
rng: &mut impl CryptoRngCore,
215+
msg: &[u8],
216+
) -> Result<S, Error> {
217+
self.try_sign_with_rng(rng, msg)
218+
}
219+
}

0 commit comments

Comments
 (0)