Remove Sync bound from TlsConnector io arg
This commit is contained in:
@@ -34,7 +34,7 @@ impl TlsConnector for PassThrough {
|
||||
fn connect(
|
||||
&self,
|
||||
_dns_name: &str,
|
||||
io: Box<dyn ReadWrite + Sync>,
|
||||
io: Box<dyn ReadWrite>,
|
||||
) -> Result<Box<dyn ReadWrite>, Error> {
|
||||
if self.handshake_fail {
|
||||
let io_err = io::Error::new(io::ErrorKind::InvalidData, PassThroughError);
|
||||
|
||||
@@ -56,10 +56,11 @@ impl TlsConnector for MbedTlsConnector {
|
||||
fn connect(
|
||||
&self,
|
||||
_dns_name: &str,
|
||||
io: Box<dyn ReadWrite + Sync>,
|
||||
io: Box<dyn ReadWrite>,
|
||||
) -> Result<Box<dyn ReadWrite>, Error> {
|
||||
let mut ctx = self.context.lock().unwrap();
|
||||
match ctx.establish(io, None) {
|
||||
let sync = SyncIo(Mutex::new(io));
|
||||
match ctx.establish(sync, None) {
|
||||
Err(_) => {
|
||||
let io_err = io::Error::new(io::ErrorKind::InvalidData, MbedTlsError);
|
||||
return Err(io_err.into());
|
||||
@@ -69,6 +70,27 @@ impl TlsConnector for MbedTlsConnector {
|
||||
}
|
||||
}
|
||||
|
||||
struct SyncIo(Mutex<Box<dyn ReadWrite>>);
|
||||
|
||||
impl io::Read for SyncIo {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
let mut lock = self.0.lock().unwrap();
|
||||
lock.read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Write for SyncIo {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
let mut lock = self.0.lock().unwrap();
|
||||
lock.write(buf)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
let mut lock = self.0.lock().unwrap();
|
||||
lock.flush()
|
||||
}
|
||||
}
|
||||
|
||||
struct MbedTlsStream {
|
||||
context: Arc<Mutex<Context>>, //tcp_stream: TcpStream,
|
||||
}
|
||||
|
||||
@@ -364,7 +364,7 @@ pub(crate) fn default_tls_config() -> std::sync::Arc<dyn TlsConnector> {
|
||||
fn connect(
|
||||
&self,
|
||||
_dns_name: &str,
|
||||
_io: Box<dyn ReadWrite + Sync>,
|
||||
_io: Box<dyn ReadWrite>,
|
||||
) -> Result<Box<dyn ReadWrite>, crate::error::Error> {
|
||||
Err(ErrorKind::UnknownScheme
|
||||
.msg("cannot make HTTPS request because no TLS backend is configured"))
|
||||
|
||||
@@ -11,11 +11,7 @@ pub(crate) fn default_tls_config() -> std::sync::Arc<dyn TlsConnector> {
|
||||
}
|
||||
|
||||
impl TlsConnector for native_tls::TlsConnector {
|
||||
fn connect(
|
||||
&self,
|
||||
dns_name: &str,
|
||||
io: Box<dyn ReadWrite + Sync>,
|
||||
) -> Result<Box<dyn ReadWrite>, Error> {
|
||||
fn connect(&self, dns_name: &str, io: Box<dyn ReadWrite>) -> Result<Box<dyn ReadWrite>, Error> {
|
||||
let stream =
|
||||
native_tls::TlsConnector::connect(self, dns_name, io).map_err(|e| match e {
|
||||
native_tls::HandshakeError::Failure(e) => ErrorKind::ConnectionFailed
|
||||
@@ -31,7 +27,7 @@ impl TlsConnector for native_tls::TlsConnector {
|
||||
}
|
||||
|
||||
#[cfg(feature = "native-tls")]
|
||||
impl ReadWrite for native_tls::TlsStream<Box<dyn ReadWrite + Sync>> {
|
||||
impl ReadWrite for native_tls::TlsStream<Box<dyn ReadWrite>> {
|
||||
fn socket(&self) -> Option<&TcpStream> {
|
||||
self.get_ref().socket()
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ fn is_close_notify(e: &std::io::Error) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
struct RustlsStream(rustls::StreamOwned<rustls::ClientConnection, Box<dyn ReadWrite + Sync>>);
|
||||
struct RustlsStream(rustls::StreamOwned<rustls::ClientConnection, Box<dyn ReadWrite>>);
|
||||
|
||||
impl ReadWrite for RustlsStream {
|
||||
fn socket(&self) -> Option<&TcpStream> {
|
||||
@@ -97,7 +97,7 @@ impl TlsConnector for Arc<rustls::ClientConfig> {
|
||||
fn connect(
|
||||
&self,
|
||||
dns_name: &str,
|
||||
mut io: Box<dyn ReadWrite + Sync>,
|
||||
mut io: Box<dyn ReadWrite>,
|
||||
) -> Result<Box<dyn ReadWrite>, Error> {
|
||||
let sni = rustls::ServerName::try_from(dns_name)
|
||||
.map_err(|e| ErrorKind::Dns.msg(format!("parsing '{}'", dns_name)).src(e))?;
|
||||
|
||||
@@ -42,7 +42,7 @@ pub trait TlsConnector: Send + Sync {
|
||||
fn connect(
|
||||
&self,
|
||||
dns_name: &str,
|
||||
io: Box<dyn ReadWrite + Sync>,
|
||||
io: Box<dyn ReadWrite>,
|
||||
) -> Result<Box<dyn ReadWrite>, crate::error::Error>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user