1
1
#![ cfg( all( feature = "builder" , feature = "pem" ) ) ]
2
2
3
3
use der:: { pem:: LineEnding , Decode , Encode , EncodePem } ;
4
+ use p256:: { pkcs8:: DecodePrivateKey , NistP256 } ;
4
5
use rsa:: pkcs1:: DecodeRsaPrivateKey ;
5
6
use rsa:: pkcs1v15:: SigningKey ;
6
7
use sha2:: Sha256 ;
@@ -15,7 +16,6 @@ use x509_cert::{
15
16
use x509_cert_test_support:: { openssl, zlint} ;
16
17
17
18
const RSA_2048_DER_EXAMPLE : & [ u8 ] = include_bytes ! ( "examples/rsa2048-pub.der" ) ;
18
- const RSA_2048_PRIV_DER_EXAMPLE : & [ u8 ] = include_bytes ! ( "examples/rsa2048-priv.der" ) ;
19
19
20
20
#[ test]
21
21
fn root_ca_certificate ( ) {
@@ -84,8 +84,8 @@ fn sub_ca_certificate() {
84
84
let pub_key =
85
85
SubjectPublicKeyInfoOwned :: try_from ( RSA_2048_DER_EXAMPLE ) . expect ( "get rsa pub key" ) ;
86
86
87
- let mut signer = rsa_signer ( ) ;
88
- let mut builder = CertificateBuilder :: new (
87
+ let mut signer = ecdsa_signer ( ) ;
88
+ let mut builder = CertificateBuilder :: new :: < ecdsa :: Signature < NistP256 > > (
89
89
profile,
90
90
CertificateVersion :: V3 ( uids) ,
91
91
serial_number,
@@ -96,7 +96,7 @@ fn sub_ca_certificate() {
96
96
)
97
97
. expect ( "Create certificate" ) ;
98
98
99
- let certificate = builder. build ( ) . unwrap ( ) ;
99
+ let certificate = builder. build :: < ecdsa :: Signature < NistP256 > > ( ) . unwrap ( ) ;
100
100
101
101
let pem = certificate. to_pem ( LineEnding :: LF ) . expect ( "generate pem" ) ;
102
102
println ! ( "{}" , openssl:: check_certificate( pem. as_bytes( ) ) ) ;
@@ -112,8 +112,17 @@ fn sub_ca_certificate() {
112
112
zlint:: check_certificate ( pem. as_bytes ( ) , ignored) ;
113
113
}
114
114
115
+ const RSA_2048_PRIV_DER_EXAMPLE : & [ u8 ] = include_bytes ! ( "examples/rsa2048-priv.der" ) ;
116
+
115
117
fn rsa_signer ( ) -> SigningKey < Sha256 > {
116
118
let private_key = rsa:: RsaPrivateKey :: from_pkcs1_der ( RSA_2048_PRIV_DER_EXAMPLE ) . unwrap ( ) ;
117
119
let signing_key = SigningKey :: < Sha256 > :: new_with_prefix ( private_key) ;
118
120
signing_key
119
121
}
122
+
123
+ const PKCS8_PRIVATE_KEY_DER : & [ u8 ] = include_bytes ! ( "examples/p256-priv.der" ) ;
124
+
125
+ fn ecdsa_signer ( ) -> ecdsa:: SigningKey < NistP256 > {
126
+ let secret_key = p256:: SecretKey :: from_pkcs8_der ( PKCS8_PRIVATE_KEY_DER ) . unwrap ( ) ;
127
+ ecdsa:: SigningKey :: from ( secret_key)
128
+ }
0 commit comments