Skip to content

Commit

Permalink
key_pair: emphasize PKCS8 in from der & alg constructor
Browse files Browse the repository at this point in the history
The `KeyPair::from_der_and_sign_algo` fn expects PKCS8 formatted DER as
input. This commit renames the fn to
`Keypair::from_pkcs8_der_and_sign_algo` to emphasize this, and to pave
the way for a more generalized fn to be added in the future.
  • Loading branch information
cpu committed Mar 19, 2024
1 parent 05b5fd9 commit b61393a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions rcgen/src/key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl KeyPair {
) -> Result<Self, Error> {
let private_key = pem::parse(pem_str)._err()?;
let private_key_der: &[_] = private_key.contents();
Self::from_der_and_sign_algo(&PrivatePkcs8KeyDer::from(private_key_der), alg)
Self::from_pkcs8_der_and_sign_algo(&PrivatePkcs8KeyDer::from(private_key_der), alg)
}

/// Obtains the key pair from a DER formatted key using the specified [`SignatureAlgorithm`]
Expand All @@ -215,7 +215,7 @@ impl KeyPair {
/// [`rustls_pemfile::private_key()`]: https://docs.rs/rustls-pemfile/latest/rustls_pemfile/fn.private_key.html
/// [`PrivateKeyDer`]: https://docs.rs/rustls-pki-types/latest/rustls_pki_types/enum.PrivateKeyDer.html
#[cfg(feature = "crypto")]
pub fn from_der_and_sign_algo(
pub fn from_pkcs8_der_and_sign_algo(
pkcs8: &PrivatePkcs8KeyDer<'_>,
alg: &'static SignatureAlgorithm,
) -> Result<Self, Error> {
Expand Down
6 changes: 3 additions & 3 deletions rustls-cert-gen/src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl KeyPairAlgorithm {
let pkcs8_bytes =
Ed25519KeyPair::generate_pkcs8(&rng).or(Err(rcgen::Error::RingUnspecified))?;

rcgen::KeyPair::from_der_and_sign_algo(&pkcs8_bytes.as_ref().into(), alg)
rcgen::KeyPair::from_pkcs8_der_and_sign_algo(&pkcs8_bytes.as_ref().into(), alg)
},
KeyPairAlgorithm::EcdsaP256 => {
use ring::signature::EcdsaKeyPair;
Expand All @@ -250,7 +250,7 @@ impl KeyPairAlgorithm {
let pkcs8_bytes =
EcdsaKeyPair::generate_pkcs8(&ECDSA_P256_SHA256_ASN1_SIGNING, &rng)
.or(Err(rcgen::Error::RingUnspecified))?;
rcgen::KeyPair::from_der_and_sign_algo(&pkcs8_bytes.as_ref().into(), alg)
rcgen::KeyPair::from_pkcs8_der_and_sign_algo(&pkcs8_bytes.as_ref().into(), alg)
},
KeyPairAlgorithm::EcdsaP384 => {
use ring::signature::EcdsaKeyPair;
Expand All @@ -262,7 +262,7 @@ impl KeyPairAlgorithm {
EcdsaKeyPair::generate_pkcs8(&ECDSA_P384_SHA384_ASN1_SIGNING, &rng)
.or(Err(rcgen::Error::RingUnspecified))?;

rcgen::KeyPair::from_der_and_sign_algo(&pkcs8_bytes.as_ref().into(), alg)
rcgen::KeyPair::from_pkcs8_der_and_sign_algo(&pkcs8_bytes.as_ref().into(), alg)
},
}
}
Expand Down

0 comments on commit b61393a

Please sign in to comment.