aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/x509/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openssl/src/x509/mod.rs')
-rw-r--r--openssl/src/x509/mod.rs22
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 {