From 59240f82ab747c85de33bb435259a49703cb0d84 Mon Sep 17 00:00:00 2001 From: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:32:53 -0800 Subject: [PATCH] Enable key encoding with the `pkcs5` feature I made `pkcs5` enable the RSA encoding traits it needs even when default features are off. I added a doctest showing how to load an encrypted PKCS#8 key with that feature. Assisted-by: Claude Assisted-by: GPT-6 Astra Signed-off-by: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com> --- Cargo.toml | 2 +- src/lib.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 47f9b010..7b633bb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ hazmat = [] pkcs1v15 = [] # PKCS #1 v1.5 is only supported as opt-in basis for legacy protocols getrandom = ["crypto-bigint/getrandom", "crypto-common/getrandom"] serde = ["encoding", "dep:serde", "dep:serdect", "crypto-bigint/serde"] -pkcs5 = ["pkcs8/encryption"] +pkcs5 = ["encoding", "pkcs8/encryption"] [lints.clippy] borrow_as_ptr = "warn" diff --git a/src/lib.rs b/src/lib.rs index 5dbe1d5e..067a5580 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -236,6 +236,17 @@ //! # } //! ``` //! +//! With the `pkcs5` feature, you can also read password-encrypted PKCS#8 keys: +//! +#![cfg_attr(feature = "pkcs5", doc = "```")] +#![cfg_attr(not(feature = "pkcs5"), doc = "```ignore")] +//! use rsa::{PrivateKey, pkcs8::{self, DecodePrivateKey}}; +//! +//! fn load_key(der: &[u8], password: &[u8]) -> pkcs8::Result { +//! PrivateKey::from_pkcs8_encrypted_der(der, password) +//! } +//! ``` +//! //! [RFC8017]: https://www.rfc-editor.org/rfc/rfc8017.html //! // TODO(tarcieri): figure out why rustdoc isn't rendering these links correctly