Skip to content

Commit ac54439

Browse files
authored
Revert "signature: replace signature_derive with blanket impls (#1827)" (#1840)
This reverts commit bf47748. Per #1831 this change breaks inference when there is a single explicit impl of the `Signer` trait. It also wasn't possible to add corresponding blanket impls to the `Async*` traits, e.g. `AsyncSigner` for `AsyncDigestSigner`, because of the existing blanket impl of `AsyncSigner` for `Signer` which we definitely want to preserve. As a general rule of thumb, blanket impls only make sense if they work 100% of the time, which doesn't seem to be happening here. Closes #1831
1 parent 622b6c0 commit ac54439

17 files changed

Lines changed: 887 additions & 57 deletions

File tree

.github/workflows/signature.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ jobs:
3737
toolchain: ${{ matrix.rust }}
3838
targets: ${{ matrix.target }}
3939
- run: cargo build --target ${{ matrix.target }} --release --no-default-features
40-
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features digest
40+
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features derive
4141
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features rand_core
42+
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features derive,rand_core
4243

4344
minimal-versions:
4445
if: false # disabled until we stop using pre-releases
@@ -51,7 +52,7 @@ jobs:
5152
strategy:
5253
matrix:
5354
rust:
54-
- 1.85.0 # MSRV
55+
- 1.85.0 # Minimum Rust version the tests pass on
5556
- stable
5657
steps:
5758
- uses: actions/checkout@v4
@@ -62,3 +63,19 @@ jobs:
6263
- run: cargo test --release --no-default-features
6364
- run: cargo test --release
6465
- run: cargo test --release --all-features
66+
67+
derive:
68+
runs-on: ubuntu-latest
69+
strategy:
70+
matrix:
71+
rust:
72+
- 1.85.0 # MSRV
73+
- stable
74+
steps:
75+
- uses: actions/checkout@v4
76+
- uses: RustCrypto/actions/cargo-cache@master
77+
- uses: dtolnay/rust-toolchain@master
78+
with:
79+
toolchain: ${{ matrix.rust }}
80+
- run: cargo test --release
81+
working-directory: signature_derive

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"elliptic-curve",
1111
"kem",
1212
"password-hash",
13+
"signature_derive",
1314
"universal-hash",
1415
"signature",
1516
]

async-signature/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ categories = ["cryptography", "no-std"]
1313
description = "Traits for cryptographic signature algorithms (e.g. ECDSA, Ed25519)"
1414

1515
[dependencies]
16-
signature = "=2.3.0-pre.7"
16+
signature = "=3.0.0-pre"
1717

1818
[features]
1919
digest = ["signature/digest"]
20-
std = ["signature/std"]
20+
std = []
2121
rand_core = ["signature/rand_core"]
2222

2323
[package.metadata.docs.rs]

crypto/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cipher = { version = "0.5.0-pre.7", path = "../cipher", optional = true }
2121
digest = { version = "0.11.0-pre.9", path = "../digest", optional = true, features = ["mac"] }
2222
elliptic-curve = { version = "0.14.0-rc.1", path = "../elliptic-curve", optional = true }
2323
password-hash = { version = "0.6.0-rc.0", path = "../password-hash", optional = true }
24-
signature = { version = "3.0.0-pre", path = "../signature", optional = true, default-features = false }
24+
signature = { version = "=3.0.0-pre", path = "../signature", optional = true, default-features = false }
2525
universal-hash = { version = "0.6.0-rc.0", path = "../universal-hash", optional = true }
2626

2727
[features]

signature/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ categories = ["cryptography", "no-std"]
1313
description = "Traits for cryptographic signature algorithms (e.g. ECDSA, Ed25519)"
1414

1515
[dependencies]
16+
derive = { package = "signature_derive", version = "2", optional = true, path = "../signature_derive" }
1617
digest = { version = "=0.11.0-pre.10", optional = true, default-features = false }
1718
rand_core = { version = "0.9", optional = true, default-features = false }
1819

signature/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ mod prehash_signature;
145145

146146
pub use crate::{encoding::*, error::*, keypair::*, signer::*, verifier::*};
147147

148+
#[cfg(feature = "derive")]
149+
pub use derive::{Signer, Verifier};
150+
151+
#[cfg(all(feature = "derive", feature = "digest"))]
152+
pub use derive::{DigestSigner, DigestVerifier};
153+
148154
#[cfg(feature = "digest")]
149155
pub use {crate::prehash_signature::*, digest};
150156

signature/src/prehash_signature.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ use crate::{
1919
/// This approach is relatively common in signature schemes based on the
2020
/// [Fiat-Shamir heuristic].
2121
///
22-
/// For signature types that implement this trait, a blanket impl of the [`Signer`] trait is
23-
/// available for any types that impl [`DigestSigner`], and likewise for the [`Verifier`] for
22+
/// For signature types that implement this trait, when the `derive` crate
23+
/// feature is enabled a custom derive for [`Signer`] is available for any
24+
/// types that impl [`DigestSigner`], and likewise for deriving [`Verifier`] for
2425
/// types which impl [`DigestVerifier`].
2526
///
2627
/// [Fiat-Shamir heuristic]: https://en.wikipedia.org/wiki/Fiat%E2%80%93Shamir_heuristic

signature/src/signer.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::error::Error;
44

55
#[cfg(feature = "digest")]
6-
use crate::{PrehashSignature, digest::Digest};
6+
use crate::digest::Digest;
77

88
#[cfg(feature = "rand_core")]
99
use crate::rand_core::{CryptoRng, TryCryptoRng};
@@ -82,17 +82,6 @@ pub trait DigestSigner<D: Digest, S> {
8282
fn try_sign_digest(&self, digest: D) -> Result<S, Error>;
8383
}
8484

85-
#[cfg(feature = "digest")]
86-
impl<S, T> Signer<S> for T
87-
where
88-
S: PrehashSignature,
89-
T: DigestSigner<S::Digest, S>,
90-
{
91-
fn try_sign(&self, msg: &[u8]) -> Result<S, Error> {
92-
self.try_sign_digest(S::Digest::new_with_prefix(msg))
93-
}
94-
}
95-
9685
/// Sign the given message using the provided external randomness source.
9786
#[cfg(feature = "rand_core")]
9887
pub trait RandomizedSigner<S> {
@@ -135,21 +124,6 @@ pub trait RandomizedDigestSigner<D: Digest, S> {
135124
) -> Result<S, Error>;
136125
}
137126

138-
#[cfg(all(feature = "digest", feature = "rand_core"))]
139-
impl<S, T> RandomizedSigner<S> for T
140-
where
141-
S: PrehashSignature,
142-
T: RandomizedDigestSigner<S::Digest, S>,
143-
{
144-
fn try_sign_with_rng<R: TryCryptoRng + ?Sized>(
145-
&self,
146-
rng: &mut R,
147-
msg: &[u8],
148-
) -> Result<S, Error> {
149-
self.try_sign_digest_with_rng(rng, S::Digest::new_with_prefix(msg))
150-
}
151-
}
152-
153127
/// Sign the provided message bytestring using `&mut Self` (e.g. an evolving
154128
/// cryptographic key such as a stateful hash-based signature), and a per-signature
155129
/// randomizer, returning a digital signature.

signature/src/verifier.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::error::Error;
44

55
#[cfg(feature = "digest")]
6-
use crate::{PrehashSignature, digest::Digest};
6+
use crate::digest::Digest;
77

88
/// Verify the provided message bytestring using `Self` (e.g. a public key)
99
pub trait Verifier<S> {
@@ -39,14 +39,3 @@ pub trait DigestVerifier<D: Digest, S> {
3939
/// Verify the signature against the given [`Digest`] output.
4040
fn verify_digest(&self, digest: D, signature: &S) -> Result<(), Error>;
4141
}
42-
43-
#[cfg(feature = "digest")]
44-
impl<S, T> Verifier<S> for T
45-
where
46-
S: PrehashSignature,
47-
T: DigestVerifier<S::Digest, S>,
48-
{
49-
fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error> {
50-
self.verify_digest(S::Digest::new_with_prefix(msg), signature)
51-
}
52-
}

0 commit comments

Comments
 (0)