add get_curve (#226)

This commit is contained in:
Eric Rosenberg 2024-03-26 06:48:53 -07:00 committed by GitHub
parent 167f5aece1
commit 3d9a5e3244
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 0 deletions

View File

@ -696,6 +696,22 @@ impl SslCurve {
#[cfg(feature = "pq-experimental")]
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.
@ -2745,6 +2761,19 @@ impl SslRef {
.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`.
///
/// This corresponds to [`SSL_get_error`].

View File

@ -920,6 +920,15 @@ fn 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]
fn test_get_ciphers() {
let ctx_builder = SslContext::builder(SslMethod::tls()).unwrap();