@@ -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,15 +467,15 @@ 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" ) ]
467471impl < C > AssociatedOid for Signature < C >
468472where
469- C : hazmat :: DigestPrimitive ,
473+ C : DigestAlgorithm ,
470474 C :: Digest : AssociatedOid ,
471475{
472476 const OID : ObjectIdentifier = match ecdsa_oid_for_digest ( C :: Digest :: OID ) {
473477 Some ( oid) => oid,
474- None => panic ! ( "no RFC5758 ECDSA OID defined for DigestPrimitive ::Digest" ) ,
478+ None => panic ! ( "no RFC5758 ECDSA OID defined for DigestAlgorithm ::Digest" ) ,
475479 } ;
476480}
477481
@@ -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 [`DigestAlgorithm `].
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" ) ]
721725impl < C > SignatureEncoding for SignatureWithOid < C >
722726where
723- C : hazmat :: DigestPrimitive ,
727+ C : DigestAlgorithm ,
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 [`DigestAlgorithm `].
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" ) ]
736740impl < C > TryFrom < & [ u8 ] > for SignatureWithOid < C >
737741where
738- C : hazmat :: DigestPrimitive ,
742+ C : DigestAlgorithm ,
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 DigestAlgorithm : 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 : DigestAlgorithm ,
799+ <FieldBytesSize < C > as Add >:: Output : ArraySize ,
800+ {
801+ type Digest = C :: Digest ;
802+ }
0 commit comments