diff options
| author | Steven Fackler <[email protected]> | 2016-10-30 14:16:17 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2016-10-30 14:16:17 -0700 |
| commit | 33cce627dac04fb3a59e3440eb997d7b99025924 (patch) | |
| tree | c4804097d96d4d3993190e3fd9ad440fca3f28f4 /openssl/src/dh.rs | |
| parent | Clean up generics a bit (diff) | |
| parent | Enable single ECDH use (diff) | |
| download | rust-openssl-33cce627dac04fb3a59e3440eb997d7b99025924.tar.xz rust-openssl-33cce627dac04fb3a59e3440eb997d7b99025924.zip | |
Merge pull request #503 from sfackler/ecdhe
ECDHE support
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) } } } |