Update EcKey
This commit is contained in:
parent
fe5fb75d45
commit
d6579ab058
|
|
@ -1,49 +1,15 @@
|
||||||
use ffi;
|
use ffi;
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use cvt_p;
|
use cvt_p;
|
||||||
use error::ErrorStack;
|
use error::ErrorStack;
|
||||||
use nid::Nid;
|
use nid::Nid;
|
||||||
use opaque::Opaque;
|
|
||||||
|
|
||||||
pub struct EcKeyRef(Opaque);
|
type_!(EcKey, ffi::EC_KEY, ffi::EC_KEY_free);
|
||||||
|
|
||||||
impl EcKeyRef {
|
|
||||||
pub unsafe fn from_ptr<'a>(ptr: *mut ffi::EC_KEY) -> &'a EcKeyRef {
|
|
||||||
&*(ptr as *mut _)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_ptr(&self) -> *mut ffi::EC_KEY {
|
|
||||||
self as *const _ as *mut _
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EcKey(*mut ffi::EC_KEY);
|
|
||||||
|
|
||||||
impl Drop for EcKey {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
ffi::EC_KEY_free(self.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EcKey {
|
impl EcKey {
|
||||||
pub fn new_by_curve_name(nid: Nid) -> Result<EcKey, ErrorStack> {
|
pub fn new_by_curve_name(nid: Nid) -> Result<EcKey, ErrorStack> {
|
||||||
unsafe { cvt_p(ffi::EC_KEY_new_by_curve_name(nid.as_raw())).map(EcKey) }
|
unsafe { cvt_p(ffi::EC_KEY_new_by_curve_name(nid.as_raw())).map(EcKey) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn from_ptr(ptr: *mut ffi::EC_KEY) -> EcKey {
|
|
||||||
EcKey(ptr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for EcKey {
|
|
||||||
type Target = EcKeyRef;
|
|
||||||
|
|
||||||
fn deref(&self) -> &EcKeyRef {
|
|
||||||
unsafe { EcKeyRef::from_ptr(self.0) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ use ffi;
|
||||||
|
|
||||||
use {init, cvt, cvt_p};
|
use {init, cvt, cvt_p};
|
||||||
use dh::Dh;
|
use dh::Dh;
|
||||||
use ec_key::EcKeyRef;
|
use ec_key::EcKey;
|
||||||
use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError};
|
use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError};
|
||||||
#[cfg(any(ossl102, ossl110))]
|
#[cfg(any(ossl102, ossl110))]
|
||||||
use verify::X509VerifyParamRef;
|
use verify::X509VerifyParamRef;
|
||||||
|
|
@ -518,7 +518,7 @@ impl SslContextBuilder {
|
||||||
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(|_| ()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_tmp_ecdh(&mut self, key: &EcKeyRef) -> Result<(), ErrorStack> {
|
pub fn set_tmp_ecdh(&mut self, key: &Ref<EcKey>) -> Result<(), ErrorStack> {
|
||||||
unsafe { cvt(ffi::SSL_CTX_set_tmp_ecdh(self.as_ptr(), key.as_ptr()) as c_int).map(|_| ()) }
|
unsafe { cvt(ffi::SSL_CTX_set_tmp_ecdh(self.as_ptr(), key.as_ptr()) as c_int).map(|_| ()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue