Convert Dh
This commit is contained in:
parent
849fca4a7b
commit
28f375974a
|
|
@ -3,25 +3,12 @@ use error::ErrorStack;
|
||||||
use bio::MemBioSlice;
|
use bio::MemBioSlice;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use {cvt, cvt_p};
|
use {cvt, cvt_p};
|
||||||
use bn::BigNum;
|
use bn::BigNum;
|
||||||
use opaque::Opaque;
|
use types::OpenSslType;
|
||||||
|
|
||||||
pub struct DhRef(Opaque);
|
type_!(Dh, ffi::DH, ffi::DH_free);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
impl Dh {
|
impl Dh {
|
||||||
pub fn from_params(p: BigNum, g: BigNum, q: BigNum) -> Result<Dh, ErrorStack> {
|
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)]
|
#[cfg(ossl110)]
|
||||||
mod compat {
|
mod compat {
|
||||||
pub use ffi::DH_set0_pqg;
|
pub use ffi::DH_set0_pqg;
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ use std::marker::PhantomData;
|
||||||
use ffi;
|
use ffi;
|
||||||
|
|
||||||
use {init, cvt, cvt_p};
|
use {init, cvt, cvt_p};
|
||||||
use dh::DhRef;
|
use dh::Dh;
|
||||||
use ec_key::EcKeyRef;
|
use ec_key::EcKeyRef;
|
||||||
use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError};
|
use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError};
|
||||||
#[cfg(any(ossl102, ossl110))]
|
#[cfg(any(ossl102, ossl110))]
|
||||||
|
|
@ -99,6 +99,7 @@ use verify::X509VerifyParamRef;
|
||||||
use pkey::PKeyRef;
|
use pkey::PKeyRef;
|
||||||
use error::ErrorStack;
|
use error::ErrorStack;
|
||||||
use opaque::Opaque;
|
use opaque::Opaque;
|
||||||
|
use types::Ref;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
mod connector;
|
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(|_| ()) }
|
unsafe { cvt(ffi::SSL_CTX_set_tmp_dh(self.as_ptr(), dh.as_ptr()) as c_int).map(|_| ()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue