| 1 | use craterust-analyzer cargo async-tls 0.13.0 crate/::commonrust-analyzer cargo async-tls 0.13.0 common/::tls_staterust-analyzer cargo async-tls 0.13.0 common/tls_state/::TlsStaterust-analyzer cargo async-tls 0.13.0 common/tls_state/TlsState#; |
| 2 | use craterust-analyzer cargo async-tls 0.13.0 crate/::serverrust-analyzer cargo async-tls 0.13.0 server/; |
| 3 | |
| 4 | use futures_iorust-analyzer cargo futures-io 0.3.34 crate/::{AsyncReadrust-analyzer cargo futures-io 0.3.34 if_std/AsyncRead#, AsyncWriterust-analyzer cargo futures-io 0.3.34 if_std/AsyncWrite#}; |
| 5 | use rustlsrust-analyzer cargo rustls 0.23.43 crate/::{ServerConfigrust-analyzer cargo rustls 0.23.43 server/server_conn/ServerConfig#, ServerConnectionrust-analyzer cargo rustls 0.23.43 server/server_conn/connection/ServerConnection#}; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/::Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#; |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 8 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#; |
| 9 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 10 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::{Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#, Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#}; |
| 11 | |
| 12 | /// The TLS accepting part. The acceptor drives |
| 13 | /// the server side of the TLS handshake process. It works |
| 14 | /// on any asynchronous stream. |
| 15 | /// |
| 16 | /// It provides a simple interface (`accept`), returning a future |
| 17 | /// that will resolve when the handshake process completed. On |
| 18 | /// success, it will hand you an async `TLSStream`. |
| 19 | /// |
| 20 | /// ## Example |
| 21 | /// |
| 22 | /// See /examples/server for an example. |
| 23 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 24 | pub struct TlsAcceptorrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor# { |
| 25 | innerrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor#inner.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<ServerConfigrust-analyzer cargo rustls 0.23.43 server/server_conn/ServerConfig#>, |
| 26 | } |
| 27 | |
| 28 | impl TlsAcceptorrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor# { |
| 29 | /// Accept a client connections. `stream` can be any type implementing `AsyncRead` and `AsyncWrite`, |
| 30 | /// such as TcpStreams or Unix domain sockets. |
| 31 | /// |
| 32 | /// Otherwise, it will return a `Accept` Future, representing the Acceptance part of a |
| 33 | /// Tls handshake. It will resolve when the handshake is over. |
| 34 | #[inline] |
| 35 | pub fn acceptrust-analyzer cargo async-tls 0.13.0 acceptor/impl#[TlsAcceptor]accept().<IO>(&self, stream: IO) -> Acceptrust-analyzer cargo async-tls 0.13.0 acceptor/Accept#<IO> |
| 36 | where |
| 37 | IO: AsyncReadrust-analyzer cargo futures-io 0.3.34 if_std/AsyncRead# + AsyncWriterust-analyzer cargo futures-io 0.3.34 if_std/AsyncWrite# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#, |
| 38 | { |
| 39 | self.accept_withrust-analyzer cargo async-tls 0.13.0 acceptor/impl#[TlsAcceptor]accept_with().(stream, |_| ()) |
| 40 | } |
| 41 | |
| 42 | // Currently private, as exposing ServerConnections exposes rusttls |
| 43 | fn accept_withrust-analyzer cargo async-tls 0.13.0 acceptor/impl#[TlsAcceptor]accept_with().<IO, F>(&self, stream: IO, f: F) -> Acceptrust-analyzer cargo async-tls 0.13.0 acceptor/Accept#<IO> |
| 44 | where |
| 45 | IO: AsyncReadrust-analyzer cargo futures-io 0.3.34 if_std/AsyncRead# + AsyncWriterust-analyzer cargo futures-io 0.3.34 if_std/AsyncWrite# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#, |
| 46 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&mut ServerConnectionrust-analyzer cargo rustls 0.23.43 server/server_conn/connection/ServerConnection#), |
| 47 | { |
| 48 | let mut conn = match ServerConnectionrust-analyzer cargo rustls 0.23.43 server/server_conn/connection/ServerConnection#::newrust-analyzer cargo rustls 0.23.43 server/server_conn/connection/impl#[ServerConnection]new().(self.innerrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor#inner..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().()) { |
| 49 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(conn) => conn, |
| 50 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => { |
| 51 | return Acceptrust-analyzer cargo async-tls 0.13.0 acceptor/Accept#(serverrust-analyzer cargo async-tls 0.13.0 server/::MidHandshakerust-analyzer cargo async-tls 0.13.0 server/MidHandshake#::Endrust-analyzer cargo async-tls 0.13.0 server/MidHandshake#End#); |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | f(&mut conn); |
| 56 | |
| 57 | Acceptrust-analyzer cargo async-tls 0.13.0 acceptor/Accept#(serverrust-analyzer cargo async-tls 0.13.0 server/::MidHandshakerust-analyzer cargo async-tls 0.13.0 server/MidHandshake#::Handshakingrust-analyzer cargo async-tls 0.13.0 server/MidHandshake#Handshaking#(serverrust-analyzer cargo async-tls 0.13.0 server/::TlsStreamrust-analyzer cargo async-tls 0.13.0 server/TlsStream# { |
| 58 | connrust-analyzer cargo async-tls 0.13.0 server/TlsStream#conn., |
| 59 | iorust-analyzer cargo async-tls 0.13.0 server/TlsStream#io.: stream, |
| 60 | staterust-analyzer cargo async-tls 0.13.0 server/TlsStream#state.: TlsStaterust-analyzer cargo async-tls 0.13.0 common/tls_state/TlsState#::Streamrust-analyzer cargo async-tls 0.13.0 common/tls_state/TlsState#Stream#, |
| 61 | })) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /// Future returned from `TlsAcceptor::accept` which will resolve |
| 66 | /// once the accept handshake has finished. |
| 67 | pub struct Acceptrust-analyzer cargo async-tls 0.13.0 acceptor/Accept#<IO>(serverrust-analyzer cargo async-tls 0.13.0 server/::MidHandshakerust-analyzer cargo async-tls 0.13.0 server/MidHandshake#<IO>); |
| 68 | |
| 69 | impl<IO: AsyncReadrust-analyzer cargo futures-io 0.3.34 if_std/AsyncRead# + AsyncWriterust-analyzer cargo futures-io 0.3.34 if_std/AsyncWrite# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#> Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future# for Acceptrust-analyzer cargo async-tls 0.13.0 acceptor/Accept#<IO> { |
| 70 | type Outputrust-analyzer cargo async-tls 0.13.0 acceptor/impl#[`Accept<IO>`][Future]Output# = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<serverrust-analyzer cargo async-tls 0.13.0 server/::TlsStreamrust-analyzer cargo async-tls 0.13.0 server/TlsStream#<IO>>; |
| 71 | |
| 72 | #[inline] |
| 73 | fn pollrust-analyzer cargo async-tls 0.13.0 acceptor/impl#[`Accept<IO>`][Future]poll().(mut self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo async-tls 0.13.0 acceptor/impl#[`Accept<IO>`][Future]>, cx: &mut Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<Selfrust-analyzer cargo async-tls 0.13.0 acceptor/impl#[`Accept<IO>`][Future]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#> { |
| 74 | Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(&mut self.0rust-analyzer cargo async-tls 0.13.0 acceptor/Accept#0.).pollrust-analyzer cargo async-tls 0.13.0 server/impl#[`MidHandshake<IO>`][Future]poll().(cx) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<ServerConfigrust-analyzer cargo rustls 0.23.43 server/server_conn/ServerConfig#>> for TlsAcceptorrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor# { |
| 79 | fn fromrust-analyzer cargo async-tls 0.13.0 acceptor/impl#[TlsAcceptor][`From<Arc<ServerConfig>>`]from().(inner: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<ServerConfigrust-analyzer cargo rustls 0.23.43 server/server_conn/ServerConfig#>) -> TlsAcceptorrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor# { |
| 80 | TlsAcceptorrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor# { innerrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor#inner. } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<ServerConfigrust-analyzer cargo rustls 0.23.43 server/server_conn/ServerConfig#> for TlsAcceptorrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor# { |
| 85 | fn fromrust-analyzer cargo async-tls 0.13.0 acceptor/impl#[TlsAcceptor][`From<ServerConfig>`]from().(inner: ServerConfigrust-analyzer cargo rustls 0.23.43 server/server_conn/ServerConfig#) -> TlsAcceptorrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor# { |
| 86 | TlsAcceptorrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor# { |
| 87 | innerrust-analyzer cargo async-tls 0.13.0 acceptor/TlsAcceptor#inner.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(inner), |
| 88 | } |
| 89 | } |
| 90 | } |