@@ -17,13 +17,14 @@ pub use signature::{self, Error};
17
17
#[ cfg( feature = "digest" ) ]
18
18
pub use signature:: digest:: { self , Digest } ;
19
19
20
- use async_trait:: async_trait;
20
+ #[ cfg( feature = "rand_core" ) ]
21
+ use signature:: rand_core:: CryptoRngCore ;
21
22
22
23
/// Asynchronously sign the provided message bytestring using `Self`
23
24
/// (e.g. client for a Cloud KMS or HSM), returning a digital signature.
24
25
///
25
26
/// This trait is an async equivalent of the [`signature::Signer`] trait.
26
- #[ async_trait ( ? Send ) ]
27
+ #[ allow ( async_fn_in_trait ) ]
27
28
pub trait AsyncSigner < S : ' static > {
28
29
/// Attempt to sign the given message, returning a digital signature on
29
30
/// success, or an error if something went wrong.
@@ -33,7 +34,6 @@ pub trait AsyncSigner<S: 'static> {
33
34
async fn sign_async ( & self , msg : & [ u8 ] ) -> Result < S , Error > ;
34
35
}
35
36
36
- #[ async_trait( ?Send ) ]
37
37
impl < S , T > AsyncSigner < S > for T
38
38
where
39
39
S : ' static ,
48
48
///
49
49
/// This trait is an async equivalent of the [`signature::DigestSigner`] trait.
50
50
#[ cfg( feature = "digest" ) ]
51
- #[ async_trait ( ? Send ) ]
51
+ #[ allow ( async_fn_in_trait ) ]
52
52
pub trait AsyncDigestSigner < D , S >
53
53
where
54
54
D : Digest + ' static ,
60
60
}
61
61
62
62
#[ cfg( feature = "digest" ) ]
63
- #[ async_trait( ?Send ) ]
64
63
impl < D , S , T > AsyncDigestSigner < D , S > for T
65
64
where
66
65
D : Digest + ' static ,
71
70
self . try_sign_digest ( digest)
72
71
}
73
72
}
73
+
74
+ /// Sign the given message using the provided external randomness source.
75
+ #[ cfg( feature = "rand_core" ) ]
76
+ #[ allow( async_fn_in_trait) ]
77
+ pub trait AsyncRandomizedSigner < S > {
78
+ /// Sign the given message and return a digital signature
79
+ async fn sign_with_rng_async ( & self , rng : & mut impl CryptoRngCore , msg : & [ u8 ] ) -> S {
80
+ self . try_sign_with_rng_async ( rng, msg)
81
+ . await
82
+ . expect ( "signature operation failed" )
83
+ }
84
+
85
+ /// Attempt to sign the given message, returning a digital signature on
86
+ /// success, or an error if something went wrong.
87
+ ///
88
+ /// The main intended use case for signing errors is when communicating
89
+ /// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
90
+ async fn try_sign_with_rng_async (
91
+ & self ,
92
+ rng : & mut impl CryptoRngCore ,
93
+ msg : & [ u8 ] ,
94
+ ) -> Result < S , Error > ;
95
+ }
96
+
97
+ #[ cfg( feature = "rand_core" ) ]
98
+ impl < S , T > AsyncRandomizedSigner < S > for T
99
+ where
100
+ S : ' static ,
101
+ T : signature:: RandomizedSigner < S > ,
102
+ {
103
+ async fn try_sign_with_rng_async (
104
+ & self ,
105
+ rng : & mut impl CryptoRngCore ,
106
+ msg : & [ u8 ] ,
107
+ ) -> Result < S , Error > {
108
+ self . try_sign_with_rng ( rng, msg)
109
+ }
110
+ }
0 commit comments