File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,12 +30,14 @@ tempfile = "3"
3030
3131[features ]
3232default = [" der" , " point" ]
33- alloc = [" der/alloc" , " pkcs8/alloc" , " zeroize/alloc" ]
33+ alloc = [" der? /alloc" , " pkcs8? /alloc" , " zeroize? /alloc" ]
3434std = [" alloc" , " der?/std" ]
3535
36+ der = [" dep:der" , " zeroize" ]
3637pem = [" alloc" , " der/pem" , " pkcs8/pem" ]
3738point = [" dep:base16ct" , " dep:generic-array" ]
3839serde = [" dep:serdect" ]
40+ zeroize = [" dep:zeroize" , " der?/zeroize" ]
3941
4042[package .metadata .docs .rs ]
4143all-features = true
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ pub use generic_array::typenum::consts;
5454#[ cfg( feature = "der" ) ]
5555pub use crate :: { parameters:: EcParameters , private_key:: EcPrivateKey , traits:: DecodeEcPrivateKey } ;
5656
57- #[ cfg( feature = "alloc" ) ]
57+ #[ cfg( all ( feature = "alloc" , feature = "der" ) ) ]
5858pub use crate :: traits:: EncodeEcPrivateKey ;
5959
6060#[ cfg( feature = "pem" ) ]
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ use der::{
1313 TagNumber , Writer ,
1414} ;
1515
16- #[ cfg( feature = "alloc" ) ]
16+ #[ cfg( all ( feature = "alloc" , feature = "zeroize" ) ) ]
1717use der:: SecretDocument ;
1818
1919#[ cfg( feature = "pem" ) ]
@@ -119,12 +119,14 @@ impl<'a> DecodeValue<'a> for EcPrivateKey<'a> {
119119
120120impl EncodeValue for EcPrivateKey < ' _ > {
121121 fn value_len ( & self ) -> der:: Result < Length > {
122- OctetStringRef :: new ( self . private_key ) ?. encoded_len ( ) ?
122+ VERSION . encoded_len ( ) ?
123+ + OctetStringRef :: new ( self . private_key ) ?. encoded_len ( ) ?
123124 + self . context_specific_parameters ( ) . encoded_len ( ) ?
124125 + self . context_specific_public_key ( ) ?. encoded_len ( ) ?
125126 }
126127
127128 fn encode_value ( & self , writer : & mut impl Writer ) -> der:: Result < ( ) > {
129+ VERSION . encode ( writer) ?;
128130 OctetStringRef :: new ( self . private_key ) ?. encode ( writer) ?;
129131 self . context_specific_parameters ( ) . encode ( writer) ?;
130132 self . context_specific_public_key ( ) ?. encode ( writer) ?;
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ use der::asn1::ObjectIdentifier;
66use hex_literal:: hex;
77use sec1:: { EcParameters , EcPrivateKey } ;
88
9+ #[ cfg( feature = "alloc" ) ]
10+ use der:: Encode ;
11+
912/// NIST P-256 SEC1 private key encoded as ASN.1 DER.
1013///
1114/// Note: this key is extracted from the corresponding `p256-priv.der`
@@ -30,3 +33,11 @@ fn decode_p256_der() {
3033 ) ;
3134 assert_eq ! ( key. public_key, Some ( hex!( "041CACFFB55F2F2CEFD89D89EB374B2681152452802DEEA09916068137D839CF7FC481A44492304D7EF66AC117BEFE83A8D08F155F2B52F9F618DD447029048E0F" ) . as_ref( ) ) ) ;
3235}
36+
37+ #[ cfg( feature = "alloc" ) ]
38+ #[ test]
39+ fn encode_p256_der ( ) {
40+ let key = EcPrivateKey :: try_from ( P256_DER_EXAMPLE ) . unwrap ( ) ;
41+ let key_encoded = key. to_der ( ) . unwrap ( ) ;
42+ assert_eq ! ( P256_DER_EXAMPLE , key_encoded) ;
43+ }
Original file line number Diff line number Diff line change 11//! Tests for SEC1 encoding/decoding traits.
22
3- #![ cfg( any( feature = "pem" , feature = "std" ) ) ]
3+ #![ cfg( any( feature = "pem" , all ( feature = "der" , feature = " std") ) ) ]
44
55use der:: SecretDocument ;
66use sec1:: { DecodeEcPrivateKey , EncodeEcPrivateKey , Result } ;
You can’t perform that action at this time.
0 commit comments