Fixes after feedback
This commit is contained in:
@@ -34,7 +34,7 @@ impl TlsConnector for PassThrough {
|
||||
fn connect(
|
||||
&self,
|
||||
_dns_name: &str,
|
||||
io: Box<dyn ReadWrite>,
|
||||
io: Box<dyn ReadWrite + Sync>,
|
||||
) -> Result<Box<dyn ReadWrite>, Error> {
|
||||
if self.handshake_fail {
|
||||
let io_err = io::Error::new(io::ErrorKind::InvalidData, PassThroughError);
|
||||
@@ -45,6 +45,7 @@ impl TlsConnector for PassThrough {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CustomTlsStream(Box<dyn ReadWrite>);
|
||||
|
||||
impl ReadWrite for CustomTlsStream {
|
||||
|
||||
@@ -56,11 +56,10 @@ impl TlsConnector for MbedTlsConnector {
|
||||
fn connect(
|
||||
&self,
|
||||
_dns_name: &str,
|
||||
io: Box<dyn ReadWrite>,
|
||||
io: Box<dyn ReadWrite + Sync>,
|
||||
) -> Result<Box<dyn ReadWrite>, Error> {
|
||||
let mut ctx = self.context.lock().unwrap();
|
||||
let sync = SyncIo(Mutex::new(io));
|
||||
match ctx.establish(sync, None) {
|
||||
match ctx.establish(io, None) {
|
||||
Err(_) => {
|
||||
let io_err = io::Error::new(io::ErrorKind::InvalidData, MbedTlsError);
|
||||
return Err(io_err.into());
|
||||
@@ -70,32 +69,16 @@ impl TlsConnector for MbedTlsConnector {
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal wrapper to make Box<dyn ReadWrite> implement Sync
|
||||
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,
|
||||
}
|
||||
|
||||
impl fmt::Debug for MbedTlsStream {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("MbedTlsStream").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl MbedTlsStream {
|
||||
pub fn new(mtc: &MbedTlsConnector) -> Box<MbedTlsStream> {
|
||||
Box::new(MbedTlsStream {
|
||||
|
||||
Reference in New Issue
Block a user