From 0c42bd97cb4a04e63285b8c7d2b1464d86a06dc2 Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Mon, 24 Jun 2024 18:27:20 +0000 Subject: [PATCH 1/4] test(bindings/s2n-tls): remove testing feature --- bindings/rust/integration/Cargo.toml | 6 +---- .../rust/integration/benches/handshake.rs | 26 ------------------- bindings/rust/s2n-tls/Cargo.toml | 2 -- bindings/rust/s2n-tls/src/lib.rs | 4 +-- 4 files changed, 3 insertions(+), 35 deletions(-) delete mode 100644 bindings/rust/integration/benches/handshake.rs diff --git a/bindings/rust/integration/Cargo.toml b/bindings/rust/integration/Cargo.toml index 854d7667f7f..6ba02e2ecb2 100644 --- a/bindings/rust/integration/Cargo.toml +++ b/bindings/rust/integration/Cargo.toml @@ -6,15 +6,11 @@ edition = "2021" publish = false [dependencies] -s2n-tls = { path = "../s2n-tls", features = ["testing"] } +s2n-tls = { path = "../s2n-tls"} s2n-tls-sys = { path = "../s2n-tls-sys" } criterion = { version = "0.3", features = ["html_reports"] } anyhow = "1" -[[bench]] -name = "handshake" -harness = false - [[bench]] name = "s2nc" harness = false diff --git a/bindings/rust/integration/benches/handshake.rs b/bindings/rust/integration/benches/handshake.rs deleted file mode 100644 index c8cd9370a86..00000000000 --- a/bindings/rust/integration/benches/handshake.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -use criterion::{criterion_group, criterion_main, Criterion}; -use s2n_tls::{ - security, - testing::{build_config, establish_connection}, -}; - -pub fn handshake(c: &mut Criterion) { - let mut group = c.benchmark_group("s2n-tls_client_server"); - - for policy in security::ALL_POLICIES { - let config = build_config(policy).unwrap(); - group.bench_function(format!("handshake_{:?}", policy), move |b| { - // This does include connection initialization overhead. - // TODO: create a separate benchmark that excludes this step. - b.iter(|| establish_connection(config.clone())); - }); - } - - group.finish(); -} - -criterion_group!(benches, handshake); -criterion_main!(benches); diff --git a/bindings/rust/s2n-tls/Cargo.toml b/bindings/rust/s2n-tls/Cargo.toml index 1e35195ccd5..c31579f7bea 100644 --- a/bindings/rust/s2n-tls/Cargo.toml +++ b/bindings/rust/s2n-tls/Cargo.toml @@ -15,10 +15,8 @@ unstable-ktls = ["s2n-tls-sys/unstable-ktls"] quic = ["s2n-tls-sys/quic"] fips = ["s2n-tls-sys/fips"] pq = ["s2n-tls-sys/pq"] -testing = ["bytes"] [dependencies] -bytes = { version = "1", optional = true } errno = { version = "0.3" } libc = "0.2" s2n-tls-sys = { version = "=0.2.7", path = "../s2n-tls-sys", features = ["internal"] } diff --git a/bindings/rust/s2n-tls/src/lib.rs b/bindings/rust/s2n-tls/src/lib.rs index 40bbb6dd1ff..88cb541a4b7 100644 --- a/bindings/rust/s2n-tls/src/lib.rs +++ b/bindings/rust/s2n-tls/src/lib.rs @@ -25,5 +25,5 @@ pub mod security; pub use s2n_tls_sys as ffi; -#[cfg(any(feature = "testing", test))] -pub mod testing; +#[cfg(test)] +mod testing; From 42c2736cbabb5a75104101c08768f0acc89022bf Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Mon, 24 Jun 2024 19:08:54 +0000 Subject: [PATCH 2/4] address ci failures - silence clippy warnings about unused types --- bindings/rust/s2n-tls/src/testing.rs | 6 +++--- bindings/rust/s2n-tls/src/testing/s2n_tls.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/rust/s2n-tls/src/testing.rs b/bindings/rust/s2n-tls/src/testing.rs index 3fe64c0d687..9e0fe8833bb 100644 --- a/bindings/rust/s2n-tls/src/testing.rs +++ b/bindings/rust/s2n-tls/src/testing.rs @@ -77,7 +77,7 @@ pub trait Context { pub enum Mode { Client, - Server, + _Server, } #[derive(Debug)] @@ -128,7 +128,7 @@ impl Pair { } } - pub fn poll_send(&mut self, sender: Mode, buf: &[u8]) -> Poll> { + pub fn _poll_send(&mut self, sender: Mode, buf: &[u8]) -> Poll> { let result = match sender { Mode::Client => self.client.0.poll_action(&mut self.client.1, |conn| { connection::Connection::poll_send(conn, buf) @@ -294,7 +294,7 @@ pub fn tls_pair(config: crate::config::Config) -> Pair { Pair::new(server, client) } -pub fn establish_connection(config: crate::config::Config) { +pub fn _establish_connection(config: crate::config::Config) { // create and configure a server connection let mut server = crate::connection::Connection::new_server(); server diff --git a/bindings/rust/s2n-tls/src/testing/s2n_tls.rs b/bindings/rust/s2n-tls/src/testing/s2n_tls.rs index 312464a24b1..a93bbce8932 100644 --- a/bindings/rust/s2n-tls/src/testing/s2n_tls.rs +++ b/bindings/rust/s2n-tls/src/testing/s2n_tls.rs @@ -33,7 +33,7 @@ impl Harness { &self.connection } - pub fn connection_mut(&mut self) -> &mut Connection { + pub fn _connection_mut(&mut self) -> &mut Connection { &mut self.connection } } From 2982348f5948bef48dc08cbf148c250d41176abc Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Mon, 24 Jun 2024 19:23:40 +0000 Subject: [PATCH 3/4] address ci failures - correct references to unused Server mode --- bindings/rust/s2n-tls/src/testing.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/rust/s2n-tls/src/testing.rs b/bindings/rust/s2n-tls/src/testing.rs index 9e0fe8833bb..8943e0d058c 100644 --- a/bindings/rust/s2n-tls/src/testing.rs +++ b/bindings/rust/s2n-tls/src/testing.rs @@ -133,7 +133,7 @@ impl Pair { Mode::Client => self.client.0.poll_action(&mut self.client.1, |conn| { connection::Connection::poll_send(conn, buf) }), - Mode::Server => self.server.0.poll_action(&mut self.server.1, |conn| { + Mode::_Server => self.server.0.poll_action(&mut self.server.1, |conn| { connection::Connection::poll_send(conn, buf) }), }; @@ -152,7 +152,7 @@ impl Pair { Mode::Client => self.client.0.poll_action(&mut self.client.1, |conn| { connection::Connection::poll_recv(conn, buf) }), - Mode::Server => self.server.0.poll_action(&mut self.server.1, |conn| { + Mode::_Server => self.server.0.poll_action(&mut self.server.1, |conn| { connection::Connection::poll_recv(conn, buf) }), }; From 0eebe6c20457829eaaa1623f009a0beabdbcca7c Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Fri, 28 Jun 2024 18:22:55 +0000 Subject: [PATCH 4/4] address pr feedback - fully remove unused items --- bindings/rust/s2n-tls/src/testing.rs | 42 -------------------- bindings/rust/s2n-tls/src/testing/s2n_tls.rs | 4 -- 2 files changed, 46 deletions(-) diff --git a/bindings/rust/s2n-tls/src/testing.rs b/bindings/rust/s2n-tls/src/testing.rs index 8943e0d058c..feb5afc9b6e 100644 --- a/bindings/rust/s2n-tls/src/testing.rs +++ b/bindings/rust/s2n-tls/src/testing.rs @@ -77,7 +77,6 @@ pub trait Context { pub enum Mode { Client, - _Server, } #[derive(Debug)] @@ -128,33 +127,11 @@ impl Pair { } } - pub fn _poll_send(&mut self, sender: Mode, buf: &[u8]) -> Poll> { - let result = match sender { - Mode::Client => self.client.0.poll_action(&mut self.client.1, |conn| { - connection::Connection::poll_send(conn, buf) - }), - Mode::_Server => self.server.0.poll_action(&mut self.server.1, |conn| { - connection::Connection::poll_send(conn, buf) - }), - }; - self.server.1.transfer(&mut self.client.1); - match result { - Poll::Ready(result) => { - result?; - Ok(()).into() - } - Poll::Pending => Poll::Pending, - } - } - pub fn poll_recv(&mut self, receiver: Mode, buf: &mut [u8]) -> Poll> { let result = match receiver { Mode::Client => self.client.0.poll_action(&mut self.client.1, |conn| { connection::Connection::poll_recv(conn, buf) }), - Mode::_Server => self.server.0.poll_action(&mut self.server.1, |conn| { - connection::Connection::poll_recv(conn, buf) - }), }; match result { Poll::Ready(result) => { @@ -294,25 +271,6 @@ pub fn tls_pair(config: crate::config::Config) -> Pair { Pair::new(server, client) } -pub fn _establish_connection(config: crate::config::Config) { - // create and configure a server connection - let mut server = crate::connection::Connection::new_server(); - server - .set_config(config.clone()) - .expect("Failed to bind config to server connection"); - let server = Harness::new(server); - - // create a client connection - let mut client = crate::connection::Connection::new_client(); - client - .set_config(config) - .expect("Unable to set client config"); - let client = Harness::new(client); - - let pair = Pair::new(server, client); - poll_tls_pair(pair); -} - pub fn poll_tls_pair(mut pair: Pair) -> Pair { loop { match pair.poll() { diff --git a/bindings/rust/s2n-tls/src/testing/s2n_tls.rs b/bindings/rust/s2n-tls/src/testing/s2n_tls.rs index a93bbce8932..7eac8ac2ef9 100644 --- a/bindings/rust/s2n-tls/src/testing/s2n_tls.rs +++ b/bindings/rust/s2n-tls/src/testing/s2n_tls.rs @@ -32,10 +32,6 @@ impl Harness { pub fn connection(&self) -> &Connection { &self.connection } - - pub fn _connection_mut(&mut self) -> &mut Connection { - &mut self.connection - } } impl super::Connection for Harness {