Skip to content

Commit

Permalink
Implement Pkcs12 via type_!
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Nov 6, 2016
1 parent 4e2ffe5 commit 96a5ccf
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions openssl/src/pkcs12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,10 @@ use {cvt, cvt_p};
use pkey::PKey;
use error::ErrorStack;
use x509::X509;
use types::OpenSslType;
use types::{OpenSslType, OpenSslTypeRef};
use stack::Stack;

/// A PKCS #12 archive.
pub struct Pkcs12(*mut ffi::PKCS12);

impl Drop for Pkcs12 {
fn drop(&mut self) {
unsafe {
ffi::PKCS12_free(self.0);
}
}
}
type_!(Pkcs12, Pkcs12Ref, ffi::PKCS12, ffi::PKCS12_free);

impl Pkcs12 {
/// Deserializes a `Pkcs12` structure from DER-encoded data.
Expand All @@ -35,7 +26,9 @@ impl Pkcs12 {
Ok(Pkcs12(p12))
}
}
}

impl Pkcs12Ref {
/// Extracts the contents of the `Pkcs12`.
pub fn parse(&self, pass: &str) -> Result<ParsedPkcs12, ErrorStack> {
unsafe {
Expand All @@ -45,7 +38,11 @@ impl Pkcs12 {
let mut cert = ptr::null_mut();
let mut chain = ptr::null_mut();

try!(cvt(ffi::PKCS12_parse(self.0, pass.as_ptr(), &mut pkey, &mut cert, &mut chain)));
try!(cvt(ffi::PKCS12_parse(self.as_ptr(),
pass.as_ptr(),
&mut pkey,
&mut cert,
&mut chain)));

let pkey = PKey::from_ptr(pkey);
let cert = X509::from_ptr(cert);
Expand Down

0 comments on commit 96a5ccf

Please sign in to comment.