diff options
| author | Onur Aslan <[email protected]> | 2016-07-29 12:11:53 +0300 |
|---|---|---|
| committer | Onur Aslan <[email protected]> | 2016-07-29 12:14:49 +0300 |
| commit | 5ed77df197afc33c04569edcd3db5993a695fbae (patch) | |
| tree | 850ae655923d264436673a585e4eb03c431d3f06 /openssl/src/x509/mod.rs | |
| parent | Merge pull request #423 from taheris/fix/moving-write-buffer (diff) | |
| download | rust-openssl-5ed77df197afc33c04569edcd3db5993a695fbae.tar.xz rust-openssl-5ed77df197afc33c04569edcd3db5993a695fbae.zip | |
Implement save_der for X509 and X509Req
Diffstat (limited to 'openssl/src/x509/mod.rs')
| -rw-r--r-- | openssl/src/x509/mod.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index 3150cc6e..396d50df 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -532,6 +532,17 @@ impl<'ctx> X509<'ctx> { } io::copy(&mut mem_bio, writer).map_err(StreamError).map(|_| ()) } + + /// Returns a DER serialized form of the certificate + pub fn save_der(&self) -> Result<Vec<u8>, SslError> { + let mut mem_bio = try!(MemBio::new()); + unsafe { + ffi::i2d_X509_bio(mem_bio.get_handle(), self.handle); + } + let mut v = Vec::new(); + try!(io::copy(&mut mem_bio, &mut v).map_err(StreamError)); + Ok(v) + } } extern "C" { @@ -637,6 +648,17 @@ impl X509Req { } io::copy(&mut mem_bio, writer).map_err(StreamError).map(|_| ()) } + + /// Returns a DER serialized form of the CSR + pub fn save_der(&self) -> Result<Vec<u8>, SslError> { + let mut mem_bio = try!(MemBio::new()); + unsafe { + ffi::i2d_X509_REQ_bio(mem_bio.get_handle(), self.handle); + } + let mut v = Vec::new(); + try!(io::copy(&mut mem_bio, &mut v).map_err(StreamError)); + Ok(v) + } } impl Drop for X509Req { |