base_endpoint/tls/rustls/
rustls_acceptor.rs1use super::{RustlsConnection, establish, tls_error};
5use crate::tls::TlsAcceptor;
6use ::rustls::{ServerConfig, ServerConnection};
7use base_scheduler::{
8 Cancellation, OperationResult, SocketClose, SocketStreamReading, SocketStreamWriting,
9};
10use std::sync::Arc;
11
12#[derive(Clone, Debug)]
14pub struct RustlsAcceptor {
15 config: Arc<ServerConfig>,
16}
17
18impl RustlsAcceptor {
19 pub fn new(config: Arc<ServerConfig>) -> Self {
21 Self { config }
22 }
23}
24
25impl<S> TlsAcceptor<S, S::Socket> for RustlsAcceptor
26where
27 S: SocketStreamReading + SocketStreamWriting + SocketClose + ?Sized,
28 S::Socket: 'static,
29{
30 type Connection = RustlsConnection<S::Socket>;
31
32 async fn accept(
33 &self,
34 scheduler: &S,
35 connection: S::Socket,
36 cancellation: &Cancellation,
37 ) -> OperationResult<Self::Connection> {
38 let state = (|| {
39 cancellation.check()?;
40 Ok(ServerConnection::new(self.config.clone())
41 .map_err(tls_error)?
42 .into())
43 })();
44 establish(scheduler, connection, state, cancellation).await
45 }
46}