DH cleanup
This commit is contained in:
parent
4d3c6868e7
commit
a0a6c03d74
|
|
@ -2,17 +2,15 @@ use ffi;
|
||||||
use error::ErrorStack;
|
use error::ErrorStack;
|
||||||
use bio::MemBioSlice;
|
use bio::MemBioSlice;
|
||||||
use bn::BigNum;
|
use bn::BigNum;
|
||||||
use std::mem;
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
pub struct DH(*mut ffi::DH);
|
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> {
|
||||||
let dh = try_ssl_null!(unsafe { ffi::DH_new_from_params(p.raw(), g.raw(), q.raw()) });
|
let dh = unsafe {
|
||||||
mem::forget(p);
|
try_ssl_null!(ffi::DH_new_from_params(p.into_raw(), g.into_raw(), q.into_raw()))
|
||||||
mem::forget(g);
|
};
|
||||||
mem::forget(q);
|
|
||||||
Ok(DH(dh))
|
Ok(DH(dh))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,21 +45,14 @@ impl DH {
|
||||||
let DH(n) = *self;
|
let DH(n) = *self;
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn raw_ptr(&self) -> *const *mut ffi::DH {
|
|
||||||
let DH(ref n) = *self;
|
|
||||||
n
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for DH {
|
impl Drop for DH {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
if !self.raw().is_null() {
|
|
||||||
ffi::DH_free(self.raw())
|
ffi::DH_free(self.raw())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue