base_endpoint/tls/
rustls.rs1mod rustls_acceptor;
9mod rustls_connection;
10mod rustls_connector;
11
12pub use rustls_acceptor::RustlsAcceptor;
13pub use rustls_connection::{
14 EncryptedSocketStreamReader, EncryptedSocketStreamWriter, RustlsConnection,
15};
16pub use rustls_connector::RustlsConnector;
17
18use base_scheduler::{
19 Cancellation, OperationResult, SocketClose, SocketStreamReading, SocketStreamWriting,
20};
21use std::io;
22
23fn tls_error(error: ::rustls::Error) -> io::Error {
24 io::Error::new(io::ErrorKind::InvalidData, error)
25}
26
27async fn establish<S>(
28 scheduler: &S,
29 socket: S::Socket,
30 state: OperationResult<::rustls::Connection>,
31 cancellation: &Cancellation,
32) -> OperationResult<RustlsConnection<S::Socket>>
33where
34 S: SocketStreamReading + SocketStreamWriting + SocketClose + ?Sized,
35 S::Socket: 'static,
36{
37 let state = match state {
38 Ok(state) => state,
39 Err(error) => {
40 let _ = scheduler.socket_close(socket).await;
41 return Err(error);
42 }
43 };
44 let mut connection = RustlsConnection::new(socket, state);
45 match connection.handshake(scheduler, cancellation).await {
46 Ok(()) => Ok(connection),
47 Err(error) => {
48 let _ = connection.abort(scheduler).await;
49 Err(error)
50 }
51 }
52}