Skip to content

Commit

Permalink
Add note about encoding keys (#163)
Browse files Browse the repository at this point in the history
* Add note about encoding keys

* Update encoding.rs

* Format code
  • Loading branch information
arniu authored Dec 7, 2020
1 parent 90b9700 commit 2f25cbe
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ impl EncodingKey {

/// If you are loading a RSA key from a .pem file.
/// This errors if the key is not a valid RSA key.
///
/// # NOTE
///
/// According to the [ring doc](https://briansmith.org/rustdoc/ring/signature/struct.RsaKeyPair.html#method.from_pkcs8),
/// the key should be at least 2047 bits.
///
pub fn from_rsa_pem(key: &[u8]) -> Result<Self> {
let pem_key = PemEncodedKey::new(key)?;
let content = pem_key.as_rsa_key()?;
Expand All @@ -37,6 +43,17 @@ impl EncodingKey {

/// If you are loading a ECDSA key from a .pem file
/// This errors if the key is not a valid private EC key
///
/// # NOTE
///
/// The key should be in PKCS#8 form.
///
/// You can generate a key with the following:
///
/// ```sh
/// openssl ecparam -genkey -noout -name prime256v1 \
/// | openssl pkcs8 -topk8 -nocrypt -out ec-private.pem
/// ```
pub fn from_ec_pem(key: &[u8]) -> Result<Self> {
let pem_key = PemEncodedKey::new(key)?;
let content = pem_key.as_ec_private_key()?;
Expand Down

0 comments on commit 2f25cbe

Please sign in to comment.