@@ -12,7 +12,7 @@ use crate::rand_core::{CryptoRng, TryCryptoRng};
12
12
/// or connection to an HSM), returning a digital signature.
13
13
pub trait Signer < S > {
14
14
/// Sign the given message and return a digital signature
15
- fn sign ( & self , msg : & [ & [ u8 ] ] ) -> S {
15
+ fn sign ( & self , msg : & [ u8 ] ) -> S {
16
16
self . try_sign ( msg) . expect ( "signature operation failed" )
17
17
}
18
18
@@ -21,6 +21,17 @@ pub trait Signer<S> {
21
21
///
22
22
/// The main intended use case for signing errors is when communicating
23
23
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
24
+ fn try_sign ( & self , msg : & [ u8 ] ) -> Result < S , Error > ;
25
+ }
26
+
27
+ /// Equivalent of [`Signer`] but the message is provided in non-contiguous byte slices.
28
+ pub trait MultiPartSigner < S > {
29
+ /// See [`Signer::sign()`].
30
+ fn sign ( & self , msg : & [ & [ u8 ] ] ) -> S {
31
+ self . try_sign ( msg) . expect ( "signature operation failed" )
32
+ }
33
+
34
+ /// See [`Signer::try_sign()`].
24
35
fn try_sign ( & self , msg : & [ & [ u8 ] ] ) -> Result < S , Error > ;
25
36
}
26
37
@@ -29,7 +40,7 @@ pub trait Signer<S> {
29
40
/// digital signature.
30
41
pub trait SignerMut < S > {
31
42
/// Sign the given message, update the state, and return a digital signature.
32
- fn sign ( & mut self , msg : & [ & [ u8 ] ] ) -> S {
43
+ fn sign ( & mut self , msg : & [ u8 ] ) -> S {
33
44
self . try_sign ( msg) . expect ( "signature operation failed" )
34
45
}
35
46
@@ -38,16 +49,27 @@ pub trait SignerMut<S> {
38
49
///
39
50
/// Signing can fail, e.g., if the number of time periods allowed by the
40
51
/// current key is exceeded.
41
- fn try_sign ( & mut self , msg : & [ & [ u8 ] ] ) -> Result < S , Error > ;
52
+ fn try_sign ( & mut self , msg : & [ u8 ] ) -> Result < S , Error > ;
42
53
}
43
54
44
55
/// Blanket impl of [`SignerMut`] for all [`Signer`] types.
45
56
impl < S , T : Signer < S > > SignerMut < S > for T {
46
- fn try_sign ( & mut self , msg : & [ & [ u8 ] ] ) -> Result < S , Error > {
57
+ fn try_sign ( & mut self , msg : & [ u8 ] ) -> Result < S , Error > {
47
58
T :: try_sign ( self , msg)
48
59
}
49
60
}
50
61
62
+ /// Equivalent of [`SignerMut`] but the message is provided in non-contiguous byte slices.
63
+ pub trait MultiPartSignerMut < S > {
64
+ /// See [`SignerMut::sign()`].
65
+ fn sign ( & mut self , msg : & [ & [ u8 ] ] ) -> S {
66
+ self . try_sign ( msg) . expect ( "signature operation failed" )
67
+ }
68
+
69
+ /// See [`SignerMut::try_sign()`].
70
+ fn try_sign ( & mut self , msg : & [ & [ u8 ] ] ) -> Result < S , Error > ;
71
+ }
72
+
51
73
/// Sign the given prehashed message [`Digest`] using `Self`.
52
74
///
53
75
/// ## Notes
@@ -86,7 +108,7 @@ pub trait DigestSigner<D: Digest, S> {
86
108
#[ cfg( feature = "rand_core" ) ]
87
109
pub trait RandomizedSigner < S > {
88
110
/// Sign the given message and return a digital signature
89
- fn sign_with_rng < R : CryptoRng + ?Sized > ( & self , rng : & mut R , msg : & [ & [ u8 ] ] ) -> S {
111
+ fn sign_with_rng < R : CryptoRng + ?Sized > ( & self , rng : & mut R , msg : & [ u8 ] ) -> S {
90
112
self . try_sign_with_rng ( rng, msg)
91
113
. expect ( "signature operation failed" )
92
114
}
@@ -96,6 +118,23 @@ pub trait RandomizedSigner<S> {
96
118
///
97
119
/// The main intended use case for signing errors is when communicating
98
120
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
121
+ fn try_sign_with_rng < R : TryCryptoRng + ?Sized > (
122
+ & self ,
123
+ rng : & mut R ,
124
+ msg : & [ u8 ] ,
125
+ ) -> Result < S , Error > ;
126
+ }
127
+
128
+ /// Equivalent of [`RandomizedSigner`] but the message is provided in non-contiguous byte slices.
129
+ #[ cfg( feature = "rand_core" ) ]
130
+ pub trait RandomizedMultiPartSigner < S > {
131
+ /// See [`RandomizedSigner::sign_with_rng()`].
132
+ fn sign_with_rng < R : CryptoRng + ?Sized > ( & self , rng : & mut R , msg : & [ & [ u8 ] ] ) -> S {
133
+ self . try_sign_with_rng ( rng, msg)
134
+ . expect ( "signature operation failed" )
135
+ }
136
+
137
+ /// See [`RandomizedSigner::try_sign_with_rng()`].
99
138
fn try_sign_with_rng < R : TryCryptoRng + ?Sized > (
100
139
& self ,
101
140
rng : & mut R ,
@@ -130,7 +169,7 @@ pub trait RandomizedDigestSigner<D: Digest, S> {
130
169
#[ cfg( feature = "rand_core" ) ]
131
170
pub trait RandomizedSignerMut < S > {
132
171
/// Sign the given message, update the state, and return a digital signature.
133
- fn sign_with_rng < R : CryptoRng + ?Sized > ( & mut self , rng : & mut R , msg : & [ & [ u8 ] ] ) -> S {
172
+ fn sign_with_rng < R : CryptoRng + ?Sized > ( & mut self , rng : & mut R , msg : & [ u8 ] ) -> S {
134
173
self . try_sign_with_rng ( rng, msg)
135
174
. expect ( "signature operation failed" )
136
175
}
@@ -143,7 +182,7 @@ pub trait RandomizedSignerMut<S> {
143
182
fn try_sign_with_rng < R : TryCryptoRng + ?Sized > (
144
183
& mut self ,
145
184
rng : & mut R ,
146
- msg : & [ & [ u8 ] ] ,
185
+ msg : & [ u8 ] ,
147
186
) -> Result < S , Error > ;
148
187
}
149
188
@@ -153,12 +192,29 @@ impl<S, T: RandomizedSigner<S>> RandomizedSignerMut<S> for T {
153
192
fn try_sign_with_rng < R : TryCryptoRng + ?Sized > (
154
193
& mut self ,
155
194
rng : & mut R ,
156
- msg : & [ & [ u8 ] ] ,
195
+ msg : & [ u8 ] ,
157
196
) -> Result < S , Error > {
158
197
T :: try_sign_with_rng ( self , rng, msg)
159
198
}
160
199
}
161
200
201
+ /// Equivalent of [`RandomizedSignerMut`] but the message is provided in non-contiguous byte slices.
202
+ #[ cfg( feature = "rand_core" ) ]
203
+ pub trait RandomizedMultiPartSignerMut < S > {
204
+ /// See [`RandomizedSignerMut::sign_with_rng()`].
205
+ fn sign_with_rng < R : CryptoRng + ?Sized > ( & mut self , rng : & mut R , msg : & [ u8 ] ) -> S {
206
+ self . try_sign_with_rng ( rng, msg)
207
+ . expect ( "signature operation failed" )
208
+ }
209
+
210
+ /// See [`RandomizedSignerMut::try_sign_with_rng()`].
211
+ fn try_sign_with_rng < R : TryCryptoRng + ?Sized > (
212
+ & mut self ,
213
+ rng : & mut R ,
214
+ msg : & [ u8 ] ,
215
+ ) -> Result < S , Error > ;
216
+ }
217
+
162
218
/// Asynchronously sign the provided message bytestring using `Self`
163
219
/// (e.g. client for a Cloud KMS or HSM), returning a digital signature.
164
220
///
@@ -169,18 +225,24 @@ pub trait AsyncSigner<S> {
169
225
///
170
226
/// The main intended use case for signing errors is when communicating
171
227
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
172
- async fn sign_async ( & self , msg : & [ & [ u8 ] ] ) -> Result < S , Error > ;
228
+ async fn sign_async ( & self , msg : & [ u8 ] ) -> Result < S , Error > ;
173
229
}
174
230
175
231
impl < S , T > AsyncSigner < S > for T
176
232
where
177
233
T : Signer < S > ,
178
234
{
179
- async fn sign_async ( & self , msg : & [ & [ u8 ] ] ) -> Result < S , Error > {
235
+ async fn sign_async ( & self , msg : & [ u8 ] ) -> Result < S , Error > {
180
236
self . try_sign ( msg)
181
237
}
182
238
}
183
239
240
+ /// Equivalent of [`AsyncSigner`] but the message is provided in non-contiguous byte slices.
241
+ pub trait AsyncMultiPartSigner < S > {
242
+ /// See [`AsyncSigner::sign_async()`].
243
+ async fn sign_async ( & self , msg : & [ & [ u8 ] ] ) -> Result < S , Error > ;
244
+ }
245
+
184
246
/// Asynchronously sign the given prehashed message [`Digest`] using `Self`.
185
247
///
186
248
/// This trait is an async equivalent of the [`DigestSigner`] trait.
@@ -198,7 +260,7 @@ where
198
260
#[ cfg( feature = "rand_core" ) ]
199
261
pub trait AsyncRandomizedSigner < S > {
200
262
/// Sign the given message and return a digital signature
201
- async fn sign_with_rng_async < R : CryptoRng + ?Sized > ( & self , rng : & mut R , msg : & [ & [ u8 ] ] ) -> S {
263
+ async fn sign_with_rng_async < R : CryptoRng + ?Sized > ( & self , rng : & mut R , msg : & [ u8 ] ) -> S {
202
264
self . try_sign_with_rng_async ( rng, msg)
203
265
. await
204
266
. expect ( "signature operation failed" )
@@ -212,7 +274,7 @@ pub trait AsyncRandomizedSigner<S> {
212
274
async fn try_sign_with_rng_async < R : TryCryptoRng + ?Sized > (
213
275
& self ,
214
276
rng : & mut R ,
215
- msg : & [ & [ u8 ] ] ,
277
+ msg : & [ u8 ] ,
216
278
) -> Result < S , Error > ;
217
279
}
218
280
@@ -224,8 +286,26 @@ where
224
286
async fn try_sign_with_rng_async < R : TryCryptoRng + ?Sized > (
225
287
& self ,
226
288
rng : & mut R ,
227
- msg : & [ & [ u8 ] ] ,
289
+ msg : & [ u8 ] ,
228
290
) -> Result < S , Error > {
229
291
self . try_sign_with_rng ( rng, msg)
230
292
}
231
293
}
294
+
295
+ /// Equivalent of [`AsyncRandomizedSigner`] but the message is provided in non-contiguous byte slices.
296
+ #[ cfg( feature = "rand_core" ) ]
297
+ pub trait AsyncRandomizedMultiPartSigner < S > {
298
+ /// See [`AsyncRandomizedSigner::sign_with_rng_async()`].
299
+ async fn sign_with_rng_async < R : CryptoRng + ?Sized > ( & self , rng : & mut R , msg : & [ & [ u8 ] ] ) -> S {
300
+ self . try_sign_with_rng_async ( rng, msg)
301
+ . await
302
+ . expect ( "signature operation failed" )
303
+ }
304
+
305
+ /// See [`AsyncRandomizedSigner::try_sign_with_rng_async()`].
306
+ async fn try_sign_with_rng_async < R : TryCryptoRng + ?Sized > (
307
+ & self ,
308
+ rng : & mut R ,
309
+ msg : & [ & [ u8 ] ] ,
310
+ ) -> Result < S , Error > ;
311
+ }
0 commit comments