mod rustls_acceptor;
mod rustls_connection;
mod rustls_connector;
pub use rustls_acceptor::RustlsAcceptor;
pub use rustls_connection::{
EncryptedSocketStreamReader, EncryptedSocketStreamWriter, RustlsConnection,
};
pub use rustls_connector::RustlsConnector;
use base_scheduler::{
Cancellation, OperationResult, SocketClose, SocketStreamReading, SocketStreamWriting,
};
use std::io;
fn tls_error(error: ::rustls::Error) -> io::Error {
io::Error::new(io::ErrorKind::InvalidData, error)
}
async fn establish<S>(
scheduler: &S,
socket: S::Socket,
state: OperationResult<::rustls::Connection>,
cancellation: &Cancellation,
) -> OperationResult<RustlsConnection<S::Socket>>
where
S: SocketStreamReading + SocketStreamWriting + SocketClose + ?Sized,
S::Socket: 'static,
{
let state = match state {
Ok(state) => state,
Err(error) => {
let _ = scheduler.socket_close(socket).await;
return Err(error);
}
};
let mut connection = RustlsConnection::new(socket, state);
match connection.handshake(scheduler, cancellation).await {
Ok(()) => Ok(connection),
Err(error) => {
let _ = connection.abort(scheduler).await;
Err(error)
}
}
}