aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/macros.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-11-13 15:27:39 +0000
committerSteven Fackler <[email protected]>2016-11-13 15:27:39 +0000
commit7d411c7975cf578205f81c2e1440c1b482a8a1a8 (patch)
treed9e142f5ff272423afa741080e9a58e7d285c11d /openssl/src/macros.rs
parentMacro-implement private_key_to_pem (diff)
downloadrust-openssl-7d411c7975cf578205f81c2e1440c1b482a8a1a8.tar.xz
rust-openssl-7d411c7975cf578205f81c2e1440c1b482a8a1a8.zip
Add private_key_from_pem_passphrase
Diffstat (limited to 'openssl/src/macros.rs')
-rw-r--r--openssl/src/macros.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/openssl/src/macros.rs b/openssl/src/macros.rs
index b225f322..9f1d7746 100644
--- a/openssl/src/macros.rs
+++ b/openssl/src/macros.rs
@@ -52,6 +52,27 @@ macro_rules! private_key_from_pem {
}
}
+ /// Deserializes a PEM-formatted private key, using the supplied password if the key is
+ /// encrypted.
+ ///
+ /// # Panics
+ ///
+ /// Panics if `passphrase` contains an embedded null.
+ pub fn private_key_from_pem_passphrase(pem: &[u8],
+ passphrase: &[u8])
+ -> Result<$t, ::error::ErrorStack> {
+ unsafe {
+ ffi::init();
+ let bio = try!(::bio::MemBioSlice::new(pem));
+ let passphrase = ::std::ffi::CString::new(passphrase).unwrap();
+ cvt_p($f(bio.as_ptr(),
+ ptr::null_mut(),
+ None,
+ passphrase.as_ptr() as *const _ as *mut _))
+ .map($t)
+ }
+ }
+
/// Deserializes a PEM-formatted private key, using a callback to retrieve a password if the
/// key is encrypted.
///
@@ -69,7 +90,7 @@ macro_rules! private_key_from_pem {
cvt_p($f(bio.as_ptr(),
ptr::null_mut(),
Some(::util::invoke_passwd_cb::<F>),
- &mut cb as *mut _ as *mut ::libc::c_void))
+ &mut cb as *mut _ as *mut _))
.map($t)
}
}
@@ -81,7 +102,7 @@ macro_rules! private_key_to_pem {
/// Serializes the private key to PEM.
pub fn private_key_to_pem(&self) -> Result<Vec<u8>, ::error::ErrorStack> {
unsafe {
- let bio = try!(MemBio::new());
+ let bio = try!(::bio::MemBio::new());
try!(cvt($f(bio.as_ptr(),
self.as_ptr(),
ptr::null(),