Skip to content

Commit 66ae999

Browse files
committed
Add set_curves_list() to C/Rust APIs
1 parent ab466d1 commit 66ae999

5 files changed

Lines changed: 23 additions & 11 deletions

File tree

quiche/include/quiche.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ int quiche_config_load_verify_locations_from_file(quiche_config *config,
168168
int quiche_config_load_verify_locations_from_directory(quiche_config *config,
169169
const char *path);
170170

171+
// Configures the TLS curve preference list (colon-separated, e.g. "X25519MLKEM768:X25519:P-256:P-384").
172+
int quiche_config_set_curves_list(quiche_config *config, const char *curves);
173+
171174
// Configures whether to verify the peer's certificate.
172175
void quiche_config_verify_peer(quiche_config *config, bool v);
173176

quiche/src/ffi.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,19 @@ pub extern "C" fn quiche_config_load_verify_locations_from_directory(
200200
}
201201
}
202202

203+
#[no_mangle]
204+
pub extern "C" fn quiche_config_set_curves_list(
205+
config: &mut Config, curves: *const c_char,
206+
) -> c_int {
207+
let curves = unsafe { ffi::CStr::from_ptr(curves).to_str().unwrap() };
208+
209+
match config.set_curves_list(curves) {
210+
Ok(_) => 0,
211+
212+
Err(e) => e.to_c() as c_int,
213+
}
214+
}
215+
203216
#[no_mangle]
204217
pub extern "C" fn quiche_config_verify_peer(config: &mut Config, v: bool) {
205218
config.verify_peer(v);

quiche/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,13 +760,13 @@ impl Config {
760760
self.tls_ctx.load_verify_locations_from_directory(dir)
761761
}
762762

763-
/// Configures the TLS curve preference list (colon-separated, e.g.
764-
/// `"X25519:P-256:P-384"`). Corresponds to `SSL_CTX_set1_curves_list`.
763+
/// Configures the TLS curve preference list.
765764
///
766-
/// Only used from [`test_utils`] helpers; gated on the same cfg so the
767-
/// underlying FFI shim isn't pulled into production builds.
768-
#[cfg(any(test, feature = "internal"))]
769-
pub(crate) fn set_curves_list(&mut self, curves: &str) -> Result<()> {
765+
/// `curves` is a colon-separated list of curve (a.k.a. group) names, in
766+
/// order of preference, e.g. `"X25519MLKEM768:X25519:P-256:P-384"`.
767+
/// Corresponds to `SSL_CTX_set1_curves_list` (a.k.a.
768+
/// `SSL_CTX_set1_groups_list`).
769+
pub fn set_curves_list(&mut self, curves: &str) -> Result<()> {
770770
self.tls_ctx.set_curves_list(curves)
771771
}
772772

quiche/src/tls/boringssl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ extern "C" {
312312

313313
// BoringSSL exports `SSL_CTX_set1_groups_list` as a real symbol; on
314314
// OpenSSL it is a header macro. See `openssl_quictls.rs` for the
315-
// OpenSSL shim. Only used from test-utils helpers.
316-
#[cfg(any(test, feature = "internal"))]
315+
// OpenSSL shim.
317316
pub(super) fn SSL_CTX_set1_groups_list(
318317
ctx: *mut SSL_CTX, groups: *const c_char,
319318
) -> c_int;

quiche/src/tls/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,6 @@ impl Context {
328328
})
329329
}
330330

331-
// Only used from the test-utils `config_no_pq` helpers; see the
332-
// matching cfg gate on `Config::set_curves_list` in `lib.rs`.
333-
#[cfg(any(test, feature = "internal"))]
334331
pub fn set_curves_list(&mut self, curves: &str) -> Result<()> {
335332
// Note: BoringSSL exports `SSL_CTX_set1_groups_list` as a real
336333
// function; OpenSSL (and openssl-quictls) defines it as a macro

0 commit comments

Comments
 (0)