diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
commit | 837b550238aa671a591ccf282dddeab29cadb206 (patch) | |
tree | 914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/pkcs8 | |
parent | Adding debian version 1.70.0+dfsg2-1. (diff) | |
download | rustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz rustc-837b550238aa671a591ccf282dddeab29cadb206.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/pkcs8')
-rw-r--r-- | vendor/pkcs8/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/pkcs8/CHANGELOG.md | 24 | ||||
-rw-r--r-- | vendor/pkcs8/Cargo.toml | 15 | ||||
-rw-r--r-- | vendor/pkcs8/LICENSE-MIT | 2 | ||||
-rw-r--r-- | vendor/pkcs8/README.md | 4 | ||||
-rw-r--r-- | vendor/pkcs8/src/encrypted_private_key_info.rs | 33 | ||||
-rw-r--r-- | vendor/pkcs8/src/error.rs | 2 | ||||
-rw-r--r-- | vendor/pkcs8/src/lib.rs | 23 | ||||
-rw-r--r-- | vendor/pkcs8/src/private_key_info.rs | 74 | ||||
-rw-r--r-- | vendor/pkcs8/src/traits.rs | 27 | ||||
-rw-r--r-- | vendor/pkcs8/src/version.rs | 4 | ||||
-rw-r--r-- | vendor/pkcs8/tests/encrypted_private_key.rs | 4 | ||||
-rw-r--r-- | vendor/pkcs8/tests/private_key.rs | 15 | ||||
-rw-r--r-- | vendor/pkcs8/tests/traits.rs | 8 |
14 files changed, 131 insertions, 106 deletions
diff --git a/vendor/pkcs8/.cargo-checksum.json b/vendor/pkcs8/.cargo-checksum.json index 32f3df041..aa3d7497f 100644 --- a/vendor/pkcs8/.cargo-checksum.json +++ b/vendor/pkcs8/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"CHANGELOG.md":"aea933ccfc3923c0c3e88b77a0b7d5aa5a4a36bf35e8b0e8f911692423020a1f","Cargo.toml":"ac0261d5f8e063c6d064ea76c8a51260a075927091fbdf95c0fb21e9dd34875b","LICENSE-APACHE":"a9040321c3712d8fd0b09cf52b17445de04a23a10165049ae187cd39e5c86be5","LICENSE-MIT":"904801faf3f1850328af8e1aa1047b9190cc22ed40df5c87f2d93d17f847ef67","README.md":"c0eea4fc2110743a2f6e07d9f80e2df3c92801b48e512cedd345ce01098eb732","src/encrypted_private_key_info.rs":"442ccb41c4b5d1ea6867501052fe78642705353afacf2bd8c50b14cfb0a712f8","src/error.rs":"be7deaf3abc0f5b41cb76f145654a8b6027616cd835be329cd55ce2e0b12a2c5","src/lib.rs":"e5e99696f70e28939a5d5b5259743ee053b7d1c990e8554b32a46a5a8b120e98","src/private_key_info.rs":"1e8a85260ff557adb1218cab27f651e0797cfc374a309c63061c6394ac8909b9","src/traits.rs":"651db842ecc79bf98a18f424737a9167ddd554ba2c85260a8ef83210c35f7655","src/version.rs":"6c8d36789f2aa0b1a4850b7ca97f6fa603bc62ebdece56cc9193e605582174de","tests/encrypted_private_key.rs":"d2d631fea2b086815605986f1d49b303b7e09eea68a614fa4a72ec3cb1c9b07a","tests/examples/ed25519-encpriv-aes128-pbkdf2-sha1.der":"b41702662d6a645cc81af5be79455509e02efbf6eb5166e91346c19334485e9a","tests/examples/ed25519-encpriv-aes256-pbkdf2-sha256.der":"72ea607c5f0e560f68ee914dca8a5a74bfa22a667333656864f7938960acd302","tests/examples/ed25519-encpriv-aes256-pbkdf2-sha256.pem":"0c8bd6713af3f28392f684c5ba8b1bd842d8b483d00c136cb1fb24976aab447a","tests/examples/ed25519-encpriv-aes256-scrypt.der":"81f29098750ab282fd071692173d4da09b2c81371e7a02da7a8a14d6bed7c8a0","tests/examples/ed25519-encpriv-aes256-scrypt.pem":"e643345b62b43ea255fccbad6efd21453c62a7bbbb4d94dfae151fe04562313d","tests/examples/ed25519-encpriv-des-pbkdf2-sha256.der":"2a2412eac2aebec977563ee503358513c179f0216d93701ecd901f0062df79dd","tests/examples/ed25519-encpriv-des3-pbkdf2-sha256.der":"e064ed2a875be1388a05be89948236c2765d85943ccf093ee3df6e9a16baa619","tests/examples/ed25519-priv-pkcs8v1.der":"c1c3b09c4d18e096209edf25bc8dfc2f11dc29896085e49e5f4e487fbd97dbb6","tests/examples/ed25519-priv-pkcs8v1.pem":"8e39c38052cd63ab3870831a9f6cab76645426ca21ef77e24e2ead445aa4df16","tests/examples/ed25519-priv-pkcs8v2.der":"78f1cd2051065b209431249093f218b0e01a5fd0b9e756db820d4893d9dbbf55","tests/examples/ed25519-priv-pkcs8v2.pem":"a7cc1efd420b972a1b0776cc8b703624c62617eb2be3705876cc145227bd8427","tests/examples/ed25519-pub.der":"55dd4c74b0e48534e2f4e173ceceb50df8f27a7ac2aa8991cc7ae914e030bced","tests/examples/ed25519-pub.pem":"36d717203cbca1812f05f30e0415251c928b659882092e653221a028571c6853","tests/examples/p256-priv.der":"8125ab208d2181ed3ef05ff0ab1906e5898c36a858277e5b987e78e505288769","tests/examples/p256-priv.pem":"f4171f5ea72bf95ee444ceb868872f5c5d2bbc5fca038ae801b06fb9ac6b9429","tests/examples/p256-pub.der":"b9968d56ed8d6aa3fb43b15fa01e355d7a3a0203b1408b3fd2733637c4d1642c","tests/examples/p256-pub.pem":"d1ff198dc495da63f5f909db0254d6e49cff519487fcb26d055a762fc3ca47a1","tests/examples/rsa2048-priv.der":"ea7fe20f854f4fb908c12f1344e6cffbb83f367bbd8bfebca20687402394266f","tests/examples/rsa2048-priv.pem":"4df5e3254935a4f7d71e3b693d1b874091717f8b6075cd33f80ce4338d2ab0f2","tests/examples/rsa2048-pub.der":"efeda9bfead9fd0594f6a5cf6fdf6c163116a3b1fad6d73cea05295b68fd1794","tests/examples/rsa2048-pub.pem":"078c3983093e86784590a2a454547acad1d50992419334be697e442e954f02f8","tests/examples/x25519-priv.der":"bc4561e57bcb0e5b8be9bbdf4fb51e5e34dc46047ce50239c35fe7f119f52f91","tests/examples/x25519-priv.pem":"c618022ab6a2e345b475830c1e0a9332458791df939d116b6e6d4da9c918771b","tests/private_key.rs":"44b42494e74087860020e9799c8e50922de36385e8d5ea74b0285879c6e43063","tests/traits.rs":"420524fd3394c9fd5cfcf02a4f1da3f3193a91712dfd513915aec9bddfaf57e9"},"package":"9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba"}
\ No newline at end of file +{"files":{"CHANGELOG.md":"a01855ad0a36a81e3e82f56d3d68a844489c3b17a5cb902e235924be158aee58","Cargo.toml":"440cf271c696da0bcef123a4e005f9f47273d140b9b824f4b7b0d4fa4639cb12","LICENSE-APACHE":"a9040321c3712d8fd0b09cf52b17445de04a23a10165049ae187cd39e5c86be5","LICENSE-MIT":"ad64fcb9589f162720f3cc5010ad76ca6ad3764e11861f9192c489df176bb71d","README.md":"49fdb13fec069473cf11a797d4fe3dc2c3cb2c496652937ae7dab4a7b87cddfc","src/encrypted_private_key_info.rs":"33746a87bce68a79a8ae53951cd020b2145383afce6c5ca4e5bbc5eb642a642e","src/error.rs":"94b661093a3c5beac61ffaabcae36e4d156309eeb78f36154a7422ccda7d2422","src/lib.rs":"b5c2fedbf3cfa31cc56b9cc16c94a5083ee83d7facfa1a34837b5262f60f622a","src/private_key_info.rs":"bd3b7aaa41ddab5fd731e1d0d1d7bf25c81fe6291a9edf51cd792136c4a50556","src/traits.rs":"fe016f54123d8bdcfd728ccba902033eccd546457cdba0d4d51f17c589df108a","src/version.rs":"a1c31cf4c2dc9677637d2616f34300d0117be70b72258a78f47841e457ec983f","tests/encrypted_private_key.rs":"f9e173d9bc76c21db92d05f36852be14e321877896dc46237ce6e6af7026002c","tests/examples/ed25519-encpriv-aes128-pbkdf2-sha1.der":"b41702662d6a645cc81af5be79455509e02efbf6eb5166e91346c19334485e9a","tests/examples/ed25519-encpriv-aes256-pbkdf2-sha256.der":"72ea607c5f0e560f68ee914dca8a5a74bfa22a667333656864f7938960acd302","tests/examples/ed25519-encpriv-aes256-pbkdf2-sha256.pem":"0c8bd6713af3f28392f684c5ba8b1bd842d8b483d00c136cb1fb24976aab447a","tests/examples/ed25519-encpriv-aes256-scrypt.der":"81f29098750ab282fd071692173d4da09b2c81371e7a02da7a8a14d6bed7c8a0","tests/examples/ed25519-encpriv-aes256-scrypt.pem":"e643345b62b43ea255fccbad6efd21453c62a7bbbb4d94dfae151fe04562313d","tests/examples/ed25519-encpriv-des-pbkdf2-sha256.der":"2a2412eac2aebec977563ee503358513c179f0216d93701ecd901f0062df79dd","tests/examples/ed25519-encpriv-des3-pbkdf2-sha256.der":"e064ed2a875be1388a05be89948236c2765d85943ccf093ee3df6e9a16baa619","tests/examples/ed25519-priv-pkcs8v1.der":"c1c3b09c4d18e096209edf25bc8dfc2f11dc29896085e49e5f4e487fbd97dbb6","tests/examples/ed25519-priv-pkcs8v1.pem":"8e39c38052cd63ab3870831a9f6cab76645426ca21ef77e24e2ead445aa4df16","tests/examples/ed25519-priv-pkcs8v2.der":"78f1cd2051065b209431249093f218b0e01a5fd0b9e756db820d4893d9dbbf55","tests/examples/ed25519-priv-pkcs8v2.pem":"a7cc1efd420b972a1b0776cc8b703624c62617eb2be3705876cc145227bd8427","tests/examples/ed25519-pub.der":"55dd4c74b0e48534e2f4e173ceceb50df8f27a7ac2aa8991cc7ae914e030bced","tests/examples/ed25519-pub.pem":"36d717203cbca1812f05f30e0415251c928b659882092e653221a028571c6853","tests/examples/p256-priv.der":"8125ab208d2181ed3ef05ff0ab1906e5898c36a858277e5b987e78e505288769","tests/examples/p256-priv.pem":"f4171f5ea72bf95ee444ceb868872f5c5d2bbc5fca038ae801b06fb9ac6b9429","tests/examples/p256-pub.der":"b9968d56ed8d6aa3fb43b15fa01e355d7a3a0203b1408b3fd2733637c4d1642c","tests/examples/p256-pub.pem":"d1ff198dc495da63f5f909db0254d6e49cff519487fcb26d055a762fc3ca47a1","tests/examples/rsa2048-priv.der":"ea7fe20f854f4fb908c12f1344e6cffbb83f367bbd8bfebca20687402394266f","tests/examples/rsa2048-priv.pem":"4df5e3254935a4f7d71e3b693d1b874091717f8b6075cd33f80ce4338d2ab0f2","tests/examples/rsa2048-pub.der":"efeda9bfead9fd0594f6a5cf6fdf6c163116a3b1fad6d73cea05295b68fd1794","tests/examples/rsa2048-pub.pem":"078c3983093e86784590a2a454547acad1d50992419334be697e442e954f02f8","tests/examples/x25519-priv.der":"bc4561e57bcb0e5b8be9bbdf4fb51e5e34dc46047ce50239c35fe7f119f52f91","tests/examples/x25519-priv.pem":"c618022ab6a2e345b475830c1e0a9332458791df939d116b6e6d4da9c918771b","tests/private_key.rs":"ff7dd659b3bc3a5bfc8789164160a4759838ad58e1233cece020340f6bb45271","tests/traits.rs":"fcd1f1198ce579736862eed872ca55f081533146001fc9ec03ac35728fbd89a8"},"package":"f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7"}
\ No newline at end of file diff --git a/vendor/pkcs8/CHANGELOG.md b/vendor/pkcs8/CHANGELOG.md index 15889d971..1f754d527 100644 --- a/vendor/pkcs8/CHANGELOG.md +++ b/vendor/pkcs8/CHANGELOG.md @@ -4,6 +4,30 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.10.2 (2023-04-04) +### Changed +- Bump `spki` to v0.7.1 ([#981]) + +[#981]: https://github.com/RustCrypto/formats/pull/981 + +## 0.10.1 (2023-03-05) +### Added +- `sha1-insecure` feature ([#913]) + +[#913]: https://github.com/RustCrypto/formats/pull/913 + +## 0.10.0 (2023-02-26) [YANKED] +### Changed +- Use blanket impls for `Decode*` traits ([#785]) +- Bump `der` dependency to v0.7 ([#899]) +- Bump `spki` dependency to v0.7 ([#900]) +- Bump `pkcs5` dependency to v0.7 ([#901]) + +[#785]: https://github.com/RustCrypto/formats/pull/785 +[#899]: https://github.com/RustCrypto/formats/pull/899 +[#900]: https://github.com/RustCrypto/formats/pull/900 +[#901]: https://github.com/RustCrypto/formats/pull/901 + ## 0.9.0 (2022-05-08) ### Added - Error conversion support to `pkcs8::spki::Error` ([#335]) diff --git a/vendor/pkcs8/Cargo.toml b/vendor/pkcs8/Cargo.toml index 6de007a54..d8365512d 100644 --- a/vendor/pkcs8/Cargo.toml +++ b/vendor/pkcs8/Cargo.toml @@ -11,9 +11,9 @@ [package] edition = "2021" -rust-version = "1.57" +rust-version = "1.65" name = "pkcs8" -version = "0.9.0" +version = "0.10.2" authors = ["RustCrypto Developers"] description = """ Pure Rust implementation of Public-Key Cryptography Standards (PKCS) #8: @@ -36,7 +36,6 @@ categories = [ ] license = "Apache-2.0 OR MIT" repository = "https://github.com/RustCrypto/formats/tree/master/pkcs8" -resolver = "2" [package.metadata.docs.rs] all-features = true @@ -46,11 +45,11 @@ rustdoc-args = [ ] [dependencies.der] -version = "0.6" +version = "0.7" features = ["oid"] [dependencies.pkcs5] -version = "0.5" +version = "0.7" optional = true [dependencies.rand_core] @@ -59,7 +58,7 @@ optional = true default-features = false [dependencies.spki] -version = "0.6" +version = "0.7.1" [dependencies.subtle] version = "2" @@ -98,9 +97,9 @@ pem = [ "der/pem", "spki/pem", ] -sha1 = [ +sha1-insecure = [ "encryption", - "pkcs5/sha1", + "pkcs5/sha1-insecure", ] std = [ "alloc", diff --git a/vendor/pkcs8/LICENSE-MIT b/vendor/pkcs8/LICENSE-MIT index 2726e14a4..e0d082780 100644 --- a/vendor/pkcs8/LICENSE-MIT +++ b/vendor/pkcs8/LICENSE-MIT @@ -1,4 +1,4 @@ -Copyright (c) 2020 The RustCrypto Project Developers +Copyright (c) 2020-2023 The RustCrypto Project Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated diff --git a/vendor/pkcs8/README.md b/vendor/pkcs8/README.md index 2fa301ced..c1585439a 100644 --- a/vendor/pkcs8/README.md +++ b/vendor/pkcs8/README.md @@ -54,7 +54,7 @@ algorithm, including the ones listed above or other algorithms. ## Minimum Supported Rust Version -This crate requires **Rust 1.57** at a minimum. +This crate requires **Rust 1.65** at a minimum. We may change the MSRV in the future, but it will be accompanied by a minor version bump. @@ -81,7 +81,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/pkcs8/badge.svg [docs-link]: https://docs.rs/pkcs8/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/300570-formats [build-image]: https://github.com/RustCrypto/formats/workflows/pkcs8/badge.svg?branch=master&event=push diff --git a/vendor/pkcs8/src/encrypted_private_key_info.rs b/vendor/pkcs8/src/encrypted_private_key_info.rs index 460e3f6e3..d55949cad 100644 --- a/vendor/pkcs8/src/encrypted_private_key_info.rs +++ b/vendor/pkcs8/src/encrypted_private_key_info.rs @@ -2,7 +2,10 @@ use crate::{Error, Result}; use core::fmt; -use der::{asn1::OctetStringRef, Decode, DecodeValue, Encode, Header, Reader, Sequence}; +use der::{ + asn1::OctetStringRef, Decode, DecodeValue, Encode, EncodeValue, Header, Length, Reader, + Sequence, Writer, +}; use pkcs5::EncryptionScheme; #[cfg(feature = "alloc")] @@ -36,7 +39,6 @@ use der::pem::PemLabel; /// ``` /// /// [RFC 5208 Section 6]: https://tools.ietf.org/html/rfc5208#section-6 -#[cfg_attr(docsrs, doc(cfg(feature = "pkcs5")))] #[derive(Clone, Eq, PartialEq)] pub struct EncryptedPrivateKeyInfo<'a> { /// Algorithm identifier describing a password-based symmetric encryption @@ -51,7 +53,6 @@ impl<'a> EncryptedPrivateKeyInfo<'a> { /// Attempt to decrypt this encrypted private key using the provided /// password to derive an encryption key. #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] pub fn decrypt(&self, password: impl AsRef<[u8]>) -> Result<SecretDocument> { Ok(self .encryption_algorithm @@ -62,7 +63,6 @@ impl<'a> EncryptedPrivateKeyInfo<'a> { /// Encrypt the given ASN.1 DER document using a symmetric encryption key /// derived from the provided password. #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] pub(crate) fn encrypt( mut rng: impl CryptoRng + RngCore, password: impl AsRef<[u8]>, @@ -81,7 +81,6 @@ impl<'a> EncryptedPrivateKeyInfo<'a> { /// Encrypt this private key using a symmetric encryption key derived /// from the provided password and [`pbes2::Parameters`]. #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] pub(crate) fn encrypt_with( pbes2_params: pbes2::Parameters<'a>, password: impl AsRef<[u8]>, @@ -111,18 +110,21 @@ impl<'a> DecodeValue<'a> for EncryptedPrivateKeyInfo<'a> { } } -impl<'a> Sequence<'a> for EncryptedPrivateKeyInfo<'a> { - fn fields<F, T>(&self, f: F) -> der::Result<T> - where - F: FnOnce(&[&dyn Encode]) -> der::Result<T>, - { - f(&[ - &self.encryption_algorithm, - &OctetStringRef::new(self.encrypted_data)?, - ]) +impl EncodeValue for EncryptedPrivateKeyInfo<'_> { + fn value_len(&self) -> der::Result<Length> { + self.encryption_algorithm.encoded_len()? + + OctetStringRef::new(self.encrypted_data)?.encoded_len()? + } + + fn encode_value(&self, writer: &mut impl Writer) -> der::Result<()> { + self.encryption_algorithm.encode(writer)?; + OctetStringRef::new(self.encrypted_data)?.encode(writer)?; + Ok(()) } } +impl<'a> Sequence<'a> for EncryptedPrivateKeyInfo<'a> {} + impl<'a> TryFrom<&'a [u8]> for EncryptedPrivateKeyInfo<'a> { type Error = Error; @@ -140,7 +142,6 @@ impl<'a> fmt::Debug for EncryptedPrivateKeyInfo<'a> { } #[cfg(feature = "alloc")] -#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "pkcs5"))))] impl TryFrom<EncryptedPrivateKeyInfo<'_>> for SecretDocument { type Error = Error; @@ -150,7 +151,6 @@ impl TryFrom<EncryptedPrivateKeyInfo<'_>> for SecretDocument { } #[cfg(feature = "alloc")] -#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "pkcs5"))))] impl TryFrom<&EncryptedPrivateKeyInfo<'_>> for SecretDocument { type Error = Error; @@ -160,7 +160,6 @@ impl TryFrom<&EncryptedPrivateKeyInfo<'_>> for SecretDocument { } #[cfg(feature = "pem")] -#[cfg_attr(docsrs, doc(cfg(feature = "pem")))] impl PemLabel for EncryptedPrivateKeyInfo<'_> { const PEM_LABEL: &'static str = "ENCRYPTED PRIVATE KEY"; } diff --git a/vendor/pkcs8/src/error.rs b/vendor/pkcs8/src/error.rs index bc4c2eafe..70c60aedb 100644 --- a/vendor/pkcs8/src/error.rs +++ b/vendor/pkcs8/src/error.rs @@ -26,7 +26,7 @@ pub enum Error { /// or [`SubjectPublicKeyInfo::subject_public_key`][`crate::SubjectPublicKeyInfo::subject_public_key`]. KeyMalformed, - /// [`AlgorithmIdentifier::parameters`][`crate::AlgorithmIdentifier::parameters`] + /// [`AlgorithmIdentifier::parameters`][`crate::AlgorithmIdentifierRef::parameters`] /// is malformed or otherwise encoded in an unexpected manner. ParametersMalformed, diff --git a/vendor/pkcs8/src/lib.rs b/vendor/pkcs8/src/lib.rs index 1d2dfa284..33ceef8e2 100644 --- a/vendor/pkcs8/src/lib.rs +++ b/vendor/pkcs8/src/lib.rs @@ -1,13 +1,19 @@ #![no_std] -#![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![doc = include_str!("../README.md")] #![doc( - html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", - html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", - html_root_url = "https://docs.rs/pkcs8/0.9.0-pre" + html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", + html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg" +)] +#![forbid(unsafe_code)] +#![warn( + clippy::mod_module_files, + clippy::unwrap_used, + missing_docs, + rust_2018_idioms, + unused_lifetimes, + unused_qualifications )] -#![forbid(unsafe_code, clippy::unwrap_used)] -#![warn(missing_docs, rust_2018_idioms, unused_qualifications)] //! ## About this crate //! This library provides generalized PKCS#8 support designed to work with a @@ -84,7 +90,9 @@ pub use crate::{ version::Version, }; pub use der::{self, asn1::ObjectIdentifier, oid::AssociatedOid}; -pub use spki::{self, AlgorithmIdentifier, DecodePublicKey, SubjectPublicKeyInfo}; +pub use spki::{ + self, AlgorithmIdentifierRef, DecodePublicKey, SubjectPublicKeyInfo, SubjectPublicKeyInfoRef, +}; #[cfg(feature = "alloc")] pub use { @@ -94,7 +102,6 @@ pub use { }; #[cfg(feature = "pem")] -#[cfg_attr(docsrs, doc(cfg(feature = "pem")))] pub use der::pem::LineEnding; #[cfg(feature = "pkcs5")] diff --git a/vendor/pkcs8/src/private_key_info.rs b/vendor/pkcs8/src/private_key_info.rs index 52f0878d7..ecae624df 100644 --- a/vendor/pkcs8/src/private_key_info.rs +++ b/vendor/pkcs8/src/private_key_info.rs @@ -1,10 +1,11 @@ //! PKCS#8 `PrivateKeyInfo`. -use crate::{AlgorithmIdentifier, Error, Result, Version}; +use crate::{AlgorithmIdentifierRef, Error, Result, Version}; use core::fmt; use der::{ asn1::{AnyRef, BitStringRef, ContextSpecific, OctetStringRef}, - Decode, DecodeValue, Encode, Header, Reader, Sequence, TagMode, TagNumber, + Decode, DecodeValue, Encode, EncodeValue, Header, Length, Reader, Sequence, TagMode, TagNumber, + Writer, }; #[cfg(feature = "alloc")] @@ -29,7 +30,7 @@ const PUBLIC_KEY_TAG: TagNumber = TagNumber::N1; /// PKCS#8 `PrivateKeyInfo`. /// -/// ASN.1 structure containing an [`AlgorithmIdentifier`], private key +/// ASN.1 structure containing an `AlgorithmIdentifier`, private key /// data in an algorithm specific format, and optional attributes /// (ignored by this implementation). /// @@ -90,8 +91,8 @@ const PUBLIC_KEY_TAG: TagNumber = TagNumber::N1; /// [RFC 5958 Section 2]: https://datatracker.ietf.org/doc/html/rfc5958#section-2 #[derive(Clone)] pub struct PrivateKeyInfo<'a> { - /// X.509 [`AlgorithmIdentifier`] for the private key type. - pub algorithm: AlgorithmIdentifier<'a>, + /// X.509 `AlgorithmIdentifier` for the private key type. + pub algorithm: AlgorithmIdentifierRef<'a>, /// Private key data. pub private_key: &'a [u8], @@ -105,7 +106,7 @@ impl<'a> PrivateKeyInfo<'a> { /// /// This is a helper method which initializes `attributes` and `public_key` /// to `None`, helpful if you aren't using those. - pub fn new(algorithm: AlgorithmIdentifier<'a>, private_key: &'a [u8]) -> Self { + pub fn new(algorithm: AlgorithmIdentifierRef<'a>, private_key: &'a [u8]) -> Self { Self { algorithm, private_key, @@ -134,28 +135,39 @@ impl<'a> PrivateKeyInfo<'a> { /// - p: 1 /// - Cipher: AES-256-CBC (best available option for PKCS#5 encryption) #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] pub fn encrypt( &self, rng: impl CryptoRng + RngCore, password: impl AsRef<[u8]>, ) -> Result<SecretDocument> { - let der = Zeroizing::new(self.to_vec()?); + let der = Zeroizing::new(self.to_der()?); EncryptedPrivateKeyInfo::encrypt(rng, password, der.as_ref()) } /// Encrypt this private key using a symmetric encryption key derived /// from the provided password and [`pbes2::Parameters`]. #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] pub fn encrypt_with_params( &self, pbes2_params: pbes2::Parameters<'_>, password: impl AsRef<[u8]>, ) -> Result<SecretDocument> { - let der = Zeroizing::new(self.to_vec()?); + let der = Zeroizing::new(self.to_der()?); EncryptedPrivateKeyInfo::encrypt_with(pbes2_params, password, der.as_ref()) } + + /// Get a `BIT STRING` representation of the public key, if present. + fn public_key_bit_string(&self) -> der::Result<Option<ContextSpecific<BitStringRef<'a>>>> { + self.public_key + .map(|pk| { + BitStringRef::from_bytes(pk).map(|value| ContextSpecific { + tag_number: PUBLIC_KEY_TAG, + tag_mode: TagMode::Implicit, + value, + }) + }) + .transpose() + } } impl<'a> DecodeValue<'a> for PrivateKeyInfo<'a> { @@ -201,29 +213,25 @@ impl<'a> DecodeValue<'a> for PrivateKeyInfo<'a> { } } -impl<'a> Sequence<'a> for PrivateKeyInfo<'a> { - fn fields<F, T>(&self, f: F) -> der::Result<T> - where - F: FnOnce(&[&dyn Encode]) -> der::Result<T>, - { - f(&[ - &u8::from(self.version()), - &self.algorithm, - &OctetStringRef::new(self.private_key)?, - &self - .public_key - .map(|pk| { - BitStringRef::from_bytes(pk).map(|value| ContextSpecific { - tag_number: PUBLIC_KEY_TAG, - tag_mode: TagMode::Implicit, - value, - }) - }) - .transpose()?, - ]) +impl EncodeValue for PrivateKeyInfo<'_> { + fn value_len(&self) -> der::Result<Length> { + self.version().encoded_len()? + + self.algorithm.encoded_len()? + + OctetStringRef::new(self.private_key)?.encoded_len()? + + self.public_key_bit_string()?.encoded_len()? + } + + fn encode_value(&self, writer: &mut impl Writer) -> der::Result<()> { + self.version().encode(writer)?; + self.algorithm.encode(writer)?; + OctetStringRef::new(self.private_key)?.encode(writer)?; + self.public_key_bit_string()?.encode(writer)?; + Ok(()) } } +impl<'a> Sequence<'a> for PrivateKeyInfo<'a> {} + impl<'a> TryFrom<&'a [u8]> for PrivateKeyInfo<'a> { type Error = Error; @@ -243,7 +251,6 @@ impl<'a> fmt::Debug for PrivateKeyInfo<'a> { } #[cfg(feature = "alloc")] -#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] impl TryFrom<PrivateKeyInfo<'_>> for SecretDocument { type Error = Error; @@ -253,7 +260,6 @@ impl TryFrom<PrivateKeyInfo<'_>> for SecretDocument { } #[cfg(feature = "alloc")] -#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] impl TryFrom<&PrivateKeyInfo<'_>> for SecretDocument { type Error = Error; @@ -263,13 +269,11 @@ impl TryFrom<&PrivateKeyInfo<'_>> for SecretDocument { } #[cfg(feature = "pem")] -#[cfg_attr(docsrs, doc(cfg(feature = "pem")))] impl PemLabel for PrivateKeyInfo<'_> { const PEM_LABEL: &'static str = "PRIVATE KEY"; } #[cfg(feature = "subtle")] -#[cfg_attr(docsrs, doc(cfg(feature = "subtle")))] impl<'a> ConstantTimeEq for PrivateKeyInfo<'a> { fn ct_eq(&self, other: &Self) -> Choice { // NOTE: public fields are not compared in constant time @@ -281,11 +285,9 @@ impl<'a> ConstantTimeEq for PrivateKeyInfo<'a> { } #[cfg(feature = "subtle")] -#[cfg_attr(docsrs, doc(cfg(feature = "subtle")))] impl<'a> Eq for PrivateKeyInfo<'a> {} #[cfg(feature = "subtle")] -#[cfg_attr(docsrs, doc(cfg(feature = "subtle")))] impl<'a> PartialEq for PrivateKeyInfo<'a> { fn eq(&self, other: &Self) -> bool { self.ct_eq(other).into() diff --git a/vendor/pkcs8/src/traits.rs b/vendor/pkcs8/src/traits.rs index dd86b90ef..b4f80b2e7 100644 --- a/vendor/pkcs8/src/traits.rs +++ b/vendor/pkcs8/src/traits.rs @@ -21,17 +21,14 @@ use der::pem::PemLabel; use std::path::Path; /// Parse a private key object from a PKCS#8 encoded document. -pub trait DecodePrivateKey: for<'a> TryFrom<PrivateKeyInfo<'a>, Error = Error> + Sized { +pub trait DecodePrivateKey: Sized { /// Deserialize PKCS#8 private key from ASN.1 DER-encoded data /// (binary format). - fn from_pkcs8_der(bytes: &[u8]) -> Result<Self> { - Self::try_from(PrivateKeyInfo::try_from(bytes)?) - } + fn from_pkcs8_der(bytes: &[u8]) -> Result<Self>; /// Deserialize encrypted PKCS#8 private key from ASN.1 DER-encoded data /// (binary format) and attempt to decrypt it using the provided password. #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] fn from_pkcs8_encrypted_der(bytes: &[u8], password: impl AsRef<[u8]>) -> Result<Self> { let doc = EncryptedPrivateKeyInfo::try_from(bytes)?.decrypt(password)?; Self::from_pkcs8_der(doc.as_bytes()) @@ -45,7 +42,6 @@ pub trait DecodePrivateKey: for<'a> TryFrom<PrivateKeyInfo<'a>, Error = Error> + /// -----BEGIN PRIVATE KEY----- /// ``` #[cfg(feature = "pem")] - #[cfg_attr(docsrs, doc(cfg(feature = "pem")))] fn from_pkcs8_pem(s: &str) -> Result<Self> { let (label, doc) = SecretDocument::from_pem(s)?; PrivateKeyInfo::validate_pem_label(label)?; @@ -61,7 +57,6 @@ pub trait DecodePrivateKey: for<'a> TryFrom<PrivateKeyInfo<'a>, Error = Error> + /// -----BEGIN ENCRYPTED PRIVATE KEY----- /// ``` #[cfg(all(feature = "encryption", feature = "pem"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "encryption", feature = "pem"))))] fn from_pkcs8_encrypted_pem(s: &str, password: impl AsRef<[u8]>) -> Result<Self> { let (label, doc) = SecretDocument::from_pem(s)?; EncryptedPrivateKeyInfo::validate_pem_label(label)?; @@ -71,15 +66,12 @@ pub trait DecodePrivateKey: for<'a> TryFrom<PrivateKeyInfo<'a>, Error = Error> + /// Load PKCS#8 private key from an ASN.1 DER-encoded file on the local /// filesystem (binary format). #[cfg(feature = "std")] - #[cfg_attr(docsrs, doc(cfg(feature = "std")))] fn read_pkcs8_der_file(path: impl AsRef<Path>) -> Result<Self> { Self::from_pkcs8_der(SecretDocument::read_der_file(path)?.as_bytes()) } /// Load PKCS#8 private key from a PEM-encoded file on the local filesystem. #[cfg(all(feature = "pem", feature = "std"))] - #[cfg_attr(docsrs, doc(cfg(feature = "pem")))] - #[cfg_attr(docsrs, doc(cfg(feature = "std")))] fn read_pkcs8_pem_file(path: impl AsRef<Path>) -> Result<Self> { let (label, doc) = SecretDocument::read_pem_file(path)?; PrivateKeyInfo::validate_pem_label(&label)?; @@ -87,9 +79,17 @@ pub trait DecodePrivateKey: for<'a> TryFrom<PrivateKeyInfo<'a>, Error = Error> + } } +impl<T> DecodePrivateKey for T +where + T: for<'a> TryFrom<PrivateKeyInfo<'a>, Error = Error>, +{ + fn from_pkcs8_der(bytes: &[u8]) -> Result<Self> { + Self::try_from(PrivateKeyInfo::try_from(bytes)?) + } +} + /// Serialize a private key object to a PKCS#8 encoded document. #[cfg(feature = "alloc")] -#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub trait EncodePrivateKey { /// Serialize a [`SecretDocument`] containing a PKCS#8-encoded private key. fn to_pkcs8_der(&self) -> Result<SecretDocument>; @@ -97,7 +97,6 @@ pub trait EncodePrivateKey { /// Create an [`SecretDocument`] containing the ciphertext of /// a PKCS#8 encoded private key encrypted under the given `password`. #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] fn to_pkcs8_encrypted_der( &self, rng: impl CryptoRng + RngCore, @@ -108,7 +107,6 @@ pub trait EncodePrivateKey { /// Serialize this private key as PEM-encoded PKCS#8 with the given [`LineEnding`]. #[cfg(feature = "pem")] - #[cfg_attr(docsrs, doc(cfg(feature = "pem")))] fn to_pkcs8_pem(&self, line_ending: LineEnding) -> Result<Zeroizing<String>> { let doc = self.to_pkcs8_der()?; Ok(doc.to_pem(PrivateKeyInfo::PEM_LABEL, line_ending)?) @@ -117,7 +115,6 @@ pub trait EncodePrivateKey { /// Serialize this private key as an encrypted PEM-encoded PKCS#8 private /// key using the `provided` to derive an encryption key. #[cfg(all(feature = "encryption", feature = "pem"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "encryption", feature = "pem"))))] fn to_pkcs8_encrypted_pem( &self, rng: impl CryptoRng + RngCore, @@ -130,14 +127,12 @@ pub trait EncodePrivateKey { /// Write ASN.1 DER-encoded PKCS#8 private key to the given path #[cfg(feature = "std")] - #[cfg_attr(docsrs, doc(cfg(feature = "std")))] fn write_pkcs8_der_file(&self, path: impl AsRef<Path>) -> Result<()> { Ok(self.to_pkcs8_der()?.write_der_file(path)?) } /// Write ASN.1 DER-encoded PKCS#8 private key to the given path #[cfg(all(feature = "pem", feature = "std"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "pem", feature = "std"))))] fn write_pkcs8_pem_file(&self, path: impl AsRef<Path>, line_ending: LineEnding) -> Result<()> { let doc = self.to_pkcs8_der()?; Ok(doc.write_pem_file(path, PrivateKeyInfo::PEM_LABEL, line_ending)?) diff --git a/vendor/pkcs8/src/version.rs b/vendor/pkcs8/src/version.rs index 339368392..0ca80bc48 100644 --- a/vendor/pkcs8/src/version.rs +++ b/vendor/pkcs8/src/version.rs @@ -6,7 +6,7 @@ use der::{Decode, Encode, FixedTag, Reader, Tag, Writer}; /// Version identifier for PKCS#8 documents. /// /// (RFC 5958 designates `0` and `1` as the only valid versions for PKCS#8 documents) -#[derive(Clone, Debug, Copy, PartialEq)] +#[derive(Clone, Debug, Copy, PartialEq, Eq)] pub enum Version { /// Denotes PKCS#8 v1: no public key field. V1 = 0, @@ -36,7 +36,7 @@ impl Encode for Version { der::Length::from(1u8).for_tlv() } - fn encode(&self, writer: &mut dyn Writer) -> der::Result<()> { + fn encode(&self, writer: &mut impl Writer) -> der::Result<()> { u8::from(*self).encode(writer) } } diff --git a/vendor/pkcs8/tests/encrypted_private_key.rs b/vendor/pkcs8/tests/encrypted_private_key.rs index 2bd72aef9..dbe0a18e7 100644 --- a/vendor/pkcs8/tests/encrypted_private_key.rs +++ b/vendor/pkcs8/tests/encrypted_private_key.rs @@ -183,7 +183,7 @@ fn encrypt_ed25519_der_encpriv_aes256_pbkdf2_sha256() { #[test] fn encrypt_ed25519_der_encpriv_aes256_scrypt() { let scrypt_params = pkcs5::pbes2::Parameters::scrypt_aes256cbc( - Default::default(), + pkcs5::scrypt::Params::new(15, 8, 1, 32).unwrap(), &hex!("E6211E2348AD69E0"), &hex!("9BD0A6251F2254F9FD5963887C27CF01"), ) @@ -203,7 +203,7 @@ fn encode_ed25519_encpriv_aes256_pbkdf2_sha256_der() { let pk = EncryptedPrivateKeyInfo::try_from(ED25519_DER_AES256_PBKDF2_SHA256_EXAMPLE).unwrap(); assert_eq!( ED25519_DER_AES256_PBKDF2_SHA256_EXAMPLE, - &pk.to_vec().unwrap() + &pk.to_der().unwrap() ); } diff --git a/vendor/pkcs8/tests/private_key.rs b/vendor/pkcs8/tests/private_key.rs index 15d669495..1ef0f7361 100644 --- a/vendor/pkcs8/tests/private_key.rs +++ b/vendor/pkcs8/tests/private_key.rs @@ -1,5 +1,6 @@ //! PKCS#8 private key tests +use der::asn1::ObjectIdentifier; use hex_literal::hex; use pkcs8::{PrivateKeyInfo, Version}; @@ -48,7 +49,11 @@ fn decode_ec_p256_der() { assert_eq!(pk.algorithm.oid, "1.2.840.10045.2.1".parse().unwrap()); assert_eq!( - pk.algorithm.parameters.unwrap().oid().unwrap(), + pk.algorithm + .parameters + .unwrap() + .decode_as::<ObjectIdentifier>() + .unwrap(), "1.2.840.10045.3.1.7".parse().unwrap() ); @@ -124,7 +129,7 @@ fn decode_x25519_der() { #[cfg(feature = "alloc")] fn encode_ec_p256_der() { let pk = PrivateKeyInfo::try_from(EC_P256_DER_EXAMPLE).unwrap(); - let pk_encoded = pk.to_vec().unwrap(); + let pk_encoded = pk.to_der().unwrap(); assert_eq!(EC_P256_DER_EXAMPLE, pk_encoded); } @@ -132,14 +137,14 @@ fn encode_ec_p256_der() { #[cfg(feature = "alloc")] fn encode_ed25519_der_v1() { let pk = PrivateKeyInfo::try_from(ED25519_DER_V1_EXAMPLE).unwrap(); - assert_eq!(ED25519_DER_V1_EXAMPLE, pk.to_vec().unwrap()); + assert_eq!(ED25519_DER_V1_EXAMPLE, pk.to_der().unwrap()); } #[test] #[cfg(all(feature = "alloc", feature = "subtle"))] fn encode_ed25519_der_v2() { let private_key = PrivateKeyInfo::try_from(ED25519_DER_V2_EXAMPLE).unwrap(); - let private_der = private_key.to_vec().unwrap(); + let private_der = private_key.to_der().unwrap(); assert_eq!( private_key, PrivateKeyInfo::try_from(private_der.as_ref()).unwrap() @@ -150,7 +155,7 @@ fn encode_ed25519_der_v2() { #[cfg(feature = "alloc")] fn encode_rsa_2048_der() { let pk = PrivateKeyInfo::try_from(RSA_2048_DER_EXAMPLE).unwrap(); - assert_eq!(RSA_2048_DER_EXAMPLE, &pk.to_vec().unwrap()); + assert_eq!(RSA_2048_DER_EXAMPLE, &pk.to_der().unwrap()); } #[test] diff --git a/vendor/pkcs8/tests/traits.rs b/vendor/pkcs8/tests/traits.rs index 1c8a969bc..4a603bb94 100644 --- a/vendor/pkcs8/tests/traits.rs +++ b/vendor/pkcs8/tests/traits.rs @@ -30,12 +30,6 @@ impl AsRef<[u8]> for MockKey { } } -impl DecodePrivateKey for MockKey { - fn from_pkcs8_der(bytes: &[u8]) -> Result<MockKey> { - Ok(MockKey(bytes.to_vec())) - } -} - impl EncodePrivateKey for MockKey { fn to_pkcs8_der(&self) -> Result<SecretDocument> { Ok(SecretDocument::try_from(self.as_ref())?) @@ -46,7 +40,7 @@ impl TryFrom<PrivateKeyInfo<'_>> for MockKey { type Error = Error; fn try_from(pkcs8: PrivateKeyInfo<'_>) -> Result<MockKey> { - Ok(MockKey(pkcs8.to_vec()?)) + Ok(MockKey(pkcs8.to_der()?)) } } |