Convert Asn1Time
This commit is contained in:
parent
3363046c34
commit
849fca4a7b
|
|
@ -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<Asn1Time> {
|
||||
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<Asn1Time, ErrorStack> {
|
||||
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()) };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Asn1Time> {
|
||||
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<Asn1Time> {
|
||||
unsafe {
|
||||
let date = compat::X509_get_notBefore(self.as_ptr());
|
||||
assert!(!date.is_null());
|
||||
Asn1TimeRef::from_ptr(date)
|
||||
Ref::from_ptr(date)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue