Skip to content

Commit

Permalink
Remove converting PKCS#8 passphrase to CString
Browse files Browse the repository at this point in the history
It's not required, there's an explicit length.
  • Loading branch information
alex committed May 31, 2023
1 parent 79ad66a commit 9fa082c
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions openssl/src/pkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,6 @@ where

/// Serializes a private key into a DER-formatted PKCS#8, using the supplied password to
/// encrypt the key.
///
/// # Panics
///
/// Panics if `passphrase` contains an embedded null.
#[corresponds(i2d_PKCS8PrivateKey_bio)]
pub fn private_key_to_pkcs8_passphrase(
&self,
Expand All @@ -362,14 +358,12 @@ where
) -> Result<Vec<u8>, ErrorStack> {
unsafe {
let bio = MemBio::new()?;
let len = passphrase.len();
let passphrase = CString::new(passphrase).unwrap();
cvt(ffi::i2d_PKCS8PrivateKey_bio(
bio.as_ptr(),
self.as_ptr(),
cipher.as_ptr(),
passphrase.as_ptr() as *const _ as *mut _,
len as ::libc::c_int,
passphrase.len() as ::libc::c_int,
None,
ptr::null_mut(),
))?;
Expand Down

0 comments on commit 9fa082c

Please sign in to comment.