diff --git a/openssl/src/asn1.rs b/openssl/src/asn1.rs index 9a83a5da..a089b41b 100644 --- a/openssl/src/asn1.rs +++ b/openssl/src/asn1.rs @@ -1,30 +1,15 @@ use libc::c_long; use std::{ptr, fmt}; -use std::ops::Deref; - use ffi; -use opaque::Opaque; use {cvt, cvt_p}; use bio::MemBio; use error::ErrorStack; +use types::{OpenSslType, Ref}; -/// A borrowed Asn1Time -pub struct Asn1TimeRef(Opaque); +type_!(Asn1Time, ffi::ASN1_TIME, ffi::ASN1_TIME_free); -impl Asn1TimeRef { - /// Creates a new `Asn1TimeRef` wrapping the provided handle. - pub unsafe fn from_ptr<'a>(handle: *mut ffi::ASN1_TIME) -> &'a Asn1TimeRef { - &*(handle as *mut _) - } - - /// Returns the raw handle - pub fn as_ptr(&self) -> *mut ffi::ASN1_TIME { - self as *const _ as *mut _ - } -} - -impl fmt::Display for Asn1TimeRef { +impl fmt::Display for Ref { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mem_bio = try!(MemBio::new()); let as_str = unsafe { @@ -35,16 +20,7 @@ impl fmt::Display for Asn1TimeRef { } } - -/// Corresponds to the ASN.1 structure Time defined in RFC5280 -pub struct Asn1Time(*mut ffi::ASN1_TIME); - impl Asn1Time { - /// Wraps existing ASN1_TIME and takes ownership - pub unsafe fn from_ptr(handle: *mut ffi::ASN1_TIME) -> Asn1Time { - Asn1Time(handle) - } - fn from_period(period: c_long) -> Result { ffi::init(); @@ -59,17 +35,3 @@ impl Asn1Time { Asn1Time::from_period(days as c_long * 60 * 60 * 24) } } - -impl Deref for Asn1Time { - type Target = Asn1TimeRef; - - fn deref(&self) -> &Asn1TimeRef { - unsafe { Asn1TimeRef::from_ptr(self.0) } - } -} - -impl Drop for Asn1Time { - fn drop(&mut self) { - unsafe { ffi::ASN1_TIME_free(self.as_ptr()) }; - } -} diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index b49a9848..8a4941ea 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -14,7 +14,6 @@ use std::str; use {cvt, cvt_p}; use asn1::Asn1Time; -use asn1::Asn1TimeRef; use bio::{MemBio, MemBioSlice}; use crypto::CryptoString; use hash::MessageDigest; @@ -24,6 +23,7 @@ use error::ErrorStack; use ffi; use nid::Nid; use opaque::Opaque; +use types::Ref; #[cfg(ossl10x)] use ffi::{X509_set_notBefore, X509_set_notAfter, ASN1_STRING_data}; @@ -401,20 +401,20 @@ impl X509Ref { } /// Returns certificate Not After validity period. - pub fn not_after<'a>(&'a self) -> &'a Asn1TimeRef { + pub fn not_after<'a>(&'a self) -> &'a Ref { unsafe { let date = compat::X509_get_notAfter(self.as_ptr()); assert!(!date.is_null()); - Asn1TimeRef::from_ptr(date) + Ref::from_ptr(date) } } /// Returns certificate Not Before validity period. - pub fn not_before<'a>(&'a self) -> &'a Asn1TimeRef { + pub fn not_before<'a>(&'a self) -> &'a Ref { unsafe { let date = compat::X509_get_notBefore(self.as_ptr()); assert!(!date.is_null()); - Asn1TimeRef::from_ptr(date) + Ref::from_ptr(date) } }