add get_curve (#226)
This commit is contained in:
parent
167f5aece1
commit
3d9a5e3244
|
|
@ -696,6 +696,22 @@ impl SslCurve {
|
||||||
|
|
||||||
#[cfg(feature = "pq-experimental")]
|
#[cfg(feature = "pq-experimental")]
|
||||||
pub const P256_KYBER768_DRAFT00: SslCurve = SslCurve(ffi::NID_P256Kyber768Draft00);
|
pub const P256_KYBER768_DRAFT00: SslCurve = SslCurve(ffi::NID_P256Kyber768Draft00);
|
||||||
|
|
||||||
|
/// Returns the curve name
|
||||||
|
///
|
||||||
|
/// This corresponds to [`SSL_get_curve_name`]
|
||||||
|
///
|
||||||
|
/// [`SSL_get_curve_name`]: https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html#SSL_get_curve_name
|
||||||
|
pub fn name(&self) -> Option<&'static str> {
|
||||||
|
unsafe {
|
||||||
|
let ptr = ffi::SSL_get_curve_name(self.0 as u16);
|
||||||
|
if ptr.is_null() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
CStr::from_ptr(ptr).to_str().ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A compliance policy.
|
/// A compliance policy.
|
||||||
|
|
@ -2745,6 +2761,19 @@ impl SslRef {
|
||||||
.expect("invalid default server curves list");
|
.expect("invalid default server curves list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the [`SslCurve`] used for this `SslRef`.
|
||||||
|
///
|
||||||
|
/// This corresponds to [`SSL_get_curve_id`]
|
||||||
|
///
|
||||||
|
/// [`SSL_get_curve_id`]: https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html#SSL_get_curve_id
|
||||||
|
pub fn curve(&self) -> Option<SslCurve> {
|
||||||
|
let curve_id = unsafe { ffi::SSL_get_curve_id(self.as_ptr()) };
|
||||||
|
if curve_id == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(SslCurve(curve_id.into()))
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns an `ErrorCode` value for the most recent operation on this `SslRef`.
|
/// Returns an `ErrorCode` value for the most recent operation on this `SslRef`.
|
||||||
///
|
///
|
||||||
/// This corresponds to [`SSL_get_error`].
|
/// This corresponds to [`SSL_get_error`].
|
||||||
|
|
|
||||||
|
|
@ -920,6 +920,15 @@ fn server_set_default_curves_list() {
|
||||||
ssl.server_set_default_curves_list();
|
ssl.server_set_default_curves_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_curve() {
|
||||||
|
let server = Server::builder().build();
|
||||||
|
let client = server.client_with_root_ca();
|
||||||
|
let client_stream = client.connect();
|
||||||
|
let curve = client_stream.ssl().curve().expect("curve");
|
||||||
|
assert!(curve.name().is_some());
|
||||||
|
}
|
||||||
|
|
||||||
#[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