diff options
author | Steven Fackler <sfackler@gmail.com> | 2016-10-30 13:38:09 -0700 |
---|---|---|
committer | Steven Fackler <sfackler@gmail.com> | 2016-10-30 13:38:09 -0700 |
commit | 677718f8da0024248fb6dfaa8f201ee6a6b3a219 (patch) | |
tree | cbd4b79f38653802ce60f75a88c344a21ca7ba38 /openssl/src/dh.rs | |
parent | 8c58ecc2fa63fb4234b9e48ef9ba0113628ce35f (diff) | |
download | rust-openssl-677718f8da0024248fb6dfaa8f201ee6a6b3a219.zip |
Configure ECDH parameters in connector
Diffstat (limited to 'openssl/src/dh.rs')
-rw-r--r-- | openssl/src/dh.rs | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/openssl/src/dh.rs b/openssl/src/dh.rs index 755e3e6b..b0c9737b 100644 --- a/openssl/src/dh.rs +++ b/openssl/src/dh.rs @@ -2,10 +2,24 @@ use ffi; use error::ErrorStack; use bio::MemBioSlice; use std::ptr; +use std::mem; +use std::ops::Deref; use {cvt, cvt_p}; use bn::BigNum; -use std::mem; +use opaque::Opaque; + +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); @@ -56,16 +70,22 @@ impl Dh { cvt_p(ffi::DH_get_2048_256()).map(Dh) } } - - pub fn as_ptr(&self) -> *mut ffi::DH { - self.0 - } } impl Drop for Dh { fn drop(&mut self) { unsafe { - ffi::DH_free(self.as_ptr()) + ffi::DH_free(self.0) + } + } +} + +impl Deref for Dh { + type Target = DhRef; + + fn deref(&self) -> &DhRef { + unsafe { + DhRef::from_ptr(self.0) } } } |