Skip to content

Commit

Permalink
docs: add mention of no Clone on private keys
Browse files Browse the repository at this point in the history
This comes up with some frequency and since it's a deliberate choice
I think it makes sense to call out in the README and in lib.rs's rustdoc
header.
  • Loading branch information
cpu committed Feb 7, 2024
1 parent cc7a758 commit 204a83d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ The [rustls-pemfile](https://docs.rs/rustls-pemfile) crate can be used to parse

This crate does not provide any functionality for creating new certificates or keys. However,
the [rcgen](https://docs.rs/rcgen) crate can be used to create new certificates and keys.

## Cloning private keys

This crate intentionally **does not** implement `Clone` on private key types in
order to minimize the exposure of private key data in memory.

Since these types are immutable, if you find you're self wanting to clone them
it may be better to consider wrapping the `PrivateKeyDer<'_>` in a [`Rc`]` or
[`Arc`].

[`Rc`]: https://doc.rust-lang.org/std/rc/struct.Rc.html
[`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
//!
//! This crate does not provide any functionality for creating new certificates or keys. However,
//! the [rcgen](https://docs.rs/rcgen) crate can be used to create new certificates and keys.
//!
//! ## Cloning private keys
//!
//! This crate intentionally **does not** implement `Clone` on private key types in
//! order to minimize the exposure of private key data in memory.
//!
//! Since these types are immutable, if you find you're self wanting to clone them
//! it may be better to consider wrapping the `PrivateKeyDer<'_>` in a [`Rc`]` or
//! [`Arc`].
//!
//! [`Rc`]: https://doc.rust-lang.org/std/rc/struct.Rc.html
//! [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(unreachable_pub, clippy::use_self)]
Expand Down

0 comments on commit 204a83d

Please sign in to comment.