1 //! SEC1 private key tests
3 #![cfg(feature = "der")]
5 use der
::asn1
::ObjectIdentifier
;
7 use sec1
::{EcParameters, EcPrivateKey}
;
9 /// NIST P-256 SEC1 private key encoded as ASN.1 DER.
11 /// Note: this key is extracted from the corresponding `p256-priv.der`
12 /// example key in the `pkcs8` crate.
13 const P256_DER_EXAMPLE
: &[u8] = include_bytes
!("examples/p256-priv.der");
16 fn decode_p256_der() {
17 let key
= EcPrivateKey
::try_from(P256_DER_EXAMPLE
).unwrap();
20 // $ openssl asn1parse -in tests/examples/p256-priv.pem
23 hex
!("69624171561A63340DE0E7D869F2A05492558E1A04868B6A9F854A866788188D")
27 Some(EcParameters
::NamedCurve(
28 ObjectIdentifier
::new("1.2.840.10045.3.1.7").unwrap()
31 assert_eq
!(key
.public_key
, Some(hex
!("041CACFFB55F2F2CEFD89D89EB374B2681152452802DEEA09916068137D839CF7FC481A44492304D7EF66AC117BEFE83A8D08F155F2B52F9F618DD447029048E0F").as_ref()));