aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-10-21 17:13:30 -0700
committerSteven Fackler <[email protected]>2016-10-21 17:13:30 -0700
commitb7017a7eecf57aa6f1ab18ea1da771bafcab2ea9 (patch)
treebb601aa88f027eeeab082d121569cec96033f750 /openssl/src
parentConvert X509Ref (diff)
downloadrust-openssl-b7017a7eecf57aa6f1ab18ea1da771bafcab2ea9.tar.xz
rust-openssl-b7017a7eecf57aa6f1ab18ea1da771bafcab2ea9.zip
Update Asn1TimeRef
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/asn1.rs67
-rw-r--r--openssl/src/x509/mod.rs4
2 files changed, 38 insertions, 33 deletions
diff --git a/openssl/src/asn1.rs b/openssl/src/asn1.rs
index 91f920a3..7e7cb3df 100644
--- a/openssl/src/asn1.rs
+++ b/openssl/src/asn1.rs
@@ -2,19 +2,48 @@ use libc::c_long;
use std::{ptr, fmt};
use std::marker::PhantomData;
use std::ops::Deref;
+
use ffi;
+use opaque::Opaque;
use {cvt, cvt_p};
use bio::MemBio;
use error::ErrorStack;
+/// A borrowed Asn1Time
+pub struct Asn1TimeRef(Opaque);
+
+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 {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let mem_bio = try!(MemBio::new());
+ let as_str = unsafe {
+ try!(cvt(ffi::ASN1_TIME_print(mem_bio.as_ptr(), self.as_ptr())));
+ String::from_utf8_unchecked(mem_bio.get_buf().to_owned())
+ };
+ write!(f, "{}", as_str)
+ }
+}
+
+
/// Corresponds to the ASN.1 structure Time defined in RFC5280
-pub struct Asn1Time(Asn1TimeRef<'static>);
+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(Asn1TimeRef::from_ptr(handle))
+ Asn1Time(handle)
}
fn from_period(period: c_long) -> Result<Asn1Time, ErrorStack> {
@@ -33,36 +62,12 @@ impl Asn1Time {
}
impl Deref for Asn1Time {
- type Target = Asn1TimeRef<'static>;
+ type Target = Asn1TimeRef;
- fn deref(&self) -> &Asn1TimeRef<'static> {
- &self.0
- }
-}
-
-/// A borrowed Asn1Time
-pub struct Asn1TimeRef<'a>(*mut ffi::ASN1_TIME, PhantomData<&'a ()>);
-
-impl<'a> Asn1TimeRef<'a> {
- /// Creates a new `Asn1TimeRef` wrapping the provided handle.
- pub unsafe fn from_ptr(handle: *mut ffi::ASN1_TIME) -> Asn1TimeRef<'a> {
- Asn1TimeRef(handle, PhantomData)
- }
-
- /// Returns the raw handle
- pub fn as_ptr(&self) -> *mut ffi::ASN1_TIME {
- self.0
- }
-}
-
-impl<'a> fmt::Display for Asn1TimeRef<'a> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let mem_bio = try!(MemBio::new());
- let as_str = unsafe {
- try!(cvt(ffi::ASN1_TIME_print(mem_bio.as_ptr(), self.0)));
- String::from_utf8_unchecked(mem_bio.get_buf().to_owned())
- };
- write!(f, "{}", as_str)
+ fn deref(&self) -> &Asn1TimeRef {
+ unsafe {
+ Asn1TimeRef::from_ptr(self.0)
+ }
}
}
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index 99710fc4..9c91bfc1 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -446,7 +446,7 @@ impl X509Ref {
}
/// Returns certificate Not After validity period.
- pub fn not_after<'a>(&'a self) -> Asn1TimeRef<'a> {
+ pub fn not_after<'a>(&'a self) -> &'a Asn1TimeRef {
unsafe {
let date = compat::X509_get_notAfter(self.as_ptr());
assert!(!date.is_null());
@@ -455,7 +455,7 @@ impl X509Ref {
}
/// Returns certificate Not Before validity period.
- pub fn not_before<'a>(&'a self) -> Asn1TimeRef<'a> {
+ pub fn not_before<'a>(&'a self) -> &'a Asn1TimeRef {
unsafe {
let date = compat::X509_get_notBefore(self.as_ptr());
assert!(!date.is_null());