Skip to content

Commit

Permalink
tokio-s2n-tls: Enable access to the IO instance from TcpStream (#3882)
Browse files Browse the repository at this point in the history
* tokio-s2n-tls: Enable access to the IO instance from TcpStream

* Rename io_* get_* for getting the inner stream

---------

Co-authored-by: Cameron Bytheway <[email protected]>
  • Loading branch information
mathpal and camshaft authored Mar 16, 2023
1 parent 6f4e104 commit d35e966
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bindings/rust/s2n-tls-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ where
C: AsRef<Connection> + AsMut<Connection> + Unpin,
S: AsyncRead + AsyncWrite + Unpin,
{
///Access a shared reference to the underlaying io stream
pub fn get_ref(&self) -> &S {
&self.stream
}

///Access the mutable reference to the underlaying io stream
pub fn get_mut(&mut self) -> &mut S {
&mut self.stream
}

async fn open(mut conn: C, stream: S) -> Result<Self, Error> {
conn.as_mut().set_blinding(Blinding::SelfService)?;
let mut tls = TlsStream {
Expand Down
17 changes: 17 additions & 0 deletions bindings/rust/s2n-tls-tokio/tests/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,20 @@ async fn handshake_error_with_blinding() -> Result<(), Box<dyn std::error::Error

Ok(())
}

#[tokio::test]
async fn io_stream_access() -> Result<(), Box<dyn std::error::Error>> {
let (server_stream, client_stream) = common::get_streams().await?;

let client_addr = client_stream.local_addr().unwrap();
let client = TlsConnector::new(common::client_config()?.build()?);
let server = TlsAcceptor::new(common::server_config()?.build()?);

let (mut client_result, _server_result) =
common::run_negotiate(&client, client_stream, &server, server_stream).await?;

assert_eq!(client_result.get_ref().local_addr().unwrap(), client_addr);
assert_eq!(client_result.get_mut().local_addr().unwrap(), client_addr);

Ok(())
}

0 comments on commit d35e966

Please sign in to comment.