File tree Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -174,4 +174,4 @@ impl From<InternalSignature> for ed25519::Signature {
174
174
fn from ( sig : InternalSignature ) -> ed25519:: Signature {
175
175
ed25519:: Signature :: from_components ( * sig. R . as_bytes ( ) , * sig. s . as_bytes ( ) )
176
176
}
177
- }
177
+ }
Original file line number Diff line number Diff line change @@ -665,6 +665,15 @@ impl pkcs8::EncodePrivateKey for SigningKey {
665
665
}
666
666
}
667
667
668
+ #[ cfg( feature = "pkcs8" ) ]
669
+ impl pkcs8:: spki:: DynSignatureAlgorithmIdentifier for SigningKey {
670
+ fn signature_algorithm_identifier ( & self ) -> pkcs8:: spki:: Result < pkcs8:: spki:: AlgorithmIdentifierOwned > {
671
+ // From https://datatracker.ietf.org/doc/html/rfc8410
672
+ // `id-Ed25519 OBJECT IDENTIFIER ::= { 1 3 101 112 }`
673
+ Ok ( pkcs8:: spki:: AlgorithmIdentifier { oid : ed25519:: pkcs8:: ALGORITHM_OID , parameters : None } )
674
+ }
675
+ }
676
+
668
677
#[ cfg( feature = "pkcs8" ) ]
669
678
impl TryFrom < pkcs8:: KeypairBytes > for SigningKey {
670
679
type Error = pkcs8:: Error ;
Original file line number Diff line number Diff line change @@ -580,6 +580,15 @@ impl pkcs8::EncodePublicKey for VerifyingKey {
580
580
}
581
581
}
582
582
583
+ #[ cfg( feature = "pkcs8" ) ]
584
+ impl pkcs8:: spki:: DynSignatureAlgorithmIdentifier for VerifyingKey {
585
+ fn signature_algorithm_identifier ( & self ) -> pkcs8:: spki:: Result < pkcs8:: spki:: AlgorithmIdentifierOwned > {
586
+ // From https://datatracker.ietf.org/doc/html/rfc8410
587
+ // `id-Ed25519 OBJECT IDENTIFIER ::= { 1 3 101 112 }`
588
+ Ok ( ed25519:: pkcs8:: spki:: AlgorithmIdentifierOwned { oid : ed25519:: pkcs8:: ALGORITHM_OID , parameters : None } )
589
+ }
590
+ }
591
+
583
592
#[ cfg( feature = "pkcs8" ) ]
584
593
impl TryFrom < pkcs8:: PublicKeyBytes > for VerifyingKey {
585
594
type Error = pkcs8:: spki:: Error ;
Original file line number Diff line number Diff line change 4
4
//! RFC5958 (PKCS#8) and RFC5280 (SPKI).
5
5
6
6
#![ cfg( feature = "pkcs8" ) ]
7
-
8
- use ed25519_dalek:: pkcs8:: { DecodePrivateKey , DecodePublicKey } ;
7
+ use ed25519_dalek:: pkcs8:: { spki:: DynSignatureAlgorithmIdentifier , DecodePrivateKey , DecodePublicKey } ;
9
8
use ed25519_dalek:: { SigningKey , VerifyingKey } ;
10
9
use hex_literal:: hex;
11
10
@@ -69,3 +68,16 @@ fn encode_verifying_key() {
69
68
let verifying_key2 = VerifyingKey :: from_public_key_der ( verifying_key_der. as_bytes ( ) ) . unwrap ( ) ;
70
69
assert_eq ! ( verifying_key, verifying_key2) ;
71
70
}
71
+
72
+ #[ test]
73
+ fn get_algo_identifier ( ) {
74
+ let verifying_key = VerifyingKey :: from_public_key_der ( PUBLIC_KEY_DER ) . unwrap ( ) ;
75
+ let identifier = verifying_key. signature_algorithm_identifier ( ) . unwrap ( ) ;
76
+ assert ! ( identifier. parameters. is_none( ) ) ; // According to rfc8410 this must be None
77
+ assert_eq ! ( identifier. oid, ed25519:: pkcs8:: ALGORITHM_OID ) ;
78
+
79
+ let signing_key = SigningKey :: from_bytes ( & SK_BYTES ) ;
80
+ let identifer = signing_key. signature_algorithm_identifier ( ) . unwrap ( ) ;
81
+ assert ! ( identifer. parameters. is_none( ) ) ; // According to rfc8410 this must be None
82
+ assert_eq ! ( identifer. oid, ed25519:: pkcs8:: ALGORITHM_OID ) ;
83
+ }
You can’t perform that action at this time.
0 commit comments