From 28f375974a21342f3ae4c39f0a4df17570d89e69 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 31 Oct 2016 19:56:03 -0700 Subject: [PATCH] Convert Dh --- openssl/src/dh.rs | 31 ++----------------------------- openssl/src/ssl/mod.rs | 5 +++-- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/openssl/src/dh.rs b/openssl/src/dh.rs index 5c5ea05e..4ae145d6 100644 --- a/openssl/src/dh.rs +++ b/openssl/src/dh.rs @@ -3,25 +3,12 @@ use error::ErrorStack; use bio::MemBioSlice; use std::ptr; use std::mem; -use std::ops::Deref; use {cvt, cvt_p}; use bn::BigNum; -use opaque::Opaque; +use types::OpenSslType; -pub struct DhRef(Opaque); - -impl DhRef { - pub unsafe fn from_ptr<'a>(ptr: *mut ffi::DH) -> &'a DhRef { - &*(ptr as *mut _) - } - - pub fn as_ptr(&self) -> *mut ffi::DH { - self as *const _ as *mut _ - } -} - -pub struct Dh(*mut ffi::DH); +type_!(Dh, ffi::DH, ffi::DH_free); impl Dh { pub fn from_params(p: BigNum, g: BigNum, q: BigNum) -> Result { @@ -63,20 +50,6 @@ impl Dh { } } -impl Drop for Dh { - fn drop(&mut self) { - unsafe { ffi::DH_free(self.0) } - } -} - -impl Deref for Dh { - type Target = DhRef; - - fn deref(&self) -> &DhRef { - unsafe { DhRef::from_ptr(self.0) } - } -} - #[cfg(ossl110)] mod compat { pub use ffi::DH_set0_pqg; diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 5466f26e..695b2382 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -91,7 +91,7 @@ use std::marker::PhantomData; use ffi; use {init, cvt, cvt_p}; -use dh::DhRef; +use dh::Dh; use ec_key::EcKeyRef; use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError}; #[cfg(any(ossl102, ossl110))] @@ -99,6 +99,7 @@ use verify::X509VerifyParamRef; use pkey::PKeyRef; use error::ErrorStack; use opaque::Opaque; +use types::Ref; mod error; mod connector; @@ -513,7 +514,7 @@ impl SslContextBuilder { } } - pub fn set_tmp_dh(&mut self, dh: &DhRef) -> Result<(), ErrorStack> { + pub fn set_tmp_dh(&mut self, dh: &Ref) -> Result<(), ErrorStack> { unsafe { cvt(ffi::SSL_CTX_set_tmp_dh(self.as_ptr(), dh.as_ptr()) as c_int).map(|_| ()) } }