rust/bssl-tls: implement Send for TlsContextBuilder TlsContextBuilder holds a NonNull<bssl_sys::SSL_CTX> without a Send implementation, causing async functions that construct a builder before an await point to fail Send bounds on fallible paths. Since the builder exclusively owns its SSL_CTX and all registered callbacks are Send + Sync, implement Send for TlsContextBuilder. Change-Id: I77d3051be0f0ce175a598ae94cdaac10109dfe4d Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/106108 Reviewed-by: Xiangfei Ding <xfding@google.com> Commit-Queue: Alice Ryhl <aliceryhl@google.com>
diff --git a/rust/bssl-tls/src/context.rs b/rust/bssl-tls/src/context.rs index 5797286..3ad0851 100644 --- a/rust/bssl-tls/src/context.rs +++ b/rust/bssl-tls/src/context.rs
@@ -121,6 +121,10 @@ _p: PhantomData<fn() -> Mode>, } +// Safety: `TlsContextBuilder` has exclusive ownership of its `SSL_CTX`, and all callbacks +// stored in its `RustContextMethods` `ex_data` are `Send + Sync`. +unsafe impl<M> Send for TlsContextBuilder<M> {} + impl<M> TlsContextBuilder<M> { fn ptr(&self) -> *mut bssl_sys::SSL_CTX { self.ptr.as_ptr()
diff --git a/rust/bssl-tls/src/tests.rs b/rust/bssl-tls/src/tests.rs index d87a43e..bcd461c 100644 --- a/rust/bssl-tls/src/tests.rs +++ b/rust/bssl-tls/src/tests.rs
@@ -581,3 +581,21 @@ } Ok(()) } + +#[test] +fn context_builder_send_across_async_fn() { + fn assert_send<F: std::future::Future + Send>(fut: F) -> F { + fut + } + + let fut = assert_send(async { + let mut builder = TlsContextBuilder::new_tls(); + builder.set_alpn_protocols([crate::alpn::H2])?; + let ctx = builder.build(); + futures::future::ready(()).await; + drop(ctx); + Ok::<_, Error>(()) + }); + + futures::executor::block_on(fut).expect("ALPN configuration succeeds"); +}