From 50682e021280af94e1dbd7eb5b5b65b8ec2169a1 Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Wed, 4 Oct 2023 03:25:55 +0000 Subject: [PATCH 1/4] refactor(bench): remove non-generic connection This commit shifts the TlsConnection trait to make it more generic. The purpose of this is to allow more general usage of the TlsConnection objects. In the future, "purpose-specific" logic will be implemented on the Config type rather than the connection type. --- bindings/rust/bench/benches/handshake.rs | 15 +- bindings/rust/bench/benches/resumption.rs | 28 +-- bindings/rust/bench/benches/throughput.rs | 15 +- bindings/rust/bench/src/harness.rs | 211 +++++++++++----------- bindings/rust/bench/src/openssl.rs | 44 +++-- bindings/rust/bench/src/rustls.rs | 52 +++--- bindings/rust/bench/src/s2n_tls.rs | 102 ++++++----- 7 files changed, 245 insertions(+), 222 deletions(-) diff --git a/bindings/rust/bench/benches/handshake.rs b/bindings/rust/bench/benches/handshake.rs index b639cef5a2b..6fc7c5b2a20 100644 --- a/bindings/rust/bench/benches/handshake.rs +++ b/bindings/rust/bench/benches/handshake.rs @@ -6,8 +6,8 @@ use bench::OpenSslConnection; #[cfg(feature = "rustls")] use bench::RustlsConnection; use bench::{ - CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, Mode, S2NConnection, - SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY, + harness::TlsBenchConfig, CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, + Mode, S2NConnection, SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY, }; use criterion::{ criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion, @@ -16,16 +16,19 @@ use pprof::criterion::{Output, PProfProfiler}; use std::error::Error; use strum::IntoEnumIterator; -fn bench_handshake_for_library( +fn bench_handshake_for_library( bench_group: &mut BenchmarkGroup, handshake_type: HandshakeType, kx_group: KXGroup, sig_type: SigType, -) { +) where + T: TlsConnection, + T::Config: TlsBenchConfig, +{ // make configs before benching to reuse let crypto_config = CryptoConfig::new(CipherSuite::default(), kx_group, sig_type); - let client_config = T::make_config(Mode::Client, crypto_config, handshake_type); - let server_config = T::make_config(Mode::Server, crypto_config, handshake_type); + let client_config = T::Config::make_config(Mode::Client, crypto_config, handshake_type); + let server_config = T::Config::make_config(Mode::Server, crypto_config, handshake_type); // generate all harnesses (TlsConnPair structs) beforehand so that benchmarks // only include negotiation and not config/connection initialization diff --git a/bindings/rust/bench/benches/resumption.rs b/bindings/rust/bench/benches/resumption.rs index f3feb022038..7b0872660ff 100644 --- a/bindings/rust/bench/benches/resumption.rs +++ b/bindings/rust/bench/benches/resumption.rs @@ -1,25 +1,25 @@ use bench::{ - CipherSuite, CryptoConfig, HandshakeType, KXGroup, S2NConnection, SigType, TlsConnPair, - TlsConnection, + harness::TlsBenchConfig, CipherSuite, CryptoConfig, HandshakeType, KXGroup, S2NConnection, + SigType, TlsConnPair, TlsConnection, }; use criterion::{ criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion, }; -fn bench_handshake_pair( - bench_group: &mut BenchmarkGroup, - sig_type: SigType, -) { +fn bench_handshake_pair(bench_group: &mut BenchmarkGroup, sig_type: SigType) +where + T: TlsConnection, + T::Config: TlsBenchConfig, +{ // generate all harnesses (TlsConnPair structs) beforehand so that benchmarks // only include negotiation and not config/connection initialization for handshake in [HandshakeType::Resumption, HandshakeType::ServerAuth] { bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| { b.iter_batched_ref( || { - TlsConnPair::::new( + TlsConnPair::::new_bench_pair( CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type), handshake, - Default::default(), ) }, |conn_pair_res| { @@ -33,18 +33,18 @@ fn bench_handshake_pair( } } -fn bench_handshake_server_1rtt( - bench_group: &mut BenchmarkGroup, - sig_type: SigType, -) { +fn bench_handshake_server_1rtt(bench_group: &mut BenchmarkGroup, sig_type: SigType) +where + T: TlsConnection, + T::Config: TlsBenchConfig, +{ for handshake in [HandshakeType::Resumption, HandshakeType::ServerAuth] { bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| { b.iter_batched_ref( || { - let pair = TlsConnPair::::new( + let pair = TlsConnPair::::new_bench_pair( CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type), handshake, - Default::default(), ) .unwrap(); let (mut c, s) = pair.split(); diff --git a/bindings/rust/bench/benches/throughput.rs b/bindings/rust/bench/benches/throughput.rs index 21764def158..7ad675202f4 100644 --- a/bindings/rust/bench/benches/throughput.rs +++ b/bindings/rust/bench/benches/throughput.rs @@ -6,8 +6,8 @@ use bench::OpenSslConnection; #[cfg(feature = "rustls")] use bench::RustlsConnection; use bench::{ - CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, Mode, S2NConnection, - SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY, + harness::TlsBenchConfig, CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, + Mode, S2NConnection, SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY, }; use criterion::{ criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion, @@ -17,14 +17,17 @@ use pprof::criterion::{Output, PProfProfiler}; use std::error::Error; use strum::IntoEnumIterator; -fn bench_throughput_for_library( +fn bench_throughput_for_library( bench_group: &mut BenchmarkGroup, shared_buf: &mut [u8], cipher_suite: CipherSuite, -) { +) where + T: TlsConnection, + T::Config: TlsBenchConfig, +{ let crypto_config = CryptoConfig::new(cipher_suite, KXGroup::default(), SigType::default()); - let client_config = T::make_config(Mode::Client, crypto_config, HandshakeType::default()); - let server_config = T::make_config(Mode::Server, crypto_config, HandshakeType::default()); + let client_config = T::Config::make_config(Mode::Client, crypto_config, HandshakeType::default()); + let server_config = T::Config::make_config(Mode::Server, crypto_config, HandshakeType::default()); bench_group.bench_function(T::name(), |b| { b.iter_batched_ref( diff --git a/bindings/rust/bench/src/harness.rs b/bindings/rust/bench/src/harness.rs index 7cc73a801bf..acacb3d9578 100644 --- a/bindings/rust/bench/src/harness.rs +++ b/bindings/rust/bench/src/harness.rs @@ -140,6 +140,20 @@ impl CryptoConfig { } } +/// The TlsBenchConfig trait allows a us to map benchmarking parameters to a +/// a configuration object +pub trait TlsBenchConfig: Sized { + /// Make a config with given parameters + fn make_config( + mode: Mode, + crypto_config: CryptoConfig, + handshake_type: HandshakeType, + ) -> Result>; +} + +/// The TlsConnection object can be created from a corresponding config type. +/// Any "purpose specific" config creation should be implemented on the config +/// rather than the connection to separate configuration vs implementation. pub trait TlsConnection: Sized { /// Library-specific config struct type Config; @@ -147,42 +161,12 @@ pub trait TlsConnection: Sized { /// Name of the connection type fn name() -> String; - /// Default connection (client or server) - fn default(mode: Mode) -> Result> { - Self::new( - mode, - CryptoConfig::default(), - HandshakeType::default(), - ConnectedBuffer::default(), - ) - } - - /// Make a config with given parameters - fn make_config( - mode: Mode, - crypto_config: CryptoConfig, - handshake_type: HandshakeType, - ) -> Result>; - /// Make connection from existing config and buffer fn new_from_config( config: &Self::Config, connected_buffer: ConnectedBuffer, ) -> Result>; - /// Initialize buffers, configs, and connections (pre-handshake) - fn new( - mode: Mode, - crypto_config: CryptoConfig, - handshake_type: HandshakeType, - buffer: ConnectedBuffer, - ) -> Result> { - Self::new_from_config( - &Self::make_config(mode, crypto_config, handshake_type)?, - buffer, - ) - } - /// Run one handshake step: receive msgs from other connection, process, and send new msgs fn handshake(&mut self) -> Result<(), Box>; @@ -217,49 +201,49 @@ pub struct TlsConnPair { server: S, } -impl Default for TlsConnPair { - fn default() -> Self { - Self::new( - CryptoConfig::default(), - HandshakeType::default(), - ConnectedBuffer::default(), - ) - .unwrap() - } -} - impl TlsConnPair { - /// Wrap two TlsConnections into a TlsConnPair - pub fn wrap(client: C, server: S) -> Self { - assert!( - client.connected_buffer() == &server.connected_buffer().clone_inverse(), - "connected buffers don't match" - ); + pub fn new(client_config: &C::Config, server_config: &S::Config) -> TlsConnPair { + let connected_buffer = ConnectedBuffer::default(); + let client = C::new_from_config(&client_config, connected_buffer.clone_inverse()).unwrap(); + let server = S::new_from_config(&server_config, connected_buffer).unwrap(); Self { client, server } } +} - /// Take back ownership of individual connections in the TlsConnPair - pub fn split(self) -> (C, S) { - (self.client, self.server) +impl Default for TlsConnPair +where + C: TlsConnection, + S: TlsConnection, + C::Config: TlsBenchConfig, + S::Config: TlsBenchConfig, +{ + fn default() -> Self { + Self::new_bench_pair(CryptoConfig::default(), HandshakeType::default()).unwrap() } +} +impl TlsConnPair +where + C: TlsConnection, + S: TlsConnection, + C::Config: TlsBenchConfig, + S::Config: TlsBenchConfig, +{ /// Initialize buffers, configs, and connections (pre-handshake) - pub fn new( + pub fn new_bench_pair( crypto_config: CryptoConfig, handshake_type: HandshakeType, - connected_buffer: ConnectedBuffer, ) -> Result> { // do an initial handshake to generate the session ticket if handshake_type == HandshakeType::Resumption { - let server_config = S::make_config(Mode::Server, crypto_config, handshake_type)?; - let client_config = C::make_config(Mode::Client, crypto_config, handshake_type)?; + let server_config = + S::Config::make_config(Mode::Server, crypto_config, handshake_type)?; + let client_config = + C::Config::make_config(Mode::Client, crypto_config, handshake_type)?; // handshake the client and server connections. This will result in // session ticket getting stored in client_config - let buffer = ConnectedBuffer::default(); - let client = C::new_from_config(&client_config, buffer.clone_inverse())?; - let server = S::new_from_config(&server_config, buffer)?; - let mut pair = TlsConnPair { client, server }; + let mut pair = TlsConnPair::::new(&client_config, &server_config); pair.handshake()?; // NewSessionTicket messages are part of the application data and sent // after the handshake is complete, so we must trigger an additional @@ -267,30 +251,38 @@ impl TlsConnPair { // gets received and stored in the config pair.round_trip_transfer(&mut [0]).unwrap(); - // new_from_config will check if a session ticket is available, - // and set it on the connection. This results in the session ticket - // in client_config (from the previous handshake) getting set on - // the client connection. - let client = C::new_from_config(&client_config, connected_buffer.clone_inverse())?; - let server = S::new_from_config(&server_config, connected_buffer)?; - - return Ok(Self { client, server }); + // new_from_config is called interally by the TlsConnPair::new + // method and will check if a session ticket is available and set it + // on the connection. This results in the session ticket in + // client_config (from the previous handshake) getting set on the + // client connection. + return Ok(TlsConnPair::::new(&client_config, &server_config)); } - Ok(Self { - client: C::new( - Mode::Client, - crypto_config, - handshake_type, - connected_buffer.clone_inverse(), - )?, - server: S::new( - Mode::Server, - crypto_config, - handshake_type, - connected_buffer, - )?, - }) + Ok(TlsConnPair::::new( + &C::Config::make_config(Mode::Client, crypto_config, handshake_type).unwrap(), + &S::Config::make_config(Mode::Server, crypto_config, handshake_type).unwrap(), + )) + } +} + +impl TlsConnPair +where + C: TlsConnection, + S: TlsConnection, +{ + /// Wrap two TlsConnections into a TlsConnPair + pub fn wrap(client: C, server: S) -> Self { + assert!( + client.connected_buffer() == &server.connected_buffer().clone_inverse(), + "connected buffers don't match" + ); + Self { client, server } + } + + /// Take back ownership of individual connections in the TlsConnPair + pub fn split(self) -> (C, S) { + (self.client, self.server) } /// Run handshake on connections @@ -454,24 +446,33 @@ mod tests { test_type::(); } - fn test_type() { + fn test_type() + where + S: TlsConnection, + C: TlsConnection, + C::Config: TlsBenchConfig, + S::Config: TlsBenchConfig, + { println!("{} client --- {} server", C::name(), S::name()); handshake_configs::(); transfer::(); } - fn handshake_configs() { + fn handshake_configs() + where + S: TlsConnection, + C: TlsConnection, + C::Config: TlsBenchConfig, + S::Config: TlsBenchConfig, + { for handshake_type in HandshakeType::iter() { for cipher_suite in CipherSuite::iter() { for kx_group in KXGroup::iter() { for sig_type in SigType::iter() { let crypto_config = CryptoConfig::new(cipher_suite, kx_group, sig_type); - let mut conn_pair = TlsConnPair::::new( - crypto_config, - handshake_type, - ConnectedBuffer::default(), - ) - .unwrap(); + let mut conn_pair = + TlsConnPair::::new_bench_pair(crypto_config, handshake_type) + .unwrap(); assert!(!conn_pair.handshake_completed()); conn_pair.handshake().unwrap(); @@ -485,14 +486,17 @@ mod tests { } } - fn session_resumption() { + fn session_resumption() + where + S: TlsConnection, + C: TlsConnection, + C::Config: TlsBenchConfig, + S::Config: TlsBenchConfig, + { println!("testing with client:{} server:{}", C::name(), S::name()); - let mut conn_pair = TlsConnPair::::new( - CryptoConfig::default(), - HandshakeType::Resumption, - ConnectedBuffer::default(), - ) - .unwrap(); + let mut conn_pair = + TlsConnPair::::new_bench_pair(CryptoConfig::default(), HandshakeType::Resumption) + .unwrap(); conn_pair.handshake().unwrap(); let (_, server) = conn_pair.split(); assert!(server.resumed_connection()); @@ -518,18 +522,21 @@ mod tests { session_resumption::(); } - fn transfer() { + fn transfer() + where + S: TlsConnection, + C: TlsConnection, + C::Config: TlsBenchConfig, + S::Config: TlsBenchConfig, + { // use a large buffer to test across TLS record boundaries let mut buf = [0x56u8; 1000000]; for cipher_suite in CipherSuite::iter() { let crypto_config = CryptoConfig::new(cipher_suite, KXGroup::default(), SigType::default()); - let mut conn_pair = TlsConnPair::::new( - crypto_config, - HandshakeType::default(), - ConnectedBuffer::default(), - ) - .unwrap(); + let mut conn_pair = + TlsConnPair::::new_bench_pair(crypto_config, HandshakeType::default()) + .unwrap(); conn_pair.handshake().unwrap(); conn_pair.round_trip_transfer(&mut buf).unwrap(); } diff --git a/bindings/rust/bench/src/openssl.rs b/bindings/rust/bench/src/openssl.rs index 85bac41e295..012f2aac0b1 100644 --- a/bindings/rust/bench/src/openssl.rs +++ b/bindings/rust/bench/src/openssl.rs @@ -4,7 +4,7 @@ use crate::{ get_cert_path, harness::{ - CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, Mode, TlsConnection, + CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, Mode, TlsConnection, TlsBenchConfig, }, PemType::*, }; @@ -42,29 +42,13 @@ pub struct OpenSslConfig { session_ticket_storage: SessionTicketStorage, } -impl TlsConnection for OpenSslConnection { - type Config = OpenSslConfig; - - fn name() -> String { - let version_num = openssl::version::number() as u64; - let patch: u8 = (version_num >> 4) as u8; - let fix = (version_num >> 12) as u8; - let minor = (version_num >> 20) as u8; - let major = (version_num >> 28) as u8; - format!( - "openssl{}.{}.{}{}", - major, - minor, - fix, - (b'a' + patch - 1) as char - ) - } +impl TlsBenchConfig for OpenSslConfig { fn make_config( mode: Mode, crypto_config: CryptoConfig, handshake_type: HandshakeType, - ) -> Result> { + ) -> Result> { let cipher_suite = match crypto_config.cipher_suite { CipherSuite::AES_128_GCM_SHA256 => "TLS_AES_128_GCM_SHA256", CipherSuite::AES_256_GCM_SHA384 => "TLS_AES_256_GCM_SHA384", @@ -139,11 +123,31 @@ impl TlsConnection for OpenSslConnection { } } } - Ok(Self::Config { + Ok(Self { config: builder.build(), session_ticket_storage, }) } +} + +impl TlsConnection for OpenSslConnection { + type Config = OpenSslConfig; + + fn name() -> String { + let version_num = openssl::version::number() as u64; + let patch: u8 = (version_num >> 4) as u8; + let fix = (version_num >> 12) as u8; + let minor = (version_num >> 20) as u8; + let major = (version_num >> 28) as u8; + format!( + "openssl{}.{}.{}{}", + major, + minor, + fix, + (b'a' + patch - 1) as char + ) + } + fn new_from_config( config: &Self::Config, diff --git a/bindings/rust/bench/src/rustls.rs b/bindings/rust/bench/src/rustls.rs index 03d8fbdad10..50de9be75bc 100644 --- a/bindings/rust/bench/src/rustls.rs +++ b/bindings/rust/bench/src/rustls.rs @@ -4,7 +4,7 @@ use crate::{ harness::{ read_to_bytes, CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, Mode, - TlsConnection, + TlsConnection, TlsBenchConfig, }, PemType::{self, *}, SigType, @@ -31,6 +31,23 @@ pub struct RustlsConnection { } impl RustlsConnection { + pub fn connection(&self) -> &Connection { + &self.connection + } + + /// Treat `WouldBlock` as an `Ok` value for when blocking is expected + fn ignore_block(res: Result) -> Result { + match res { + Ok(t) => Ok(t), + Err(err) => match err.kind() { + std::io::ErrorKind::WouldBlock => Ok(T::default()), + _ => Err(err), + }, + } + } +} + +impl RustlsConfig { fn get_root_cert_store(sig_type: SigType) -> Result> { let root_cert = Certificate(certs(&mut BufReader::new(&*read_to_bytes(CACert, sig_type)))?.remove(0)); @@ -55,21 +72,6 @@ impl RustlsConnection { pkcs8_private_keys(&mut BufReader::new(&*read_to_bytes(pem_type, sig_type)))?.remove(0), )) } - - /// Treat `WouldBlock` as an `Ok` value for when blocking is expected - fn ignore_block(res: Result) -> Result { - match res { - Ok(t) => Ok(t), - Err(err) => match err.kind() { - std::io::ErrorKind::WouldBlock => Ok(T::default()), - _ => Err(err), - }, - } - } - - pub fn connection(&self) -> &Connection { - &self.connection - } } /// Clients and servers have different config types in Rustls, so wrap them in an enum @@ -78,18 +80,12 @@ pub enum RustlsConfig { Server(Arc), } -impl TlsConnection for RustlsConnection { - type Config = RustlsConfig; - - fn name() -> String { - "rustls".to_string() - } - +impl TlsBenchConfig for RustlsConfig { fn make_config( mode: Mode, crypto_config: CryptoConfig, handshake_type: HandshakeType, - ) -> Result> { + ) -> Result> { let cipher_suite = match crypto_config.cipher_suite { CipherSuite::AES_128_GCM_SHA256 => TLS13_AES_128_GCM_SHA256, CipherSuite::AES_256_GCM_SHA384 => TLS13_AES_256_GCM_SHA384, @@ -150,6 +146,14 @@ impl TlsConnection for RustlsConnection { } } } +} + +impl TlsConnection for RustlsConnection { + type Config = RustlsConfig; + + fn name() -> String { + "rustls".to_string() + } fn new_from_config( config: &Self::Config, diff --git a/bindings/rust/bench/src/s2n_tls.rs b/bindings/rust/bench/src/s2n_tls.rs index b685e1b619e..7be0aac3809 100644 --- a/bindings/rust/bench/src/s2n_tls.rs +++ b/bindings/rust/bench/src/s2n_tls.rs @@ -63,60 +63,12 @@ pub struct S2NConfig { ticket_storage: SessionTicketStorage, } -pub struct S2NConnection { - // Pin> is to ensure long-term *mut to IO buffers remains valid - connected_buffer: Pin>, - connection: Connection, - handshake_completed: bool, -} - -impl S2NConnection { - /// Unsafe callback for custom IO C API - /// - /// s2n-tls IO is usually used with file descriptors to a TCP socket, but we - /// reduce overhead and outside noise with a local buffer for benchmarking - unsafe extern "C" fn send_cb(context: *mut c_void, data: *const u8, len: u32) -> c_int { - let context = &mut *(context as *mut ConnectedBuffer); - let data = core::slice::from_raw_parts(data, len as _); - context.write(data).unwrap() as _ - } - - /// Unsafe callback for custom IO C API - unsafe extern "C" fn recv_cb(context: *mut c_void, data: *mut u8, len: u32) -> c_int { - let context = &mut *(context as *mut ConnectedBuffer); - let data = core::slice::from_raw_parts_mut(data, len as _); - context.flush().unwrap(); - match context.read(data) { - Err(err) => { - // s2n-tls requires the callback to set errno if blocking happens - if let ErrorKind::WouldBlock = err.kind() { - errno::set_errno(errno::Errno(libc::EWOULDBLOCK)); - -1 - } else { - panic!("{err:?}"); - } - } - Ok(len) => len as _, - } - } - - pub fn connection(&self) -> &Connection { - &self.connection - } -} - -impl TlsConnection for S2NConnection { - type Config = S2NConfig; - - fn name() -> String { - "s2n-tls".to_string() - } - +impl crate::harness::TlsBenchConfig for S2NConfig { fn make_config( mode: Mode, crypto_config: CryptoConfig, handshake_type: HandshakeType, - ) -> Result> { + ) -> Result> { // these security policies negotiate the given cipher suite and key // exchange group as their top choice let security_policy = match (crypto_config.cipher_suite, crypto_config.kx_group) { @@ -198,6 +150,56 @@ impl TlsConnection for S2NConnection { ticket_storage: session_ticket_storage, }) } +} + +pub struct S2NConnection { + // Pin> is to ensure long-term *mut to IO buffers remains valid + connected_buffer: Pin>, + connection: Connection, + handshake_completed: bool, +} + +impl S2NConnection { + /// Unsafe callback for custom IO C API + /// + /// s2n-tls IO is usually used with file descriptors to a TCP socket, but we + /// reduce overhead and outside noise with a local buffer for benchmarking + unsafe extern "C" fn send_cb(context: *mut c_void, data: *const u8, len: u32) -> c_int { + let context = &mut *(context as *mut ConnectedBuffer); + let data = core::slice::from_raw_parts(data, len as _); + context.write(data).unwrap() as _ + } + + /// Unsafe callback for custom IO C API + unsafe extern "C" fn recv_cb(context: *mut c_void, data: *mut u8, len: u32) -> c_int { + let context = &mut *(context as *mut ConnectedBuffer); + let data = core::slice::from_raw_parts_mut(data, len as _); + context.flush().unwrap(); + match context.read(data) { + Err(err) => { + // s2n-tls requires the callback to set errno if blocking happens + if let ErrorKind::WouldBlock = err.kind() { + errno::set_errno(errno::Errno(libc::EWOULDBLOCK)); + -1 + } else { + panic!("{err:?}"); + } + } + Ok(len) => len as _, + } + } + + pub fn connection(&self) -> &Connection { + &self.connection + } +} + +impl TlsConnection for S2NConnection { + type Config = S2NConfig; + + fn name() -> String { + "s2n-tls".to_string() + } fn new_from_config( config: &Self::Config, From 86755eee5ec50e7963614c8df095545b4fc243fb Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Thu, 12 Oct 2023 10:26:00 -0700 Subject: [PATCH 2/4] Update bindings/rust/bench/src/harness.rs Co-authored-by: maddeleine <59030281+maddeleine@users.noreply.github.com> --- bindings/rust/bench/src/harness.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/rust/bench/src/harness.rs b/bindings/rust/bench/src/harness.rs index acacb3d9578..8511fac7f01 100644 --- a/bindings/rust/bench/src/harness.rs +++ b/bindings/rust/bench/src/harness.rs @@ -140,7 +140,7 @@ impl CryptoConfig { } } -/// The TlsBenchConfig trait allows a us to map benchmarking parameters to a +/// The TlsBenchConfig trait allows us to map benchmarking parameters to /// a configuration object pub trait TlsBenchConfig: Sized { /// Make a config with given parameters From ee55b37ce3950c9ffae5b30d1c5b779b4d71909c Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Mon, 16 Oct 2023 18:47:26 -0700 Subject: [PATCH 3/4] Update bindings/rust/bench/src/harness.rs Co-authored-by: toidiu --- bindings/rust/bench/src/harness.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/bindings/rust/bench/src/harness.rs b/bindings/rust/bench/src/harness.rs index 8511fac7f01..0730a1328cf 100644 --- a/bindings/rust/bench/src/harness.rs +++ b/bindings/rust/bench/src/harness.rs @@ -143,7 +143,6 @@ impl CryptoConfig { /// The TlsBenchConfig trait allows us to map benchmarking parameters to /// a configuration object pub trait TlsBenchConfig: Sized { - /// Make a config with given parameters fn make_config( mode: Mode, crypto_config: CryptoConfig, From b50c2aea4a28eb8bcb5b4ad9dfa1dd6e031a4dcc Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Tue, 17 Oct 2023 22:25:35 +0000 Subject: [PATCH 4/4] address pr feedback * the "purpose specific" comment was found to be confusing, remove it. --- bindings/rust/bench/src/harness.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings/rust/bench/src/harness.rs b/bindings/rust/bench/src/harness.rs index 0730a1328cf..5e7697cad80 100644 --- a/bindings/rust/bench/src/harness.rs +++ b/bindings/rust/bench/src/harness.rs @@ -151,8 +151,6 @@ pub trait TlsBenchConfig: Sized { } /// The TlsConnection object can be created from a corresponding config type. -/// Any "purpose specific" config creation should be implemented on the config -/// rather than the connection to separate configuration vs implementation. pub trait TlsConnection: Sized { /// Library-specific config struct type Config;