aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/x509
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-08-15 18:46:15 -0700
committerSteven Fackler <[email protected]>2016-08-15 18:46:15 -0700
commit0f428d190410263e4daa65b917c0e84707a9c0ef (patch)
tree4d6d5b8b77c7ca5755a3636786b8a36584fba92a /openssl/src/x509
parentMerge branch 'release-v0.7.15-sys-v0.8.0' into release (diff)
parentRelease openssl-sys v0.7.16, openssl v0.8.1 (diff)
downloadrust-openssl-openssl-sys-v0.7.16.tar.xz
rust-openssl-openssl-sys-v0.7.16.zip
Merge branch 'release-sys-v0.7.16-v0.8.1' into releaseopenssl-v0.8.1openssl-sys-v0.7.16
Diffstat (limited to 'openssl/src/x509')
-rw-r--r--openssl/src/x509/mod.rs44
-rw-r--r--openssl/src/x509/tests.rs2
2 files changed, 35 insertions, 11 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index 4cb4458a..0cc0eca7 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -94,7 +94,7 @@ impl X509StoreContext {
if ptr.is_null() {
None
} else {
- Some(X509Ref::new(ptr))
+ Some(X509Ref::from_ptr(ptr))
}
}
}
@@ -298,7 +298,7 @@ impl X509Generator {
unsafe {
let x509 = try_ssl_null!(ffi::X509_new());
- let x509 = X509::new(x509);
+ let x509 = X509::from_ptr(x509);
try_ssl!(ffi::X509_set_version(x509.as_ptr(), 2));
try_ssl!(ffi::ASN1_INTEGER_set(ffi::X509_get_serialNumber(x509.as_ptr()),
@@ -359,7 +359,7 @@ impl X509Generator {
let req = ffi::X509_to_X509_REQ(cert.as_ptr(), ptr::null_mut(), ptr::null());
try_ssl_null!(req);
- let exts = ::c_helpers::rust_X509_get_extensions(cert.as_ptr());
+ let exts = ::c_helpers::rust_0_8_X509_get_extensions(cert.as_ptr());
if exts != ptr::null_mut() {
try_ssl!(ffi::X509_REQ_add_extensions(req, exts));
}
@@ -377,8 +377,14 @@ pub struct X509Ref<'a>(*mut ffi::X509, PhantomData<&'a ()>);
impl<'a> X509Ref<'a> {
/// Creates a new `X509Ref` wrapping the provided handle.
- pub unsafe fn new(handle: *mut ffi::X509) -> X509Ref<'a> {
- X509Ref(handle, PhantomData)
+ pub unsafe fn from_ptr(x509: *mut ffi::X509) -> X509Ref<'a> {
+ X509Ref(x509, PhantomData)
+ }
+
+ ///
+ #[deprecated(note = "renamed to `X509::from_ptr`", since = "0.8.1")]
+ pub unsafe fn new(x509: *mut ffi::X509) -> X509Ref<'a> {
+ X509Ref::from_ptr(x509)
}
pub fn as_ptr(&self) -> *mut ffi::X509 {
@@ -402,7 +408,7 @@ impl<'a> X509Ref<'a> {
}
Some(GeneralNames {
- stack: stack as *const _,
+ stack: stack as *mut _,
m: PhantomData,
})
}
@@ -451,8 +457,14 @@ pub struct X509(X509Ref<'static>);
impl X509 {
/// Returns a new `X509`, taking ownership of the handle.
+ pub unsafe fn from_ptr(x509: *mut ffi::X509) -> X509 {
+ X509(X509Ref::from_ptr(x509))
+ }
+
+ ///
+ #[deprecated(note = "renamed to `X509::from_ptr`", since = "0.8.1")]
pub unsafe fn new(x509: *mut ffi::X509) -> X509 {
- X509(X509Ref::new(x509))
+ X509::from_ptr(x509)
}
/// Reads a certificate from PEM.
@@ -463,7 +475,7 @@ impl X509 {
ptr::null_mut(),
None,
ptr::null_mut()));
- Ok(X509::new(handle))
+ Ok(X509::from_ptr(handle))
}
}
}
@@ -481,7 +493,7 @@ impl Clone for X509 {
/// Requires the `x509_clone` feature.
fn clone(&self) -> X509 {
unsafe {
- ::c_helpers::rust_X509_clone(self.as_ptr());
+ ::c_helpers::rust_0_8_X509_clone(self.as_ptr());
X509::new(self.as_ptr())
}
}
@@ -723,12 +735,24 @@ make_validation_error!(X509_V_OK,
X509ApplicationVerification = X509_V_ERR_APPLICATION_VERIFICATION,
);
+// FIXME remove lifetime param for 0.9
/// A collection of OpenSSL `GENERAL_NAME`s.
pub struct GeneralNames<'a> {
- stack: *const ffi::stack_st_GENERAL_NAME,
+ stack: *mut ffi::stack_st_GENERAL_NAME,
m: PhantomData<&'a ()>,
}
+impl<'a> Drop for GeneralNames<'a> {
+ fn drop(&mut self) {
+ unsafe {
+ // This transmute is dubious but it's what openssl itself does...
+ let free: unsafe extern "C" fn(*mut ffi::GENERAL_NAME) = ffi::GENERAL_NAME_free;
+ let free: unsafe extern "C" fn(*mut c_void) = mem::transmute(free);
+ ffi::sk_pop_free(&mut (*self.stack).stack, Some(free));
+ }
+ }
+}
+
impl<'a> GeneralNames<'a> {
/// Returns the number of `GeneralName`s in this structure.
pub fn len(&self) -> usize {
diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs
index c09b31cd..43add896 100644
--- a/openssl/src/x509/tests.rs
+++ b/openssl/src/x509/tests.rs
@@ -86,7 +86,7 @@ fn test_cert_loading() {
let cert = X509::from_pem(cert).ok().expect("Failed to load PEM");
let fingerprint = cert.fingerprint(SHA1).unwrap();
- let hash_str = "E19427DAC79FBE758394945276A6E4F15F0BEBE6";
+ let hash_str = "59172d9313e84459bcff27f967e79e6e9217e584";
let hash_vec = hash_str.from_hex().unwrap();
assert_eq!(fingerprint, hash_vec);