-
Notifications
You must be signed in to change notification settings - Fork 140
Implement From<KeyPair> for PrivateKeyDer<'static>
#403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
9a630fb to
2de3e3c
Compare
|
What is your use case for this exactly? We typically prefer not to use shared (immutable) references to propagate private key material, instead transferring it by ownership only. The current rcgen is not so strict in this regard, but I'd prefer not to make it worse, and it seems like you can already do what you need today (I think the easier route would be |
Well, if this is intentional, then okay i guess. But this really seems odd from the outside. |
|
I would be open to taking a |
Okay, is this what you had in mind? |
From<&'a KeyPair> for PrivateKeyDer<'a>From<KeyPair> for PrivateKeyDer<'static>
|
@djc thank you for taking a look! |
|
(We're using the merge queue to rebase, so we'll need all the commits to be squashed into a single one.) |
The "obvious" and safe way to go from `KeyPair` to `PrivateKeyDer`
seems to round-tripping via PEM:
```
rustls::pki_types::PrivateKeyDer::from_pem_slice(
signing_key.serialize_pem().as_bytes(),
)
```
But `rcgen::key_pair::KeyPair::serialized_der()` is
```
/// Returns a reference to the serialized key pair (including the private key)
/// in PKCS#8 format in DER
```
and `PrivateKeyDer` can be constructed from such a input.
This avoids memory allocation and PEM roundtripping,
both of which are optional features anyways,
and this conversion is non-failing.
7db82fb to
46bf626
Compare
|
@djc thank you! |
I've stumbled into this when trying to write a simple rustls-driven server with self-signed cert.
The "obvious" and safe way to go from
KeyPairtoPrivateKeyDerseems to round-tripping via PEM:But
rcgen::key_pair::KeyPair::serialized_der()isand
PrivateKeyDercan be constructed from such a input.This avoids memory allocation and PEM roundtripping,
both of which are optional features anyways,
and this conversion is non-failing.
Perhaps it makes sense to provide this QOL interface?