|
4 | 4 | //! RFC5958 (PKCS#8) and RFC5280 (SPKI). |
5 | 5 |
|
6 | 6 | #![cfg(feature = "pkcs8")] |
7 | | - |
8 | 7 | use ed25519_dalek::pkcs8::{DecodePrivateKey, DecodePublicKey}; |
9 | 8 | use ed25519_dalek::{SigningKey, VerifyingKey}; |
10 | 9 | use hex_literal::hex; |
11 | 10 |
|
12 | 11 | #[cfg(feature = "alloc")] |
13 | 12 | use ed25519_dalek::pkcs8::{EncodePrivateKey, EncodePublicKey}; |
14 | 13 |
|
| 14 | +#[cfg(all(feature = "alloc", feature = "pkcs8"))] |
| 15 | +use ed25519_dalek::pkcs8::spki::DynSignatureAlgorithmIdentifier; |
| 16 | + |
15 | 17 | /// Ed25519 PKCS#8 v1 private key encoded as ASN.1 DER. |
16 | 18 | const PKCS8_V1_DER: &[u8] = include_bytes!("examples/pkcs8-v1.der"); |
17 | 19 |
|
@@ -69,3 +71,17 @@ fn encode_verifying_key() { |
69 | 71 | let verifying_key2 = VerifyingKey::from_public_key_der(verifying_key_der.as_bytes()).unwrap(); |
70 | 72 | assert_eq!(verifying_key, verifying_key2); |
71 | 73 | } |
| 74 | + |
| 75 | +#[test] |
| 76 | +#[cfg(feature = "alloc")] |
| 77 | +fn get_algo_identifier() { |
| 78 | + let verifying_key = VerifyingKey::from_public_key_der(PUBLIC_KEY_DER).unwrap(); |
| 79 | + let identifier = verifying_key.signature_algorithm_identifier().unwrap(); |
| 80 | + assert!(identifier.parameters.is_none()); // According to rfc8410 this must be None |
| 81 | + assert_eq!(identifier.oid, ed25519::pkcs8::ALGORITHM_OID); |
| 82 | + |
| 83 | + let signing_key = SigningKey::from_bytes(&SK_BYTES); |
| 84 | + let identifer = signing_key.signature_algorithm_identifier().unwrap(); |
| 85 | + assert!(identifer.parameters.is_none()); // According to rfc8410 this must be None |
| 86 | + assert_eq!(identifer.oid, ed25519::pkcs8::ALGORITHM_OID); |
| 87 | +} |
0 commit comments