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/macros.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/macros.rs')
| -rw-r--r-- | openssl/src/macros.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/openssl/src/macros.rs b/openssl/src/macros.rs index 9f1d7746..6c37f7b0 100644 --- a/openssl/src/macros.rs +++ b/openssl/src/macros.rs @@ -113,5 +113,25 @@ macro_rules! private_key_to_pem { Ok(bio.get_buf().to_owned()) } } + + /// Serializes the private key to PEM, encrypting it with the specified symmetric cipher and + /// passphrase. + pub fn private_key_to_pem_passphrase(&self, + cipher: ::symm::Cipher, + passphrase: &[u8]) + -> Result<Vec<u8>, ::error::ErrorStack> { + unsafe { + let bio = try!(::bio::MemBio::new()); + assert!(passphrase.len() <= ::libc::c_int::max_value() as usize); + try!(cvt($f(bio.as_ptr(), + self.as_ptr(), + cipher.as_ptr(), + passphrase.as_ptr() as *const _ as *mut _, + passphrase.len() as ::libc::c_int, + None, + ptr::null_mut()))); + Ok(bio.get_buf().to_owned()) + } + } } } |