Skip to content

Commit c6e390a

Browse files
authored
feat: Add new binding functions to ConnectConfiguration (#42)
1 parent 025f25c commit c6e390a

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

boring-sys/build/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ fn ensure_patches_applied(config: &Config) -> io::Result<()> {
487487
config,
488488
"boringssl-44b3df6f03d85c901767250329c571db405122d5.patch",
489489
)?;
490-
490+
491491
if config.features.underscore_wildcards {
492492
println!("cargo:warning=applying underscore wildcards patch to boringssl");
493493
apply_patch(config, "underscore-wildcards.patch")?;

boring/src/ssl/connector.rs

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use std::io::{Read, Write};
22
use std::ops::{Deref, DerefMut};
33

4+
use foreign_types::ForeignTypeRef;
5+
use openssl_macros::corresponds;
6+
47
use crate::dh::Dh;
58
use crate::error::ErrorStack;
69
use crate::ssl::{
710
HandshakeError, Ssl, SslContext, SslContextBuilder, SslContextRef, SslMethod, SslMode,
811
SslOptions, SslRef, SslStream, SslVerifyMode,
912
};
10-
use crate::version;
13+
use crate::{cvt, version};
1114
use std::net::IpAddr;
1215

1316
use super::MidHandshakeSslStream;
@@ -24,13 +27,13 @@ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
2427
";
2528

2629
enum ContextType {
27-
WithMethod(SslMethod)
30+
WithMethod(SslMethod),
2831
}
2932

3033
#[allow(clippy::inconsistent_digit_grouping)]
3134
fn ctx(ty: ContextType) -> Result<SslContextBuilder, ErrorStack> {
3235
let mut ctx = match ty {
33-
ContextType::WithMethod(method) => SslContextBuilder::new(method)
36+
ContextType::WithMethod(method) => SslContextBuilder::new(method),
3437
}?;
3538

3639
let mut opts = SslOptions::ALL
@@ -256,6 +259,63 @@ impl ConnectConfiguration {
256259
}
257260
}
258261

262+
impl ConnectConfiguration {
263+
/// Enables or disables ECH grease.
264+
///
265+
/// # Arguments
266+
///
267+
/// * `enable` - A boolean indicating whether to enable ECH grease.
268+
///
269+
/// # Safety
270+
///
271+
/// This function is unsafe because it calls an FFI function.
272+
#[corresponds(SSL_set_enable_ech_grease)]
273+
pub fn set_enable_ech_grease(&mut self, enable: bool) {
274+
unsafe { ffi::SSL_set_enable_ech_grease(self.as_ptr(), enable as _) }
275+
}
276+
277+
/// Adds application settings.
278+
///
279+
/// # Arguments
280+
///
281+
/// * `alps` - A slice of bytes representing the application settings.
282+
///
283+
/// # Returns
284+
///
285+
/// * `Result<(), ErrorStack>` - Returns `Ok(())` if the operation is successful, otherwise returns an `ErrorStack`.
286+
///
287+
/// # Safety
288+
///
289+
/// This function is unsafe because it calls an FFI function.
290+
#[corresponds(SSL_add_application_settings)]
291+
pub fn add_application_settings(&mut self, alps: &[u8]) -> Result<(), ErrorStack> {
292+
unsafe {
293+
cvt(ffi::SSL_add_application_settings(
294+
self.as_ptr(),
295+
alps.as_ptr(),
296+
alps.len(),
297+
std::ptr::null(),
298+
0,
299+
))
300+
.map(|_| ())
301+
}
302+
}
303+
304+
/// Sets the ALPS use new codepoint flag.
305+
///
306+
/// # Arguments
307+
///
308+
/// * `use_new` - A boolean indicating whether to use the new codepoint.
309+
///
310+
/// # Safety
311+
///
312+
/// This function is unsafe because it calls an FFI function.
313+
#[corresponds(SSL_set_alps_use_new_codepoint)]
314+
pub fn set_alps_use_new_codepoint(&mut self, use_new: bool) {
315+
unsafe { ffi::SSL_set_alps_use_new_codepoint(self.as_ptr(), use_new as _) }
316+
}
317+
}
318+
259319
impl Deref for ConnectConfiguration {
260320
type Target = SslRef;
261321

boring/src/ssl/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ impl Ssl3AlertLevel {
970970

971971
/// A builder for `SslContext`s.
972972
pub struct SslContextBuilder {
973-
ctx: SslContext
973+
ctx: SslContext,
974974
}
975975

976976
impl SslContextBuilder {

0 commit comments

Comments
 (0)