Skip to content

Commit bbd4e1a

Browse files
committed
librustls: add rustls_client_config_builder_set_check_selected_alpn
1 parent 49ed121 commit bbd4e1a

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

librustls/src/client.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub(crate) struct ClientConfigBuilder {
5555
versions: Vec<&'static SupportedProtocolVersion>,
5656
verifier: Option<Arc<dyn ServerCertVerifier>>,
5757
alpn_protocols: Vec<Vec<u8>>,
58+
check_selected_alpn: bool,
5859
enable_sni: bool,
5960
cert_resolver: Option<Arc<dyn ResolvesClientCert>>,
6061
key_log: Option<Arc<dyn KeyLog>>,
@@ -71,6 +72,7 @@ impl Default for ClientConfigBuilder {
7172
versions: Vec::new(),
7273
verifier: None,
7374
alpn_protocols: Vec::new(),
75+
check_selected_alpn: true,
7476
// Note: we don't derive Default for this struct because we want to enable SNI
7577
// by default.
7678
enable_sni: true,
@@ -269,6 +271,22 @@ impl rustls_client_config_builder {
269271
}
270272
}
271273

274+
/// Enable or disable verifying the selected ALPN was offered.
275+
///
276+
/// The default is `true`.
277+
///
278+
/// <https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html#structfield.check_selected_alpn>
279+
#[no_mangle]
280+
pub extern "C" fn rustls_client_config_builder_set_check_selected_alpn(
281+
config: *mut rustls_client_config_builder,
282+
enable: bool,
283+
) {
284+
ffi_panic_boundary! {
285+
let config = try_mut_from_ptr!(config);
286+
config.check_selected_alpn = enable;
287+
}
288+
}
289+
272290
/// Enable or disable SNI.
273291
/// <https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html#structfield.enable_sni>
274292
#[no_mangle]

librustls/src/rustls.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,16 @@ rustls_result rustls_client_config_builder_set_alpn_protocols(struct rustls_clie
14481448
const struct rustls_slice_bytes *protocols,
14491449
size_t len);
14501450

1451+
/**
1452+
* Enable or disable verifying the selected ALPN was offered.
1453+
*
1454+
* The default is `true`.
1455+
*
1456+
* <https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html#structfield.check_selected_alpn>
1457+
*/
1458+
void rustls_client_config_builder_set_check_selected_alpn(struct rustls_client_config_builder *config,
1459+
bool enable);
1460+
14511461
/**
14521462
* Enable or disable SNI.
14531463
* <https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html#structfield.enable_sni>

website/static/api.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,14 @@
506506
"name": "rustls_client_config_builder_set_alpn_protocols",
507507
"text": "```c\nrustls_result rustls_client_config_builder_set_alpn_protocols(struct rustls_client_config_builder *builder,\n const struct rustls_slice_bytes *protocols,\n size_t len);\n```"
508508
},
509+
{
510+
"anchor": "rustls-client-config-builder-set-check-selected-alpn",
511+
"comment": "Enable or disable verifying the selected ALPN was offered.\n\n The default is `true`.\n\n <https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html#structfield.check_selected_alpn>",
512+
"feature": null,
513+
"deprecation": null,
514+
"name": "rustls_client_config_builder_set_check_selected_alpn",
515+
"text": "```c\nvoid rustls_client_config_builder_set_check_selected_alpn(struct rustls_client_config_builder *config,\n bool enable);\n```"
516+
},
509517
{
510518
"anchor": "rustls-client-config-builder-set-enable-sni",
511519
"comment": "Enable or disable SNI.\n <https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html#structfield.enable_sni>",

0 commit comments

Comments
 (0)