]> git.proxmox.com Git - rustc.git/blob - vendor/sec1/tests/private_key.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / sec1 / tests / private_key.rs
1 //! SEC1 private key tests
2
3 #![cfg(feature = "der")]
4
5 use der::asn1::ObjectIdentifier;
6 use hex_literal::hex;
7 use sec1::{EcParameters, EcPrivateKey};
8
9 /// NIST P-256 SEC1 private key encoded as ASN.1 DER.
10 ///
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");
14
15 #[test]
16 fn decode_p256_der() {
17 let key = EcPrivateKey::try_from(P256_DER_EXAMPLE).unwrap();
18
19 // Extracted using:
20 // $ openssl asn1parse -in tests/examples/p256-priv.pem
21 assert_eq!(
22 key.private_key,
23 hex!("69624171561A63340DE0E7D869F2A05492558E1A04868B6A9F854A866788188D")
24 );
25 assert_eq!(
26 key.parameters,
27 Some(EcParameters::NamedCurve(
28 ObjectIdentifier::new("1.2.840.10045.3.1.7").unwrap()
29 ))
30 );
31 assert_eq!(key.public_key, Some(hex!("041CACFFB55F2F2CEFD89D89EB374B2681152452802DEEA09916068137D839CF7FC481A44492304D7EF66AC117BEFE83A8D08F155F2B52F9F618DD447029048E0F").as_ref()));
32 }