More API cleanup
This commit is contained in:
parent
c4e7743c57
commit
5e6b8e68fd
|
|
@ -1,7 +1,7 @@
|
||||||
use libc::{c_int, c_ulong, c_void};
|
use libc::{c_int, c_ulong, c_void};
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::{fmt, ptr, mem};
|
use std::{fmt, ptr};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::{Add, Div, Mul, Neg, Rem, Shl, Shr, Sub, Deref, DerefMut};
|
use std::ops::{Add, Div, Mul, Neg, Rem, Shl, Shr, Sub, Deref, DerefMut};
|
||||||
|
|
||||||
|
|
@ -677,12 +677,6 @@ impl BigNum {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_raw(self) -> *mut ffi::BIGNUM {
|
|
||||||
let ptr = self.as_ptr();
|
|
||||||
mem::forget(self);
|
|
||||||
ptr
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for BigNum {
|
impl Drop for BigNum {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use ffi;
|
use ffi;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use std::mem;
|
||||||
use libc::{c_int, c_void, c_char, c_ulong};
|
use libc::{c_int, c_void, c_char, c_ulong};
|
||||||
|
|
||||||
use bn::{BigNum, BigNumRef};
|
use bn::{BigNum, BigNumRef};
|
||||||
|
|
@ -26,8 +27,10 @@ impl RSA {
|
||||||
pub fn from_public_components(n: BigNum, e: BigNum) -> Result<RSA, ErrorStack> {
|
pub fn from_public_components(n: BigNum, e: BigNum) -> Result<RSA, ErrorStack> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let rsa = try_ssl_null!(ffi::RSA_new());
|
let rsa = try_ssl_null!(ffi::RSA_new());
|
||||||
(*rsa).n = n.into_raw();
|
(*rsa).n = n.as_ptr();
|
||||||
(*rsa).e = e.into_raw();
|
(*rsa).e = e.as_ptr();
|
||||||
|
mem::forget(n);
|
||||||
|
mem::forget(e);
|
||||||
Ok(RSA(rsa))
|
Ok(RSA(rsa))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -43,14 +46,22 @@ impl RSA {
|
||||||
-> Result<RSA, ErrorStack> {
|
-> Result<RSA, ErrorStack> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let rsa = try_ssl_null!(ffi::RSA_new());
|
let rsa = try_ssl_null!(ffi::RSA_new());
|
||||||
(*rsa).n = n.into_raw();
|
(*rsa).n = n.as_ptr();
|
||||||
(*rsa).e = e.into_raw();
|
(*rsa).e = e.as_ptr();
|
||||||
(*rsa).d = d.into_raw();
|
(*rsa).d = d.as_ptr();
|
||||||
(*rsa).p = p.into_raw();
|
(*rsa).p = p.as_ptr();
|
||||||
(*rsa).q = q.into_raw();
|
(*rsa).q = q.as_ptr();
|
||||||
(*rsa).dmp1 = dp.into_raw();
|
(*rsa).dmp1 = dp.as_ptr();
|
||||||
(*rsa).dmq1 = dq.into_raw();
|
(*rsa).dmq1 = dq.as_ptr();
|
||||||
(*rsa).iqmp = qi.into_raw();
|
(*rsa).iqmp = qi.as_ptr();
|
||||||
|
mem::forget(n);
|
||||||
|
mem::forget(e);
|
||||||
|
mem::forget(d);
|
||||||
|
mem::forget(p);
|
||||||
|
mem::forget(q);
|
||||||
|
mem::forget(dp);
|
||||||
|
mem::forget(dq);
|
||||||
|
mem::forget(qi);
|
||||||
Ok(RSA(rsa))
|
Ok(RSA(rsa))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,11 @@ impl DH {
|
||||||
#[cfg(feature = "dh_from_params")]
|
#[cfg(feature = "dh_from_params")]
|
||||||
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 = unsafe {
|
let dh = unsafe {
|
||||||
try_ssl_null!(::c_helpers::rust_DH_new_from_params(p.into_raw(), g.into_raw(), q.into_raw()))
|
try_ssl_null!(::c_helpers::rust_DH_new_from_params(p.as_ptr(), g.as_ptr(), q.as_ptr()))
|
||||||
};
|
};
|
||||||
|
mem::forget(p);
|
||||||
|
mem::forget(g);
|
||||||
|
mem::forget(q);
|
||||||
Ok(DH(dh))
|
Ok(DH(dh))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +45,7 @@ impl DH {
|
||||||
Ok(DH(dh))
|
Ok(DH(dh))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn raw(&self) -> *mut ffi::DH {
|
pub unsafe fn as_ptr(&self) -> *mut ffi::DH {
|
||||||
let DH(n) = *self;
|
let DH(n) = *self;
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +54,7 @@ impl DH {
|
||||||
impl Drop for DH {
|
impl Drop for DH {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::DH_free(self.raw())
|
ffi::DH_free(self.as_ptr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -466,7 +466,7 @@ impl<'a> SslContextRef<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_tmp_dh(&mut self, dh: &DH) -> Result<(), ErrorStack> {
|
pub fn set_tmp_dh(&mut self, dh: &DH) -> Result<(), ErrorStack> {
|
||||||
wrap_ssl_result(unsafe { ffi::SSL_CTX_set_tmp_dh(self.as_ptr(), dh.raw()) as i32 })
|
wrap_ssl_result(unsafe { ffi::SSL_CTX_set_tmp_dh(self.as_ptr(), dh.as_ptr()) as i32 })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use the default locations of trusted certificates for verification.
|
/// Use the default locations of trusted certificates for verification.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue