@@ -101,9 +101,13 @@ use {
101
101
} ;
102
102
103
103
#[ 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 ,
107
111
} ;
108
112
109
113
#[ cfg( feature = "pkcs8" ) ]
@@ -463,10 +467,10 @@ where
463
467
///
464
468
/// To support non-default digest algorithms, use the [`SignatureWithOid`]
465
469
/// type instead.
466
- #[ cfg( all ( feature = "digest" , feature = "hazmat" ) ) ]
470
+ #[ cfg( feature = "digest" ) ]
467
471
impl < C > AssociatedOid for Signature < C >
468
472
where
469
- C : hazmat :: DigestPrimitive ,
473
+ C : DigestPrimitive ,
470
474
C :: Digest : AssociatedOid ,
471
475
{
472
476
const OID : ObjectIdentifier = match ecdsa_oid_for_digest ( C :: Digest :: OID ) {
@@ -713,29 +717,29 @@ where
713
717
}
714
718
715
719
/// NOTE: this implementation assumes the default digest for the given elliptic
716
- /// curve as defined by [`hazmat:: DigestPrimitive`].
720
+ /// curve as defined by [`DigestPrimitive`].
717
721
///
718
722
/// When working with alternative digests, you will need to use e.g.
719
723
/// [`SignatureWithOid::new_with_digest`].
720
- #[ cfg( all ( feature = "digest" , feature = "hazmat" ) ) ]
724
+ #[ cfg( feature = "digest" ) ]
721
725
impl < C > SignatureEncoding for SignatureWithOid < C >
722
726
where
723
- C : hazmat :: DigestPrimitive ,
727
+ C : DigestPrimitive ,
724
728
C :: Digest : AssociatedOid ,
725
729
SignatureSize < C > : ArraySize ,
726
730
{
727
731
type Repr = SignatureBytes < C > ;
728
732
}
729
733
730
734
/// NOTE: this implementation assumes the default digest for the given elliptic
731
- /// curve as defined by [`hazmat:: DigestPrimitive`].
735
+ /// curve as defined by [`DigestPrimitive`].
732
736
///
733
737
/// When working with alternative digests, you will need to use e.g.
734
738
/// [`SignatureWithOid::new_with_digest`].
735
- #[ cfg( all ( feature = "digest" , feature = "hazmat" ) ) ]
739
+ #[ cfg( feature = "digest" ) ]
736
740
impl < C > TryFrom < & [ u8 ] > for SignatureWithOid < C >
737
741
where
738
- C : hazmat :: DigestPrimitive ,
742
+ C : DigestPrimitive ,
739
743
C :: Digest : AssociatedOid ,
740
744
SignatureSize < C > : ArraySize ,
741
745
{
@@ -770,3 +774,29 @@ const fn ecdsa_oid_for_digest(digest_oid: ObjectIdentifier) -> Option<ObjectIden
770
774
_ => None ,
771
775
}
772
776
}
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
+ }
0 commit comments