diff options
| author | Steven Fackler <[email protected]> | 2016-08-15 18:46:15 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-08-15 18:46:15 -0700 |
| commit | 0f428d190410263e4daa65b917c0e84707a9c0ef (patch) | |
| tree | 4d6d5b8b77c7ca5755a3636786b8a36584fba92a /openssl/src/x509/mod.rs | |
| parent | Merge branch 'release-v0.7.15-sys-v0.8.0' into release (diff) | |
| parent | Release openssl-sys v0.7.16, openssl v0.8.1 (diff) | |
| download | rust-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/mod.rs')
| -rw-r--r-- | openssl/src/x509/mod.rs | 44 |
1 files changed, 34 insertions, 10 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 { |