aboutsummaryrefslogtreecommitdiff
path: root/src/asn1
diff options
context:
space:
mode:
authorValerii Hiora <[email protected]>2014-10-01 20:19:29 +0300
committerValerii Hiora <[email protected]>2014-10-06 07:12:54 +0300
commit72ee42adba18adbb0e6eefd13faab5e6d610fdcd (patch)
tree2ce3241b11f7a6f53fa9127e8a1e8085a4d1f6e8 /src/asn1
parentIgnore stderr from openssl s_server (diff)
downloadrust-openssl-72ee42adba18adbb0e6eefd13faab5e6d610fdcd.tar.xz
rust-openssl-72ee42adba18adbb0e6eefd13faab5e6d610fdcd.zip
Better error handling in cert generation
Now it should correctly free all resources in case of failure.
Diffstat (limited to 'src/asn1')
-rw-r--r--src/asn1/mod.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/asn1/mod.rs b/src/asn1/mod.rs
index e69de29b..2cd4584f 100644
--- a/src/asn1/mod.rs
+++ b/src/asn1/mod.rs
@@ -0,0 +1,47 @@
+use libc::{c_long};
+use std::ptr;
+
+use ffi;
+use ssl::error::{SslError};
+
+
+pub struct Asn1Time {
+ handle: *mut ffi::ASN1_TIME,
+ owned: bool
+}
+
+impl Asn1Time {
+ /// Wraps existing ASN1_TIME and takes ownership
+ pub fn new(handle: *mut ffi::ASN1_TIME) -> Asn1Time {
+ Asn1Time {
+ handle: handle,
+ owned: true
+ }
+ }
+
+ fn new_with_period(period: u64) -> Result<Asn1Time, SslError> {
+ let handle = unsafe {
+ try_ssl_null!(ffi::X509_gmtime_adj(ptr::null_mut(),
+ period as c_long))
+ };
+ Ok(Asn1Time::new(handle))
+ }
+
+ /// Creates a new time on specified interval in days from now
+ pub fn days_from_now(days: uint) -> Result<Asn1Time, SslError> {
+ Asn1Time::new_with_period(days as u64 * 60 * 60 * 24)
+ }
+
+ /// Returns raw handle
+ pub unsafe fn get_handle(&self) -> *mut ffi::ASN1_TIME {
+ return self.handle
+ }
+}
+
+impl Drop for Asn1Time {
+ fn drop(&mut self) {
+ if self.owned {
+ unsafe { ffi::ASN1_TIME_free(self.handle) };
+ }
+ }
+}