@@ -12,7 +12,10 @@ use core::fmt::{Debug, Display, Formatter, LowerHex, UpperHex};
12
12
use core:: marker:: PhantomData ;
13
13
use digest:: Digest ;
14
14
use pkcs8:: {
15
- spki:: { der:: AnyRef , AlgorithmIdentifierRef , AssociatedAlgorithmIdentifier } ,
15
+ spki:: {
16
+ der:: AnyRef , AlgorithmIdentifierRef , AssociatedAlgorithmIdentifier ,
17
+ SignatureAlgorithmIdentifier ,
18
+ } ,
16
19
AssociatedOid , Document , EncodePrivateKey , EncodePublicKey , SecretDocument ,
17
20
} ;
18
21
use rand_core:: CryptoRngCore ;
@@ -448,6 +451,19 @@ where
448
451
const ALGORITHM_IDENTIFIER : AlgorithmIdentifierRef < ' static > = pkcs1:: ALGORITHM_ID ;
449
452
}
450
453
454
+ impl < D > SignatureAlgorithmIdentifier for SigningKey < D >
455
+ where
456
+ D : Digest + oid:: RsaSignatureAssociatedOid ,
457
+ {
458
+ type Params = AnyRef < ' static > ;
459
+
460
+ const SIGNATURE_ALGORITHM_IDENTIFIER : AlgorithmIdentifierRef < ' static > =
461
+ AlgorithmIdentifierRef {
462
+ oid : D :: OID ,
463
+ parameters : Some ( AnyRef :: NULL ) ,
464
+ } ;
465
+ }
466
+
451
467
impl < D > From < RsaPrivateKey > for SigningKey < D >
452
468
where
453
469
D : Digest ,
@@ -627,6 +643,19 @@ where
627
643
const ALGORITHM_IDENTIFIER : AlgorithmIdentifierRef < ' static > = pkcs1:: ALGORITHM_ID ;
628
644
}
629
645
646
+ impl < D > SignatureAlgorithmIdentifier for VerifyingKey < D >
647
+ where
648
+ D : Digest + oid:: RsaSignatureAssociatedOid ,
649
+ {
650
+ type Params = AnyRef < ' static > ;
651
+
652
+ const SIGNATURE_ALGORITHM_IDENTIFIER : AlgorithmIdentifierRef < ' static > =
653
+ AlgorithmIdentifierRef {
654
+ oid : D :: OID ,
655
+ parameters : Some ( AnyRef :: NULL ) ,
656
+ } ;
657
+ }
658
+
630
659
impl < D > From < RsaPublicKey > for VerifyingKey < D >
631
660
where
632
661
D : Digest ,
@@ -795,6 +824,46 @@ impl EncryptingKeypair for DecryptingKey {
795
824
}
796
825
}
797
826
827
+ mod oid {
828
+ use const_oid:: ObjectIdentifier ;
829
+
830
+ /// A trait which associates an RSA-specific OID with a type.
831
+ pub ( crate ) trait RsaSignatureAssociatedOid {
832
+ /// The OID associated with this type.
833
+ const OID : ObjectIdentifier ;
834
+ }
835
+
836
+ #[ cfg( feature = "sha1" ) ]
837
+ impl RsaSignatureAssociatedOid for sha1:: Sha1 {
838
+ const OID : ObjectIdentifier =
839
+ const_oid:: ObjectIdentifier :: new_unwrap ( "1.2.840.113549.1.1.5" ) ;
840
+ }
841
+
842
+ #[ cfg( feature = "sha2" ) ]
843
+ impl RsaSignatureAssociatedOid for sha2:: Sha224 {
844
+ const OID : ObjectIdentifier =
845
+ const_oid:: ObjectIdentifier :: new_unwrap ( "1.2.840.113549.1.1.14" ) ;
846
+ }
847
+
848
+ #[ cfg( feature = "sha2" ) ]
849
+ impl RsaSignatureAssociatedOid for sha2:: Sha256 {
850
+ const OID : ObjectIdentifier =
851
+ const_oid:: ObjectIdentifier :: new_unwrap ( "1.2.840.113549.1.1.11" ) ;
852
+ }
853
+
854
+ #[ cfg( feature = "sha2" ) ]
855
+ impl RsaSignatureAssociatedOid for sha2:: Sha384 {
856
+ const OID : ObjectIdentifier =
857
+ const_oid:: ObjectIdentifier :: new_unwrap ( "1.2.840.113549.1.1.12" ) ;
858
+ }
859
+
860
+ #[ cfg( feature = "sha2" ) ]
861
+ impl RsaSignatureAssociatedOid for sha2:: Sha512 {
862
+ const OID : ObjectIdentifier =
863
+ const_oid:: ObjectIdentifier :: new_unwrap ( "1.2.840.113549.1.1.13" ) ;
864
+ }
865
+ }
866
+
798
867
#[ cfg( test) ]
799
868
mod tests {
800
869
use super :: * ;
0 commit comments