Convert Asn1Time
This commit is contained in:
parent
3363046c34
commit
849fca4a7b
|
|
@ -1,30 +1,15 @@
|
||||||
use libc::c_long;
|
use libc::c_long;
|
||||||
use std::{ptr, fmt};
|
use std::{ptr, fmt};
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use ffi;
|
use ffi;
|
||||||
use opaque::Opaque;
|
|
||||||
|
|
||||||
use {cvt, cvt_p};
|
use {cvt, cvt_p};
|
||||||
use bio::MemBio;
|
use bio::MemBio;
|
||||||
use error::ErrorStack;
|
use error::ErrorStack;
|
||||||
|
use types::{OpenSslType, Ref};
|
||||||
|
|
||||||
/// A borrowed Asn1Time
|
type_!(Asn1Time, ffi::ASN1_TIME, ffi::ASN1_TIME_free);
|
||||||
pub struct Asn1TimeRef(Opaque);
|
|
||||||
|
|
||||||
impl Asn1TimeRef {
|
impl fmt::Display for Ref<Asn1Time> {
|
||||||
/// 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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let mem_bio = try!(MemBio::new());
|
let mem_bio = try!(MemBio::new());
|
||||||
let as_str = unsafe {
|
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 {
|
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> {
|
fn from_period(period: c_long) -> Result<Asn1Time, ErrorStack> {
|
||||||
ffi::init();
|
ffi::init();
|
||||||
|
|
||||||
|
|
@ -59,17 +35,3 @@ impl Asn1Time {
|
||||||
Asn1Time::from_period(days as c_long * 60 * 60 * 24)
|
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 {cvt, cvt_p};
|
||||||
use asn1::Asn1Time;
|
use asn1::Asn1Time;
|
||||||
use asn1::Asn1TimeRef;
|
|
||||||
use bio::{MemBio, MemBioSlice};
|
use bio::{MemBio, MemBioSlice};
|
||||||
use crypto::CryptoString;
|
use crypto::CryptoString;
|
||||||
use hash::MessageDigest;
|
use hash::MessageDigest;
|
||||||
|
|
@ -24,6 +23,7 @@ use error::ErrorStack;
|
||||||
use ffi;
|
use ffi;
|
||||||
use nid::Nid;
|
use nid::Nid;
|
||||||
use opaque::Opaque;
|
use opaque::Opaque;
|
||||||
|
use types::Ref;
|
||||||
|
|
||||||
#[cfg(ossl10x)]
|
#[cfg(ossl10x)]
|
||||||
use ffi::{X509_set_notBefore, X509_set_notAfter, ASN1_STRING_data};
|
use ffi::{X509_set_notBefore, X509_set_notAfter, ASN1_STRING_data};
|
||||||
|
|
@ -401,20 +401,20 @@ impl X509Ref {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns certificate Not After validity period.
|
/// 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 {
|
unsafe {
|
||||||
let date = compat::X509_get_notAfter(self.as_ptr());
|
let date = compat::X509_get_notAfter(self.as_ptr());
|
||||||
assert!(!date.is_null());
|
assert!(!date.is_null());
|
||||||
Asn1TimeRef::from_ptr(date)
|
Ref::from_ptr(date)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns certificate Not Before validity period.
|
/// 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 {
|
unsafe {
|
||||||
let date = compat::X509_get_notBefore(self.as_ptr());
|
let date = compat::X509_get_notBefore(self.as_ptr());
|
||||||
assert!(!date.is_null());
|
assert!(!date.is_null());
|
||||||
Asn1TimeRef::from_ptr(date)
|
Ref::from_ptr(date)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue