Convert Dh

This commit is contained in:
Steven Fackler 2016-10-31 19:56:03 -07:00
parent 849fca4a7b
commit 28f375974a
2 changed files with 5 additions and 31 deletions

View File

@ -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<Dh, ErrorStack> {
@ -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;

View File

@ -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<Dh>) -> Result<(), ErrorStack> {
unsafe { cvt(ffi::SSL_CTX_set_tmp_dh(self.as_ptr(), dh.as_ptr()) as c_int).map(|_| ()) }
}