Camel case DH
This commit is contained in:
parent
8604668a18
commit
dafb46fc51
|
|
@ -7,12 +7,12 @@ use {cvt, cvt_p};
|
||||||
use bn::BigNum;
|
use bn::BigNum;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
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> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let dh = DH(try!(cvt_p(ffi::DH_new())));
|
let dh = Dh(try!(cvt_p(ffi::DH_new())));
|
||||||
try!(cvt(compat::DH_set0_pqg(dh.0,
|
try!(cvt(compat::DH_set0_pqg(dh.0,
|
||||||
p.as_ptr(),
|
p.as_ptr(),
|
||||||
q.as_ptr(),
|
q.as_ptr(),
|
||||||
|
|
@ -22,47 +22,47 @@ impl DH {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_pem(buf: &[u8]) -> Result<DH, ErrorStack> {
|
pub fn from_pem(buf: &[u8]) -> Result<Dh, ErrorStack> {
|
||||||
let mem_bio = try!(MemBioSlice::new(buf));
|
let mem_bio = try!(MemBioSlice::new(buf));
|
||||||
unsafe {
|
unsafe {
|
||||||
cvt_p(ffi::PEM_read_bio_DHparams(mem_bio.as_ptr(),
|
cvt_p(ffi::PEM_read_bio_DHparams(mem_bio.as_ptr(),
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
None,
|
None,
|
||||||
ptr::null_mut()))
|
ptr::null_mut()))
|
||||||
.map(DH)
|
.map(Dh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
|
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
|
||||||
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
||||||
pub fn get_1024_160() -> Result<DH, ErrorStack> {
|
pub fn get_1024_160() -> Result<Dh, ErrorStack> {
|
||||||
unsafe {
|
unsafe {
|
||||||
cvt_p(ffi::DH_get_1024_160()).map(DH)
|
cvt_p(ffi::DH_get_1024_160()).map(Dh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
|
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
|
||||||
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
||||||
pub fn get_2048_224() -> Result<DH, ErrorStack> {
|
pub fn get_2048_224() -> Result<Dh, ErrorStack> {
|
||||||
unsafe {
|
unsafe {
|
||||||
cvt_p(ffi::DH_get_2048_224()).map(DH)
|
cvt_p(ffi::DH_get_2048_224()).map(Dh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
|
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
|
||||||
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
||||||
pub fn get_2048_256() -> Result<DH, ErrorStack> {
|
pub fn get_2048_256() -> Result<Dh, ErrorStack> {
|
||||||
unsafe {
|
unsafe {
|
||||||
cvt_p(ffi::DH_get_2048_256()).map(DH)
|
cvt_p(ffi::DH_get_2048_256()).map(Dh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn as_ptr(&self) -> *mut ffi::DH {
|
pub fn as_ptr(&self) -> *mut ffi::DH {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for DH {
|
impl Drop for Dh {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::DH_free(self.as_ptr())
|
ffi::DH_free(self.as_ptr())
|
||||||
|
|
@ -94,7 +94,7 @@ mod compat {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::DH;
|
use dh::Dh;
|
||||||
use bn::BigNum;
|
use bn::BigNum;
|
||||||
use ssl::{SslMethod, SslContext};
|
use ssl::{SslMethod, SslContext};
|
||||||
|
|
||||||
|
|
@ -102,11 +102,11 @@ mod tests {
|
||||||
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
||||||
fn test_dh_rfc5114() {
|
fn test_dh_rfc5114() {
|
||||||
let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
|
let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
|
||||||
let dh1 = DH::get_1024_160().unwrap();
|
let dh1 = Dh::get_1024_160().unwrap();
|
||||||
ctx.set_tmp_dh(&dh1).unwrap();
|
ctx.set_tmp_dh(&dh1).unwrap();
|
||||||
let dh2 = DH::get_2048_224().unwrap();
|
let dh2 = Dh::get_2048_224().unwrap();
|
||||||
ctx.set_tmp_dh(&dh2).unwrap();
|
ctx.set_tmp_dh(&dh2).unwrap();
|
||||||
let dh3 = DH::get_2048_256().unwrap();
|
let dh3 = Dh::get_2048_256().unwrap();
|
||||||
ctx.set_tmp_dh(&dh3).unwrap();
|
ctx.set_tmp_dh(&dh3).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ mod tests {
|
||||||
let q = BigNum::from_hex_str("8CF83642A709A097B447997640129DA299B1A47D1EB3750BA308B0FE64F\
|
let q = BigNum::from_hex_str("8CF83642A709A097B447997640129DA299B1A47D1EB3750BA308B0FE64F\
|
||||||
5FBD3")
|
5FBD3")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let dh = DH::from_params(p, g, q).unwrap();
|
let dh = Dh::from_params(p, g, q).unwrap();
|
||||||
ctx.set_tmp_dh(&dh).unwrap();
|
ctx.set_tmp_dh(&dh).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,7 +144,7 @@ mod tests {
|
||||||
fn test_dh_from_pem() {
|
fn test_dh_from_pem() {
|
||||||
let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
|
let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
|
||||||
let params = include_bytes!("../test/dhparams.pem");
|
let params = include_bytes!("../test/dhparams.pem");
|
||||||
let dh = DH::from_pem(params).ok().expect("Failed to load PEM");
|
let dh = Dh::from_pem(params).ok().expect("Failed to load PEM");
|
||||||
ctx.set_tmp_dh(&dh).unwrap();
|
ctx.set_tmp_dh(&dh).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ use std::marker::PhantomData;
|
||||||
use ffi;
|
use ffi;
|
||||||
|
|
||||||
use {init, cvt, cvt_p};
|
use {init, cvt, cvt_p};
|
||||||
use dh::DH;
|
use dh::Dh;
|
||||||
use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError};
|
use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError};
|
||||||
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
|
||||||
use x509::verify::X509VerifyParamRef;
|
use x509::verify::X509VerifyParamRef;
|
||||||
|
|
@ -425,7 +425,7 @@ impl SslContextBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_tmp_dh(&mut self, dh: &DH) -> Result<(), ErrorStack> {
|
pub fn set_tmp_dh(&mut self, dh: &Dh) -> Result<(), ErrorStack> {
|
||||||
unsafe {
|
unsafe {
|
||||||
cvt(ffi::SSL_CTX_set_tmp_dh(self.as_ptr(), dh.as_ptr()) as c_int).map(|_| ())
|
cvt(ffi::SSL_CTX_set_tmp_dh(self.as_ptr(), dh.as_ptr()) as c_int).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue