Box<dyn ReadWrite> for TlsConnector::connect

This commit is contained in:
Martin Algesten
2022-04-30 12:50:08 +02:00
parent 101467f13f
commit 65371c966c
6 changed files with 90 additions and 51 deletions

View File

@@ -31,21 +31,28 @@ struct PassThrough {
}
impl TlsConnector for PassThrough {
fn connect(&self, _dns_name: &str, tcp_stream: TcpStream) -> Result<Box<dyn ReadWrite>, Error> {
fn connect(
&self,
_dns_name: &str,
io: Box<dyn ReadWrite>,
) -> Result<Box<dyn ReadWrite>, Error> {
if self.handshake_fail {
let io_err = io::Error::new(io::ErrorKind::InvalidData, PassThroughError);
return Err(io_err.into());
}
Ok(Box::new(CustomTlsStream(tcp_stream)))
Ok(Box::new(CustomTlsStream(io)))
}
}
struct CustomTlsStream(TcpStream);
struct CustomTlsStream(Box<dyn ReadWrite>);
impl ReadWrite for CustomTlsStream {
fn socket(&self) -> Option<&TcpStream> {
Some(&self.0)
self.0.socket()
}
fn is_poolable(&self) -> bool {
self.0.is_poolable()
}
}