4
4
//! RFC5958 (PKCS#8) and RFC5280 (SPKI).
5
5
6
6
#![ cfg( feature = "pkcs8" ) ]
7
- use ed25519_dalek:: pkcs8:: { DecodePrivateKey , DecodePublicKey } ;
7
+ use ed25519_dalek:: pkcs8:: { spki :: DynSignatureAlgorithmIdentifier , DecodePrivateKey , DecodePublicKey } ;
8
8
use ed25519_dalek:: { SigningKey , VerifyingKey } ;
9
9
use hex_literal:: hex;
10
10
11
11
#[ cfg( feature = "alloc" ) ]
12
12
use ed25519_dalek:: pkcs8:: { EncodePrivateKey , EncodePublicKey } ;
13
13
14
- #[ cfg( feature = "x509" ) ]
15
- use x509_cert:: builder:: Builder ;
16
- #[ cfg( feature = "x509" ) ]
17
- use x509_cert:: der:: EncodePem ;
18
- #[ cfg( feature = "x509" ) ]
19
- use x509_cert:: spki:: DynSignatureAlgorithmIdentifier ;
20
-
21
14
/// Ed25519 PKCS#8 v1 private key encoded as ASN.1 DER.
22
15
const PKCS8_V1_DER : & [ u8 ] = include_bytes ! ( "examples/pkcs8-v1.der" ) ;
23
16
@@ -76,45 +69,15 @@ fn encode_verifying_key() {
76
69
assert_eq ! ( verifying_key, verifying_key2) ;
77
70
}
78
71
79
- #[ cfg( feature = "x509" ) ]
80
72
#[ test]
81
- fn build_valid_x509_cert ( ) {
82
- use std:: time:: Duration ;
83
- use std:: str:: FromStr ;
84
- use x509_cert:: {
85
- builder:: { CertificateBuilder , Profile } ,
86
- name:: Name ,
87
- serial_number:: SerialNumber ,
88
- spki:: SubjectPublicKeyInfoOwned ,
89
- time:: Validity ,
90
- } ;
91
- let profile = Profile :: Root ;
92
- let serial_number = SerialNumber :: from ( 42u32 ) ;
93
- let validity = Validity :: from_now ( Duration :: new ( 360 , 0 ) ) . unwrap ( ) ;
94
- let subject = Name :: from_str ( "CN=World domination corporation,O=World domination Inc,C=US" ) . unwrap ( ) ;
95
- let signing = SigningKey :: from_bytes ( & SK_BYTES ) ;
96
- let verifying_key = VerifyingKey :: from_bytes ( & PK_BYTES ) . unwrap ( ) ;
97
- let public_key = verifying_key. to_public_key_der ( ) . unwrap ( ) ;
98
- let key_info =
99
- SubjectPublicKeyInfoOwned :: try_from ( & public_key. as_bytes ( ) [ ..] ) . unwrap ( ) ;
100
-
101
- let builder = CertificateBuilder :: new (
102
- profile,
103
- serial_number,
104
- validity,
105
- subject,
106
- key_info,
107
- & signing,
108
- )
109
- . expect ( "should create certificate" ) ;
110
-
111
- let certificate = builder. build ( ) . unwrap ( ) ;
112
- certificate. to_pem ( x509_cert:: der:: pem:: LineEnding :: LF ) . expect ( "should generate pem" ) ;
113
-
114
- // Note: In order to verify the certificate the same way the x509_cert crate does it via `x509-cert-test-support`, it requires an additional `zlint` tool to be installed
115
- // The tool is installed via `go install github.com/zmap/zlint/v3/cmd/zlint@latest`.
116
- //
117
- // TODO: Blocked by: https://github.com/zmap/zlint/issues/883
118
- // let ignored = &[];
119
- // x509_cert_test_support::zlint::check_certificate(pem.as_bytes(), ignored);
120
- }
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
+ }
0 commit comments