Skip to content

Commit 5cb62a4

Browse files
authored
signature: enable/fix workspace-level lints; reformat docs (#2391)
Note: lint config was added in #2270
1 parent 375378f commit 5cb62a4

6 files changed

Lines changed: 213 additions & 158 deletions

File tree

signature/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ rand_core = { version = "0.10", optional = true, default-features = false }
2020
alloc = []
2121
rand_core = ["dep:rand_core"]
2222

23+
[lints]
24+
workspace = true
25+
2326
[package.metadata.docs.rs]
2427
all-features = true

signature/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub struct Error {
3030

3131
impl Error {
3232
/// Create a new error with no associated source
33+
#[must_use]
3334
pub fn new() -> Self {
3435
Self::default()
3536
}
@@ -90,6 +91,7 @@ impl core::error::Error for Error {
9091
None
9192
}
9293
#[cfg(feature = "alloc")]
94+
#[allow(trivial_casts)]
9395
{
9496
self.source
9597
.as_ref()

signature/src/hazmat.rs

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
//! Hazardous Materials: low-level APIs which can be insecure if misused.
22
//!
3-
//! The traits in this module are not generally recommended, and should only be
4-
//! used in special cases where they are specifically needed.
3+
//! The traits in this module are not generally recommended, and should only be used in special
4+
//! cases where they are specifically needed.
55
//!
6-
//! Using them incorrectly can introduce security vulnerabilities. Please
7-
//! carefully read the documentation before attempting to use them.
6+
//! <div class = "warning">
7+
//! <b>Security Warning</b>
8+
//!
9+
//! Using these traits incorrectly can introduce security vulnerabilities. Please carefully read the
10+
//! documentation before attempting to use them.
11+
//! </div>
812
913
use crate::Error;
1014

@@ -13,36 +17,38 @@ use crate::rand_core::TryCryptoRng;
1317

1418
/// Sign the provided message prehash, returning a digital signature.
1519
pub trait PrehashSigner<S> {
16-
/// Attempt to sign the given message digest, returning a digital signature
17-
/// on success, or an error if something went wrong.
20+
/// Attempt to sign the given message digest, returning a digital signature on success, or an
21+
/// error if something went wrong.
22+
///
23+
/// The `prehash` parameter should be the output of a secure cryptographic hash function.
1824
///
19-
/// The `prehash` parameter should be the output of a secure cryptographic
20-
/// hash function.
25+
/// This API takes a `prehash` byte slice as there can potentially be many compatible lengths
26+
/// for the message digest for a given concrete signature algorithm.
2127
///
22-
/// This API takes a `prehash` byte slice as there can potentially be many
23-
/// compatible lengths for the message digest for a given concrete signature
24-
/// algorithm.
28+
/// Allowed lengths are algorithm-dependent and up to a particular implementation to decide.
2529
///
26-
/// Allowed lengths are algorithm-dependent and up to a particular
27-
/// implementation to decide.
30+
/// # Errors
31+
/// Returns [`Error`] in the event `prehash` is an invalid length.
2832
fn sign_prehash(&self, prehash: &[u8]) -> Result<S, Error>;
2933
}
3034

31-
/// Sign the provided message prehash using the provided external randomness source, returning a digital signature.
35+
/// Sign the provided message prehash using the provided external randomness source, returning a
36+
/// digital signature.
3237
#[cfg(feature = "rand_core")]
3338
pub trait RandomizedPrehashSigner<S> {
34-
/// Attempt to sign the given message digest, returning a digital signature
35-
/// on success, or an error if something went wrong.
39+
/// Attempt to sign the given message digest, returning a digital signature on success, or an
40+
/// error if something went wrong.
3641
///
37-
/// The `prehash` parameter should be the output of a secure cryptographic
38-
/// hash function.
42+
/// The `prehash` parameter should be the output of a secure cryptographic hash function.
3943
///
40-
/// This API takes a `prehash` byte slice as there can potentially be many
41-
/// compatible lengths for the message digest for a given concrete signature
42-
/// algorithm.
44+
/// This API takes a `prehash` byte slice as there can potentially be many compatible lengths
45+
/// for the message digest for a given concrete signature algorithm.
4346
///
44-
/// Allowed lengths are algorithm-dependent and up to a particular
45-
/// implementation to decide.
47+
/// Allowed lengths are algorithm-dependent and up to a particular implementation to decide.
48+
///
49+
/// # Errors
50+
/// Returns [`Error`] in the event `prehash` is an invalid length, or if an internal error
51+
/// in the provided `rng` occurs.
4652
fn sign_prehash_with_rng<R: TryCryptoRng + ?Sized>(
4753
&self,
4854
rng: &mut R,
@@ -52,57 +58,54 @@ pub trait RandomizedPrehashSigner<S> {
5258

5359
/// Verify the provided message prehash using `Self` (e.g. a public key)
5460
pub trait PrehashVerifier<S> {
55-
/// Use `Self` to verify that the provided signature for a given message
56-
/// `prehash` is authentic.
61+
/// Use `Self` to verify that the provided signature for a given message `prehash` is authentic.
62+
///
63+
/// The `prehash` parameter MUST be the output of a secure cryptographic hash function.
5764
///
58-
/// The `prehash` parameter should be the output of a secure cryptographic
59-
/// hash function.
65+
/// <div class="warning">
66+
/// <b>Security Warning</b>
6067
///
61-
/// Returns `Error` if it is inauthentic or some other error occurred, or
62-
/// otherwise returns `Ok(())`.
68+
/// If `prehash` is something other than the output of a cryptographically secure hash function,
69+
/// an attacker can potentially forge signatures by e.g. solving a system of linear equations.
70+
/// </div>
6371
///
64-
/// # ⚠️ Security Warning
72+
/// Returns `Ok(())` if the signature verified successfully.
6573
///
66-
/// If `prehash` is something other than the output of a cryptographically
67-
/// secure hash function, an attacker can potentially forge signatures by
68-
/// solving a system of linear equations.
74+
/// # Errors
75+
/// Returns [`Error`] in the event the signature fails to verify or if `prehash` is an invalid
76+
/// length.
6977
fn verify_prehash(&self, prehash: &[u8], signature: &S) -> Result<(), Error>;
7078
}
7179

7280
/// Asynchronously sign the provided message prehash, returning a digital signature.
7381
#[allow(async_fn_in_trait)]
7482
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.
83+
/// Attempt to sign the given message digest, returning a digital signature on success, or an
84+
/// error if something went wrong.
7785
///
78-
/// The `prehash` parameter should be the output of a secure cryptographic
79-
/// hash function.
86+
/// The `prehash` parameter should be the output of a secure cryptographic hash function.
8087
///
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.
88+
/// This API takes a `prehash` byte slice as there can potentially be many compatible lengths
89+
/// for the message digest for a given concrete signature algorithm.
8490
///
85-
/// Allowed lengths are algorithm-dependent and up to a particular
86-
/// implementation to decide.
91+
/// Allowed lengths are algorithm-dependent and up to a particular implementation to decide.
8792
async fn sign_prehash_async(&self, prehash: &[u8]) -> Result<S, Error>;
8893
}
8994

90-
/// Asynchronously sign the provided message prehash using the provided external randomness source, returning a digital signature.
95+
/// Asynchronously sign the provided message prehash using the provided external randomness source,
96+
/// returning a digital signature.
9197
#[cfg(feature = "rand_core")]
9298
#[allow(async_fn_in_trait)]
9399
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.
100+
/// Attempt to sign the given message digest, returning a digital signature on success, or an
101+
/// error if something went wrong.
96102
///
97-
/// The `prehash` parameter should be the output of a secure cryptographic
98-
/// hash function.
103+
/// The `prehash` parameter should be the output of a secure cryptographic hash function.
99104
///
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.
105+
/// This API takes a `prehash` byte slice as there can potentially be many compatible lengths
106+
/// for the message digest for a given concrete signature algorithm.
103107
///
104-
/// Allowed lengths are algorithm-dependent and up to a particular
105-
/// implementation to decide.
108+
/// Allowed lengths are algorithm-dependent and up to a particular implementation to decide.
106109
async fn sign_prehash_with_rng_async<R: TryCryptoRng + ?Sized>(
107110
&self,
108111
rng: &mut R,

signature/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
)]
88
#![forbid(unsafe_code)]
99
#![allow(async_fn_in_trait)]
10-
#![warn(
11-
clippy::mod_module_files,
12-
clippy::unwrap_used,
13-
missing_docs,
14-
rust_2018_idioms,
15-
unused_lifetimes,
16-
missing_debug_implementations,
17-
unused_qualifications
18-
)]
1910

2011
//! # Design
2112
//!

0 commit comments

Comments
 (0)