Skip to content

Commit 9e3f5ec

Browse files
committed
signature: use &[&[u8]] for messages
1 parent baf8d73 commit 9e3f5ec

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

async-signature/tests/mock_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct Signature;
1111
struct MockSigner;
1212

1313
impl AsyncSigner<Signature> for MockSigner {
14-
async fn sign_async(&self, _msg: &[u8]) -> Result<Signature, Error> {
14+
async fn sign_async(&self, _msg: &[&[u8]]) -> Result<Signature, Error> {
1515
unimplemented!("just meant to check compilation")
1616
}
1717
}
@@ -33,7 +33,7 @@ impl async_signature::AsyncRandomizedSigner<Signature> for MockSigner {
3333
>(
3434
&self,
3535
_rng: &mut R,
36-
_msg: &[u8],
36+
_msg: &[&[u8]],
3737
) -> Result<Signature, Error> {
3838
unimplemented!("just meant to check compilation")
3939
}

signature/src/signer.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::rand_core::{CryptoRng, TryCryptoRng};
1212
/// or connection to an HSM), returning a digital signature.
1313
pub 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,15 +21,15 @@ 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>;
24+
fn try_sign(&self, msg: &[&[u8]]) -> Result<S, Error>;
2525
}
2626

2727
/// Sign the provided message bytestring using `&mut Self` (e.g. an evolving
2828
/// cryptographic key such as a stateful hash-based signature), returning a
2929
/// digital signature.
3030
pub trait SignerMut<S> {
3131
/// Sign the given message, update the state, and return a digital signature.
32-
fn sign(&mut self, msg: &[u8]) -> S {
32+
fn sign(&mut self, msg: &[&[u8]]) -> S {
3333
self.try_sign(msg).expect("signature operation failed")
3434
}
3535

@@ -38,12 +38,12 @@ pub trait SignerMut<S> {
3838
///
3939
/// Signing can fail, e.g., if the number of time periods allowed by the
4040
/// current key is exceeded.
41-
fn try_sign(&mut self, msg: &[u8]) -> Result<S, Error>;
41+
fn try_sign(&mut self, msg: &[&[u8]]) -> Result<S, Error>;
4242
}
4343

4444
/// Blanket impl of [`SignerMut`] for all [`Signer`] types.
4545
impl<S, T: Signer<S>> SignerMut<S> for T {
46-
fn try_sign(&mut self, msg: &[u8]) -> Result<S, Error> {
46+
fn try_sign(&mut self, msg: &[&[u8]]) -> Result<S, Error> {
4747
T::try_sign(self, msg)
4848
}
4949
}
@@ -86,7 +86,7 @@ pub trait DigestSigner<D: Digest, S> {
8686
#[cfg(feature = "rand_core")]
8787
pub trait RandomizedSigner<S> {
8888
/// Sign the given message and return a digital signature
89-
fn sign_with_rng<R: CryptoRng + ?Sized>(&self, rng: &mut R, msg: &[u8]) -> S {
89+
fn sign_with_rng<R: CryptoRng + ?Sized>(&self, rng: &mut R, msg: &[&[u8]]) -> S {
9090
self.try_sign_with_rng(rng, msg)
9191
.expect("signature operation failed")
9292
}
@@ -99,7 +99,7 @@ pub trait RandomizedSigner<S> {
9999
fn try_sign_with_rng<R: TryCryptoRng + ?Sized>(
100100
&self,
101101
rng: &mut R,
102-
msg: &[u8],
102+
msg: &[&[u8]],
103103
) -> Result<S, Error>;
104104
}
105105

@@ -130,7 +130,7 @@ pub trait RandomizedDigestSigner<D: Digest, S> {
130130
#[cfg(feature = "rand_core")]
131131
pub trait RandomizedSignerMut<S> {
132132
/// 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 {
133+
fn sign_with_rng<R: CryptoRng + ?Sized>(&mut self, rng: &mut R, msg: &[&[u8]]) -> S {
134134
self.try_sign_with_rng(rng, msg)
135135
.expect("signature operation failed")
136136
}
@@ -143,7 +143,7 @@ pub trait RandomizedSignerMut<S> {
143143
fn try_sign_with_rng<R: TryCryptoRng + ?Sized>(
144144
&mut self,
145145
rng: &mut R,
146-
msg: &[u8],
146+
msg: &[&[u8]],
147147
) -> Result<S, Error>;
148148
}
149149

@@ -153,7 +153,7 @@ impl<S, T: RandomizedSigner<S>> RandomizedSignerMut<S> for T {
153153
fn try_sign_with_rng<R: TryCryptoRng + ?Sized>(
154154
&mut self,
155155
rng: &mut R,
156-
msg: &[u8],
156+
msg: &[&[u8]],
157157
) -> Result<S, Error> {
158158
T::try_sign_with_rng(self, rng, msg)
159159
}
@@ -169,14 +169,14 @@ pub trait AsyncSigner<S> {
169169
///
170170
/// The main intended use case for signing errors is when communicating
171171
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
172-
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error>;
172+
async fn sign_async(&self, msg: &[&[u8]]) -> Result<S, Error>;
173173
}
174174

175175
impl<S, T> AsyncSigner<S> for T
176176
where
177177
T: Signer<S>,
178178
{
179-
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error> {
179+
async fn sign_async(&self, msg: &[&[u8]]) -> Result<S, Error> {
180180
self.try_sign(msg)
181181
}
182182
}
@@ -198,7 +198,7 @@ where
198198
#[cfg(feature = "rand_core")]
199199
pub trait AsyncRandomizedSigner<S> {
200200
/// 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 {
201+
async fn sign_with_rng_async<R: CryptoRng + ?Sized>(&self, rng: &mut R, msg: &[&[u8]]) -> S {
202202
self.try_sign_with_rng_async(rng, msg)
203203
.await
204204
.expect("signature operation failed")
@@ -212,7 +212,7 @@ pub trait AsyncRandomizedSigner<S> {
212212
async fn try_sign_with_rng_async<R: TryCryptoRng + ?Sized>(
213213
&self,
214214
rng: &mut R,
215-
msg: &[u8],
215+
msg: &[&[u8]],
216216
) -> Result<S, Error>;
217217
}
218218

@@ -224,7 +224,7 @@ where
224224
async fn try_sign_with_rng_async<R: TryCryptoRng + ?Sized>(
225225
&self,
226226
rng: &mut R,
227-
msg: &[u8],
227+
msg: &[&[u8]],
228228
) -> Result<S, Error> {
229229
self.try_sign_with_rng(rng, msg)
230230
}

signature/src/verifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub trait Verifier<S> {
1111
/// bytestring is authentic.
1212
///
1313
/// Returns `Error` if it is inauthentic, or otherwise returns `()`.
14-
fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error>;
14+
fn verify(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error>;
1515
}
1616

1717
/// Verify the provided signature for the given prehashed message [`Digest`]

0 commit comments

Comments
 (0)