forked from sfackler/rust-openssl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sfackler#60 from vhbit/cert-gen-cleanup
Better error handling in cert generation
- Loading branch information
Showing
5 changed files
with
103 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters