Add `"x509_expiry"` feature flag

- fix return of `ASN1_TIME_print`
- assert on null `date`
This commit is contained in:
David Weinstein 2016-08-16 22:39:30 -04:00
parent 32a4e2ba50
commit 96b1ef829c
5 changed files with 9 additions and 4 deletions

View File

@ -625,7 +625,7 @@ extern "C" {
pub fn ASN1_INTEGER_set(dest: *mut ASN1_INTEGER, value: c_long) -> c_int; pub fn ASN1_INTEGER_set(dest: *mut ASN1_INTEGER, value: c_long) -> c_int;
pub fn ASN1_STRING_type_new(ty: c_int) -> *mut ASN1_STRING; pub fn ASN1_STRING_type_new(ty: c_int) -> *mut ASN1_STRING;
pub fn ASN1_TIME_free(tm: *mut ASN1_TIME); pub fn ASN1_TIME_free(tm: *mut ASN1_TIME);
pub fn ASN1_TIME_print(b: *mut BIO, tm: *const ASN1_TIME); pub fn ASN1_TIME_print(b: *mut BIO, tm: *const ASN1_TIME) -> c_int;
pub fn BIO_ctrl(b: *mut BIO, cmd: c_int, larg: c_long, parg: *mut c_void) -> c_long; pub fn BIO_ctrl(b: *mut BIO, cmd: c_int, larg: c_long, parg: *mut c_void) -> c_long;
pub fn BIO_free_all(b: *mut BIO); pub fn BIO_free_all(b: *mut BIO);

View File

@ -30,6 +30,7 @@ hmac_clone = ["openssl-sys/hmac_clone"]
c_helpers = ["gcc"] c_helpers = ["gcc"]
x509_clone = ["c_helpers"] x509_clone = ["c_helpers"]
x509_generator_request = ["c_helpers"] x509_generator_request = ["c_helpers"]
x509_expiry = ["c_helpers"]
ssl_context_clone = ["c_helpers"] ssl_context_clone = ["c_helpers"]
hmac = ["c_helpers"] hmac = ["c_helpers"]
dh_from_params = ["c_helpers"] dh_from_params = ["c_helpers"]

View File

@ -58,7 +58,7 @@ impl<'a> fmt::Display for Asn1TimeRef<'a> {
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 {
ffi::ASN1_TIME_print(mem_bio.as_ptr(), self.0); try_ssl!(ffi::ASN1_TIME_print(mem_bio.as_ptr(), self.0));
String::from_utf8_unchecked(mem_bio.get_buf().to_owned()) String::from_utf8_unchecked(mem_bio.get_buf().to_owned())
}; };
write!(f, "{}", as_str) write!(f, "{}", as_str)

View File

@ -15,11 +15,11 @@ STACK_OF(X509_EXTENSION) *rust_0_8_X509_get_extensions(X509 *x) {
return x->cert_info ? x->cert_info->extensions : NULL; return x->cert_info ? x->cert_info->extensions : NULL;
} }
ASN1_TIME* rust_0_8_X509_get_notAfter_shim(X509 *x) { ASN1_TIME* rust_0_8_X509_get_notAfter(X509 *x) {
return X509_get_notAfter(x); return X509_get_notAfter(x);
} }
ASN1_TIME* rust_0_8_X509_get_notBefore_shim(X509 *x) { ASN1_TIME* rust_0_8_X509_get_notBefore(X509 *x) {
return X509_get_notBefore(x); return X509_get_notBefore(x);
} }

View File

@ -434,17 +434,21 @@ impl<'a> X509Ref<'a> {
} }
/// Returns Issuer validity notAfter /// Returns Issuer validity notAfter
#[cfg(feature = "x509_expiry")]
pub fn not_after(&self) -> Asn1TimeRef { pub fn not_after(&self) -> Asn1TimeRef {
unsafe { unsafe {
let date = ::c_helpers::rust_0_8_X509_get_notAfter(self.0); let date = ::c_helpers::rust_0_8_X509_get_notAfter(self.0);
assert!(!date.is_null());
Asn1TimeRef::from_ptr(date) Asn1TimeRef::from_ptr(date)
} }
} }
/// Returns Issuer validity notBefore /// Returns Issuer validity notBefore
#[cfg(feature = "x509_expiry")]
pub fn not_before(&self) -> Asn1TimeRef { pub fn not_before(&self) -> Asn1TimeRef {
unsafe { unsafe {
let date = ::c_helpers::rust_0_8_X509_get_notBefore(self.0); let date = ::c_helpers::rust_0_8_X509_get_notBefore(self.0);
assert!(!date.is_null());
Asn1TimeRef::from_ptr(date) Asn1TimeRef::from_ptr(date)
} }
} }