Properly handle `Option<i32>` in `SslRef::set_curves`
This commit is contained in:
parent
cfc8f2db4f
commit
89dc444fb3
|
|
@ -1970,16 +1970,13 @@ impl SslContextBuilder {
|
||||||
// when the flags are used, the preferences are set just before connecting or accepting.
|
// when the flags are used, the preferences are set just before connecting or accepting.
|
||||||
#[cfg(not(feature = "kx-safe-default"))]
|
#[cfg(not(feature = "kx-safe-default"))]
|
||||||
pub fn set_curves(&mut self, curves: &[SslCurve]) -> Result<(), ErrorStack> {
|
pub fn set_curves(&mut self, curves: &[SslCurve]) -> Result<(), ErrorStack> {
|
||||||
let mut nid_curves = Vec::with_capacity(curves.len());
|
let curves: Vec<i32> = curves.iter().filter_map(|curve| curve.nid()).collect();
|
||||||
for curve in curves {
|
|
||||||
nid_curves.push(curve.nid())
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
cvt_0i(ffi::SSL_CTX_set1_curves(
|
cvt_0i(ffi::SSL_CTX_set1_curves(
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
nid_curves.as_ptr() as *const _,
|
curves.as_ptr() as *const _,
|
||||||
nid_curves.len(),
|
curves.len(),
|
||||||
))
|
))
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -945,6 +945,19 @@ fn get_curve_name() {
|
||||||
assert_eq!(SslCurve::X25519.name(), Some("X25519"));
|
assert_eq!(SslCurve::X25519.name(), Some("X25519"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "kx-safe-default"))]
|
||||||
|
#[test]
|
||||||
|
fn set_curves() {
|
||||||
|
let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
|
||||||
|
ctx.set_curves(&[
|
||||||
|
SslCurve::SECP224R1,
|
||||||
|
SslCurve::SECP256R1,
|
||||||
|
SslCurve::SECP384R1,
|
||||||
|
SslCurve::X25519,
|
||||||
|
])
|
||||||
|
.expect("Failed to set curves");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_ciphers() {
|
fn test_get_ciphers() {
|
||||||
let ctx_builder = SslContext::builder(SslMethod::tls()).unwrap();
|
let ctx_builder = SslContext::builder(SslMethod::tls()).unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue