Skip to content

Commit 1a6f687

Browse files
committed
ecdsa: Signer would only be implemented with hazmat
1 parent 37b1204 commit 1a6f687

6 files changed

Lines changed: 55 additions & 53 deletions

File tree

ecdsa/src/der.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,10 @@ fn find_scalar_range(outer: &[u8], inner: &[u8]) -> Result<Range<usize>> {
382382
Ok(Range { start, end })
383383
}
384384

385-
#[cfg(all(feature = "digest", feature = "hazmat"))]
385+
#[cfg(feature = "digest")]
386386
impl<C> signature::PrehashSignature for Signature<C>
387387
where
388-
C: EcdsaCurve + crate::hazmat::DigestPrimitive,
388+
C: EcdsaCurve + crate::DigestPrimitive,
389389
MaxSize<C>: ArraySize,
390390
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
391391
{

ecdsa/src/hazmat.rs

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,19 @@ use {
2828
};
2929

3030
#[cfg(feature = "digest")]
31-
use {
32-
elliptic_curve::FieldBytesSize,
33-
signature::{
34-
PrehashSignature,
35-
digest::{Digest, FixedOutput, FixedOutputReset, core_api::BlockSizeUser},
36-
},
37-
};
31+
use signature::digest::{Digest, FixedOutput, FixedOutputReset, core_api::BlockSizeUser};
3832

3933
#[cfg(feature = "rfc6979")]
4034
use elliptic_curve::FieldBytesEncoding;
4135

4236
#[cfg(any(feature = "arithmetic", feature = "digest"))]
4337
use crate::{Signature, elliptic_curve::array::ArraySize};
4438

45-
/// Bind a preferred [`Digest`] algorithm to an elliptic curve type.
46-
///
47-
/// Generally there is a preferred variety of the SHA-2 family used with ECDSA
48-
/// for a particular elliptic curve.
49-
///
50-
/// This trait can be used to specify it, and with it receive a blanket impl of
51-
/// [`PrehashSignature`], used by [`signature_derive`][1]) for the [`Signature`]
52-
/// type for a particular elliptic curve.
53-
///
54-
/// [1]: https://github.com/RustCrypto/traits/tree/master/signature/derive
55-
#[cfg(feature = "digest")]
56-
pub trait DigestPrimitive: EcdsaCurve {
57-
/// Preferred digest to use when computing ECDSA signatures for this
58-
/// elliptic curve. This is typically a member of the SHA-2 family.
59-
type Digest: BlockSizeUser + Digest + FixedOutput + FixedOutputReset;
60-
}
61-
62-
#[cfg(feature = "digest")]
63-
impl<C> PrehashSignature for Signature<C>
64-
where
65-
C: DigestPrimitive,
66-
<FieldBytesSize<C> as core::ops::Add>::Output: ArraySize,
67-
{
68-
type Digest = C::Digest;
69-
}
39+
#[deprecated(
40+
since = "0.17.0",
41+
note = "`DigestPrimitive` is no longer in `hazmat`, please use `ecdsa::DigestPrimitive` instead"
42+
)]
43+
pub use crate::DigestPrimitive;
7044

7145
/// Partial implementation of the `bits2int` function as defined in
7246
/// [RFC6979 § 2.3.2] as well as [SEC1] § 2.3.8.

ecdsa/src/lib.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ use {
101101
};
102102

103103
#[cfg(feature = "digest")]
104-
use digest::{
105-
Digest,
106-
const_oid::{AssociatedOid, ObjectIdentifier},
104+
use {
105+
digest::{
106+
Digest, FixedOutput, FixedOutputReset,
107+
const_oid::{AssociatedOid, ObjectIdentifier},
108+
core_api::BlockSizeUser,
109+
},
110+
signature::PrehashSignature,
107111
};
108112

109113
#[cfg(feature = "pkcs8")]
@@ -463,10 +467,10 @@ where
463467
///
464468
/// To support non-default digest algorithms, use the [`SignatureWithOid`]
465469
/// type instead.
466-
#[cfg(all(feature = "digest", feature = "hazmat"))]
470+
#[cfg(feature = "digest")]
467471
impl<C> AssociatedOid for Signature<C>
468472
where
469-
C: hazmat::DigestPrimitive,
473+
C: DigestPrimitive,
470474
C::Digest: AssociatedOid,
471475
{
472476
const OID: ObjectIdentifier = match ecdsa_oid_for_digest(C::Digest::OID) {
@@ -713,29 +717,29 @@ where
713717
}
714718

715719
/// NOTE: this implementation assumes the default digest for the given elliptic
716-
/// curve as defined by [`hazmat::DigestPrimitive`].
720+
/// curve as defined by [`DigestPrimitive`].
717721
///
718722
/// When working with alternative digests, you will need to use e.g.
719723
/// [`SignatureWithOid::new_with_digest`].
720-
#[cfg(all(feature = "digest", feature = "hazmat"))]
724+
#[cfg(feature = "digest")]
721725
impl<C> SignatureEncoding for SignatureWithOid<C>
722726
where
723-
C: hazmat::DigestPrimitive,
727+
C: DigestPrimitive,
724728
C::Digest: AssociatedOid,
725729
SignatureSize<C>: ArraySize,
726730
{
727731
type Repr = SignatureBytes<C>;
728732
}
729733

730734
/// NOTE: this implementation assumes the default digest for the given elliptic
731-
/// curve as defined by [`hazmat::DigestPrimitive`].
735+
/// curve as defined by [`DigestPrimitive`].
732736
///
733737
/// When working with alternative digests, you will need to use e.g.
734738
/// [`SignatureWithOid::new_with_digest`].
735-
#[cfg(all(feature = "digest", feature = "hazmat"))]
739+
#[cfg(feature = "digest")]
736740
impl<C> TryFrom<&[u8]> for SignatureWithOid<C>
737741
where
738-
C: hazmat::DigestPrimitive,
742+
C: DigestPrimitive,
739743
C::Digest: AssociatedOid,
740744
SignatureSize<C>: ArraySize,
741745
{
@@ -770,3 +774,29 @@ const fn ecdsa_oid_for_digest(digest_oid: ObjectIdentifier) -> Option<ObjectIden
770774
_ => None,
771775
}
772776
}
777+
778+
/// Bind a preferred [`Digest`] algorithm to an elliptic curve type.
779+
///
780+
/// Generally there is a preferred variety of the SHA-2 family used with ECDSA
781+
/// for a particular elliptic curve.
782+
///
783+
/// This trait can be used to specify it, and with it receive a blanket impl of
784+
/// [`PrehashSignature`], used by [`signature_derive`][1]) for the [`Signature`]
785+
/// type for a particular elliptic curve.
786+
///
787+
/// [1]: https://github.com/RustCrypto/traits/tree/master/signature/derive
788+
#[cfg(feature = "digest")]
789+
pub trait DigestPrimitive: EcdsaCurve {
790+
/// Preferred digest to use when computing ECDSA signatures for this
791+
/// elliptic curve. This is typically a member of the SHA-2 family.
792+
type Digest: BlockSizeUser + Digest + FixedOutput + FixedOutputReset;
793+
}
794+
795+
#[cfg(feature = "digest")]
796+
impl<C> PrehashSignature for Signature<C>
797+
where
798+
C: DigestPrimitive,
799+
<FieldBytesSize<C> as Add>::Output: ArraySize,
800+
{
801+
type Digest = C::Digest;
802+
}

ecdsa/src/recovery.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ use {
2828

2929
#[cfg(any(feature = "signing", feature = "verifying"))]
3030
use {
31-
crate::{
32-
EcdsaCurve, Signature, SignatureSize,
33-
hazmat::{DigestPrimitive, bits2field},
34-
},
31+
crate::{DigestPrimitive, EcdsaCurve, Signature, SignatureSize, hazmat::bits2field},
3532
elliptic_curve::{CurveArithmetic, Scalar, array::ArraySize, ops::Invert},
3633
signature::digest::Digest,
3734
};

ecdsa/src/signing.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! ECDSA signing: producing signatures using a [`SigningKey`].
22
33
use crate::{
4-
EcdsaCurve, Error, Result, Signature, SignatureSize, SignatureWithOid, ecdsa_oid_for_digest,
5-
hazmat::{DigestPrimitive, bits2field, sign_prehashed_rfc6979},
4+
DigestPrimitive, EcdsaCurve, Error, Result, Signature, SignatureSize, SignatureWithOid,
5+
ecdsa_oid_for_digest,
6+
hazmat::{bits2field, sign_prehashed_rfc6979},
67
};
78
use core::fmt::{self, Debug};
89
use digest::{Digest, FixedOutput, const_oid::AssociatedOid};

ecdsa/src/verifying.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! ECDSA verifying: checking signatures are authentic using a [`VerifyingKey`].
22
33
use crate::{
4-
EcdsaCurve, Error, Result, Signature, SignatureSize,
5-
hazmat::{self, DigestPrimitive, bits2field},
4+
DigestPrimitive, EcdsaCurve, Error, Result, Signature, SignatureSize,
5+
hazmat::{self, bits2field},
66
};
77
use core::{cmp::Ordering, fmt::Debug};
88
use elliptic_curve::{

0 commit comments

Comments
 (0)