diff options
| author | Steven Fackler <[email protected]> | 2017-08-09 14:20:51 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-08-09 14:20:51 -0700 |
| commit | 4c3b3476f462871bfecf929afc5e9564c7fdc10a (patch) | |
| tree | 8132826185e249e91b2f2863e4601bae15b778b3 /openssl/src | |
| parent | Delete DTLS tests (diff) | |
| parent | added cms decryption (diff) | |
| download | rust-openssl-4c3b3476f462871bfecf929afc5e9564c7fdc10a.tar.xz rust-openssl-4c3b3476f462871bfecf929afc5e9564c7fdc10a.zip | |
Merge pull request #675 from sdemos/master
added cms decryption
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/cms.rs | 60 | ||||
| -rw-r--r-- | openssl/src/lib.rs | 2 |
2 files changed, 62 insertions, 0 deletions
diff --git a/openssl/src/cms.rs b/openssl/src/cms.rs new file mode 100644 index 00000000..9619d0b8 --- /dev/null +++ b/openssl/src/cms.rs @@ -0,0 +1,60 @@ +//! CMS archive + +use ffi; +use foreign_types::{ForeignType, ForeignTypeRef}; +use std::ptr; +use error::ErrorStack; + +use bio::{MemBio, MemBioSlice}; + +use x509::X509; +use pkey::PKeyRef; + +use cvt; +use cvt_p; + +foreign_type! { + type CType = ffi::CMS_ContentInfo; + fn drop = ffi::CMS_ContentInfo_free; + + pub struct CmsContentInfo; + pub struct CmsContentInfoRef; +} + +impl CmsContentInfoRef { + pub fn decrypt(&self, pkey: &PKeyRef, cert: &X509) -> Result<Vec<u8>, ErrorStack> { + unsafe { + let pkey = pkey.as_ptr(); + let cert = cert.as_ptr(); + let out = try!(MemBio::new()); + let flags: u32 = 0; + + try!(cvt(ffi::CMS_decrypt( + self.as_ptr(), + pkey, + cert, + ptr::null_mut(), + out.as_ptr(), + flags.into(), + ))); + + Ok(out.get_buf().to_owned()) + } + } + +} + +impl CmsContentInfo { + pub fn smime_read_cms(smime: &[u8]) -> Result<CmsContentInfo, ErrorStack> { + unsafe { + let bio = try!(MemBioSlice::new(smime)); + + let cms = try!(cvt_p(ffi::SMIME_read_CMS( + bio.as_ptr(), + ptr::null_mut(), + ))); + + Ok(CmsContentInfo::from_ptr(cms)) + } + } +} diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index a6d5e6a0..d71d8d9d 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -31,6 +31,8 @@ mod util; pub mod aes; pub mod asn1; pub mod bn; +#[cfg(not(libressl))] +pub mod cms; pub mod conf; pub mod crypto; pub mod dh; |