Skip to content

Commit 9040594

Browse files
committed
docs: add mention of no Clone on private keys
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.
1 parent cc7a758 commit 9040594

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ The [rustls-pemfile](https://docs.rs/rustls-pemfile) crate can be used to parse
3838

3939
This crate does not provide any functionality for creating new certificates or keys. However,
4040
the [rcgen](https://docs.rs/rcgen) crate can be used to create new certificates and keys.
41+
42+
## Cloning private keys
43+
44+
This crate intentionally **does not** implement `Clone` on private key types in
45+
order to minimize the exposure of private key data in memory.
46+
47+
Since these types are immutable, if you find you're self wanting to clone them
48+
it may be better to consider wrapping the `PrivateKeyDer<'_>` in a [`Rc`]` or
49+
[`Arc`].
50+
51+
[`Rc`]: https://doc.rust-lang.org/std/rc/struct.Rc.html
52+
[`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html

src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
//!
2626
//! This crate does not provide any functionality for creating new certificates or keys. However,
2727
//! the [rcgen](https://docs.rs/rcgen) crate can be used to create new certificates and keys.
28+
//!
29+
//! ## Cloning private keys
30+
//!
31+
//! This crate intentionally **does not** implement `Clone` on private key types in
32+
//! order to minimize the exposure of private key data in memory.
33+
//!
34+
//! Since these types are immutable, if you find you're self wanting to clone them
35+
//! it may be better to consider wrapping the `PrivateKeyDer<'_>` in a [`Rc`]` or
36+
//! [`Arc`].
37+
//!
38+
//! [`Rc`]: https://doc.rust-lang.org/std/rc/struct.Rc.html
39+
//! [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
2840
2941
#![cfg_attr(not(feature = "std"), no_std)]
3042
#![warn(unreachable_pub, clippy::use_self)]

0 commit comments

Comments
 (0)