aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/asn1
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-08-06 22:23:03 -0700
committerSteven Fackler <[email protected]>2016-08-06 22:23:03 -0700
commit5af01a5dbd42a20cd8114f03168b014ae4d9d023 (patch)
tree1a5796194f0b3cff73c50ba354cdbf52caf62f8f /openssl/src/asn1
parentget_handle -> handle (diff)
downloadrust-openssl-5af01a5dbd42a20cd8114f03168b014ae4d9d023.tar.xz
rust-openssl-5af01a5dbd42a20cd8114f03168b014ae4d9d023.zip
Clean up asn1time
Diffstat (limited to 'openssl/src/asn1')
-rw-r--r--openssl/src/asn1/mod.rs34
1 files changed, 13 insertions, 21 deletions
diff --git a/openssl/src/asn1/mod.rs b/openssl/src/asn1/mod.rs
index 39273cb8..e79a0fd2 100644
--- a/openssl/src/asn1/mod.rs
+++ b/openssl/src/asn1/mod.rs
@@ -4,44 +4,36 @@ use std::ptr;
use ffi;
use error::ErrorStack;
-pub struct Asn1Time {
- handle: *mut ffi::ASN1_TIME,
- owned: bool,
-}
+pub struct Asn1Time(*mut ffi::ASN1_TIME);
impl Asn1Time {
/// Wraps existing ASN1_TIME and takes ownership
- pub fn new(handle: *mut ffi::ASN1_TIME) -> Asn1Time {
- Asn1Time {
- handle: handle,
- owned: true,
- }
+ pub unsafe fn from_raw(handle: *mut ffi::ASN1_TIME) -> Asn1Time {
+ Asn1Time(handle)
}
- fn new_with_period(period: u64) -> Result<Asn1Time, ErrorStack> {
+ fn from_period(period: u64) -> Result<Asn1Time, ErrorStack> {
ffi::init();
- let handle = unsafe {
- try_ssl_null!(ffi::X509_gmtime_adj(ptr::null_mut(), period as c_long))
- };
- Ok(Asn1Time::new(handle))
+ unsafe {
+ let handle = try_ssl_null!(ffi::X509_gmtime_adj(ptr::null_mut(), period as c_long));
+ Ok(Asn1Time::from_raw(handle))
+ }
}
/// Creates a new time on specified interval in days from now
pub fn days_from_now(days: u32) -> Result<Asn1Time, ErrorStack> {
- Asn1Time::new_with_period(days as u64 * 60 * 60 * 24)
+ Asn1Time::from_period(days as u64 * 60 * 60 * 24)
}
- /// Returns raw handle
- pub unsafe fn handle(&self) -> *mut ffi::ASN1_TIME {
- return self.handle;
+ /// Returns the raw handle
+ pub fn handle(&self) -> *mut ffi::ASN1_TIME {
+ self.0
}
}
impl Drop for Asn1Time {
fn drop(&mut self) {
- if self.owned {
- unsafe { ffi::ASN1_TIME_free(self.handle) };
- }
+ unsafe { ffi::ASN1_TIME_free(self.0) };
}
}