summaryrefslogtreecommitdiffstats
path: root/vendor/sec1/tests/private_key.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
commit2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4 (patch)
tree033cc839730fda84ff08db877037977be94e5e3a /vendor/sec1/tests/private_key.rs
parentInitial commit. (diff)
downloadcargo-upstream.tar.xz
cargo-upstream.zip
Adding upstream version 0.70.1+ds1.upstream/0.70.1+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/sec1/tests/private_key.rs')
-rw-r--r--vendor/sec1/tests/private_key.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/sec1/tests/private_key.rs b/vendor/sec1/tests/private_key.rs
new file mode 100644
index 0000000..224a947
--- /dev/null
+++ b/vendor/sec1/tests/private_key.rs
@@ -0,0 +1,43 @@
+//! SEC1 private key tests
+
+#![cfg(feature = "der")]
+
+use der::asn1::ObjectIdentifier;
+use hex_literal::hex;
+use sec1::{EcParameters, EcPrivateKey};
+
+#[cfg(feature = "alloc")]
+use der::Encode;
+
+/// NIST P-256 SEC1 private key encoded as ASN.1 DER.
+///
+/// Note: this key is extracted from the corresponding `p256-priv.der`
+/// example key in the `pkcs8` crate.
+const P256_DER_EXAMPLE: &[u8] = include_bytes!("examples/p256-priv.der");
+
+#[test]
+fn decode_p256_der() {
+ let key = EcPrivateKey::try_from(P256_DER_EXAMPLE).unwrap();
+
+ // Extracted using:
+ // $ openssl asn1parse -in tests/examples/p256-priv.pem
+ assert_eq!(
+ key.private_key,
+ hex!("69624171561A63340DE0E7D869F2A05492558E1A04868B6A9F854A866788188D")
+ );
+ assert_eq!(
+ key.parameters,
+ Some(EcParameters::NamedCurve(
+ ObjectIdentifier::new("1.2.840.10045.3.1.7").unwrap()
+ ))
+ );
+ assert_eq!(key.public_key, Some(hex!("041CACFFB55F2F2CEFD89D89EB374B2681152452802DEEA09916068137D839CF7FC481A44492304D7EF66AC117BEFE83A8D08F155F2B52F9F618DD447029048E0F").as_ref()));
+}
+
+#[cfg(feature = "alloc")]
+#[test]
+fn encode_p256_der() {
+ let key = EcPrivateKey::try_from(P256_DER_EXAMPLE).unwrap();
+ let key_encoded = key.to_der().unwrap();
+ assert_eq!(P256_DER_EXAMPLE, key_encoded);
+}