@@ -12,7 +12,7 @@ use crate::rand_core::{CryptoRng, TryCryptoRng};
1212/// or connection to an HSM), returning a digital signature.
1313pub trait Signer < S > {
1414 /// Sign the given message and return a digital signature
15- fn sign ( & self , msg : & [ & [ u8 ] ] ) -> S {
15+ fn sign ( & self , msg : & [ u8 ] ) -> S {
1616 self . try_sign ( msg) . expect ( "signature operation failed" )
1717 }
1818
@@ -21,6 +21,17 @@ pub trait Signer<S> {
2121 ///
2222 /// The main intended use case for signing errors is when communicating
2323 /// 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()`].
2435 fn try_sign ( & self , msg : & [ & [ u8 ] ] ) -> Result < S , Error > ;
2536}
2637
@@ -29,7 +40,7 @@ pub trait Signer<S> {
2940/// digital signature.
3041pub trait SignerMut < S > {
3142 /// 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 {
3344 self . try_sign ( msg) . expect ( "signature operation failed" )
3445 }
3546
@@ -38,16 +49,27 @@ pub trait SignerMut<S> {
3849 ///
3950 /// Signing can fail, e.g., if the number of time periods allowed by the
4051 /// 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 > ;
4253}
4354
4455/// Blanket impl of [`SignerMut`] for all [`Signer`] types.
4556impl < 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 > {
4758 T :: try_sign ( self , msg)
4859 }
4960}
5061
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+
5173/// Sign the given prehashed message [`Digest`] using `Self`.
5274///
5375/// ## Notes
@@ -86,7 +108,7 @@ pub trait DigestSigner<D: Digest, S> {
86108#[ cfg( feature = "rand_core" ) ]
87109pub trait RandomizedSigner < S > {
88110 /// 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 {
90112 self . try_sign_with_rng ( rng, msg)
91113 . expect ( "signature operation failed" )
92114 }
@@ -96,6 +118,23 @@ pub trait RandomizedSigner<S> {
96118 ///
97119 /// The main intended use case for signing errors is when communicating
98120 /// 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()`].
99138 fn try_sign_with_rng < R : TryCryptoRng + ?Sized > (
100139 & self ,
101140 rng : & mut R ,
@@ -130,7 +169,7 @@ pub trait RandomizedDigestSigner<D: Digest, S> {
130169#[ cfg( feature = "rand_core" ) ]
131170pub trait RandomizedSignerMut < S > {
132171 /// 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 {
134173 self . try_sign_with_rng ( rng, msg)
135174 . expect ( "signature operation failed" )
136175 }
@@ -143,7 +182,7 @@ pub trait RandomizedSignerMut<S> {
143182 fn try_sign_with_rng < R : TryCryptoRng + ?Sized > (
144183 & mut self ,
145184 rng : & mut R ,
146- msg : & [ & [ u8 ] ] ,
185+ msg : & [ u8 ] ,
147186 ) -> Result < S , Error > ;
148187}
149188
@@ -153,12 +192,29 @@ impl<S, T: RandomizedSigner<S>> RandomizedSignerMut<S> for T {
153192 fn try_sign_with_rng < R : TryCryptoRng + ?Sized > (
154193 & mut self ,
155194 rng : & mut R ,
156- msg : & [ & [ u8 ] ] ,
195+ msg : & [ u8 ] ,
157196 ) -> Result < S , Error > {
158197 T :: try_sign_with_rng ( self , rng, msg)
159198 }
160199}
161200
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+
162218/// Asynchronously sign the provided message bytestring using `Self`
163219/// (e.g. client for a Cloud KMS or HSM), returning a digital signature.
164220///
@@ -169,18 +225,24 @@ pub trait AsyncSigner<S> {
169225 ///
170226 /// The main intended use case for signing errors is when communicating
171227 /// 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 > ;
173229}
174230
175231impl < S , T > AsyncSigner < S > for T
176232where
177233 T : Signer < S > ,
178234{
179- async fn sign_async ( & self , msg : & [ & [ u8 ] ] ) -> Result < S , Error > {
235+ async fn sign_async ( & self , msg : & [ u8 ] ) -> Result < S , Error > {
180236 self . try_sign ( msg)
181237 }
182238}
183239
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+
184246/// Asynchronously sign the given prehashed message [`Digest`] using `Self`.
185247///
186248/// This trait is an async equivalent of the [`DigestSigner`] trait.
@@ -198,7 +260,7 @@ where
198260#[ cfg( feature = "rand_core" ) ]
199261pub trait AsyncRandomizedSigner < S > {
200262 /// 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 {
202264 self . try_sign_with_rng_async ( rng, msg)
203265 . await
204266 . expect ( "signature operation failed" )
@@ -212,7 +274,7 @@ pub trait AsyncRandomizedSigner<S> {
212274 async fn try_sign_with_rng_async < R : TryCryptoRng + ?Sized > (
213275 & self ,
214276 rng : & mut R ,
215- msg : & [ & [ u8 ] ] ,
277+ msg : & [ u8 ] ,
216278 ) -> Result < S , Error > ;
217279}
218280
@@ -224,8 +286,26 @@ where
224286 async fn try_sign_with_rng_async < R : TryCryptoRng + ?Sized > (
225287 & self ,
226288 rng : & mut R ,
227- msg : & [ & [ u8 ] ] ,
289+ msg : & [ u8 ] ,
228290 ) -> Result < S , Error > {
229291 self . try_sign_with_rng ( rng, msg)
230292 }
231293}
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