diff options
| author | Steven Fackler <[email protected]> | 2016-11-13 16:09:52 +0000 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-11-13 16:09:52 +0000 |
| commit | 387e78257b578fef5933142085aefa1c76722b49 (patch) | |
| tree | 319cee47bc8e88f7f083ef14937b35a64c637344 /openssl/src/pkey.rs | |
| parent | Add private_key_from_pem_passphrase (diff) | |
| download | rust-openssl-387e78257b578fef5933142085aefa1c76722b49.tar.xz rust-openssl-387e78257b578fef5933142085aefa1c76722b49.zip | |
Support serialization of encrypted private keys
Switch to PEM_write_bio_PKCS8PrivateKey since the other function outputs
nonstandard PEM when encrypting.
Diffstat (limited to 'openssl/src/pkey.rs')
| -rw-r--r-- | openssl/src/pkey.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs index 27b36c4b..079a04cc 100644 --- a/openssl/src/pkey.rs +++ b/openssl/src/pkey.rs @@ -48,7 +48,7 @@ impl PKeyRef { } } - private_key_to_pem!(ffi::PEM_write_bio_PrivateKey); + private_key_to_pem!(ffi::PEM_write_bio_PKCS8PrivateKey); /// Encodes the public key in the PEM format. pub fn public_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> { @@ -185,6 +185,7 @@ impl PKey { #[cfg(test)] mod tests { + use symm::Cipher; use dh::Dh; use dsa::Dsa; use ec_key::EcKey; @@ -194,6 +195,15 @@ mod tests { use super::*; #[test] + fn test_to_password() { + let rsa = Rsa::generate(2048).unwrap(); + let pkey = PKey::from_rsa(rsa).unwrap(); + let pem = pkey.private_key_to_pem_passphrase(Cipher::aes_128_cbc(), b"foobar").unwrap(); + PKey::private_key_from_pem_passphrase(&pem, b"foobar").unwrap(); + assert!(PKey::private_key_from_pem_passphrase(&pem, b"fizzbuzz").is_err()); + } + + #[test] fn test_private_key_from_pem() { let key = include_bytes!("../test/key.pem"); PKey::private_key_from_pem(key).unwrap(); |