pub struct RustlsConnection<C> { /* private fields */ }Expand description
An established rustls connection owning its scheduler socket and TLS buffers. Sequential operations take the compatible scheduler explicitly; with_duplex additionally supervises concurrent plaintext directions. Await operations after cooperative cancellation before closing; dropping an operation provides no asynchronous retirement guarantee.
write reports the plaintext bytes accepted into TLS buffering. Follow it with flush to send the final buffered data. Cancellation while flushing preserves the exact unsent ciphertext for a later flush; never replay already accepted plaintext. A TLS protocol error is fatal, and a transport error may also make continued use impossible.
Implementations§
Source§impl<C: Send + 'static> RustlsConnection<C>
impl<C: Send + 'static> RustlsConnection<C>
Sourcepub async fn with_duplex<'scope, S, F, Fut, T, E>(
self,
scheduler: &'scope S,
cancellation: &Cancellation,
application: F,
) -> Result<T, E>where
S: SocketStreamReading<Socket = C> + SocketStreamWriting + SocketClose + ?Sized,
F: FnOnce(EncryptedSocketStreamReader<'scope>, EncryptedSocketStreamWriter<'scope>) -> Fut + Send,
Fut: Future<Output = Result<T, E>> + Send,
T: Send,
E: From<OperationError> + From<Error> + Send,
pub async fn with_duplex<'scope, S, F, Fut, T, E>(
self,
scheduler: &'scope S,
cancellation: &Cancellation,
application: F,
) -> Result<T, E>where
S: SocketStreamReading<Socket = C> + SocketStreamWriting + SocketClose + ?Sized,
F: FnOnce(EncryptedSocketStreamReader<'scope>, EncryptedSocketStreamWriter<'scope>) -> Fut + Send,
Fut: Future<Output = Result<T, E>> + Send,
T: Send,
E: From<OperationError> + From<Error> + Send,
Run an application with independent plaintext directions. Reads and writes drive retained I/O futures directly; this future supervises control output and joins persistent scheduler lanes. No task is spawned.
On successful application completion, send close_notify. On failure or cancellation, abort pending I/O. Every path joins lane retirement and consumes the socket before returning; dropping this future is not a join.
Source§impl<C> RustlsConnection<C>
impl<C> RustlsConnection<C>
Sourcepub fn socket(&self) -> &C
pub fn socket(&self) -> &C
Borrow the underlying socket to inspect its addresses. Application data must pass through the TLS connection.
Sourcepub fn peer_certificates(&self) -> Option<&[CertificateDer<'static>]>
pub fn peer_certificates(&self) -> Option<&[CertificateDer<'static>]>
The authenticated peer’s certificate chain, if supplied. Server connections only have a peer chain when client authentication completed.
Sourcepub async fn read<S>(
&mut self,
scheduler: &S,
buffer: &mut [u8],
cancellation: &Cancellation,
) -> OperationResult<usize>
pub async fn read<S>( &mut self, scheduler: &S, buffer: &mut [u8], cancellation: &Cancellation, ) -> OperationResult<usize>
Read decrypted bytes, driving pending TLS control output as needed. A nonempty buffer returns zero only after an authenticated TLS close notification. Transport EOF without that notification reports UnexpectedEof once buffered plaintext is consumed. An empty buffer returns zero after checking cancellation.
Sourcepub async fn write<S>(
&mut self,
scheduler: &S,
buffer: &[u8],
cancellation: &Cancellation,
) -> OperationResult<usize>where
S: SocketStreamWriting<Socket = C> + ?Sized,
C: 'static,
pub async fn write<S>(
&mut self,
scheduler: &S,
buffer: &[u8],
cancellation: &Cancellation,
) -> OperationResult<usize>where
S: SocketStreamWriting<Socket = C> + ?Sized,
C: 'static,
Flush prior output, then accept a possibly short plaintext prefix into TLS buffering. The accepted prefix is reported without any subsequent asynchronous wait. Call flush to send it; later writes and reads also drive queued output.
Sourcepub async fn flush<S>(
&mut self,
scheduler: &S,
cancellation: &Cancellation,
) -> OperationResult<()>where
S: SocketStreamWriting<Socket = C> + ?Sized,
C: 'static,
pub async fn flush<S>(
&mut self,
scheduler: &S,
cancellation: &Cancellation,
) -> OperationResult<()>where
S: SocketStreamWriting<Socket = C> + ?Sized,
C: 'static,
Send all queued TLS records, including pending ciphertext from a cancelled flush. Cancellation does not discard or duplicate bytes already accepted by TLS.
Sourcepub async fn shutdown<S>(
&mut self,
scheduler: &S,
cancellation: &Cancellation,
) -> OperationResult<()>where
S: SocketStreamWriting<Socket = C> + ?Sized,
C: 'static,
pub async fn shutdown<S>(
&mut self,
scheduler: &S,
cancellation: &Cancellation,
) -> OperationResult<()>where
S: SocketStreamWriting<Socket = C> + ?Sized,
C: 'static,
Send a TLS close notification and stop accepting plaintext writes. Reads remain available. This does not wait for the peer’s close notification or close the socket. Retry after cancellation to finish sending the same notification.
Sourcepub async fn close<S>(
self,
scheduler: &S,
cancellation: &Cancellation,
) -> OperationResult<()>
pub async fn close<S>( self, scheduler: &S, cancellation: &Cancellation, ) -> OperationResult<()>
Attempt TLS shutdown, then consume and close the socket even if shutdown failed or was cancelled. Preserve the shutdown error if socket closure also fails.
Trait Implementations§
Source§impl<C: Debug> Debug for RustlsConnection<C>
impl<C: Debug> Debug for RustlsConnection<C>
Source§impl<C: Send> TlsSession for RustlsConnection<C>
impl<C: Send> TlsSession for RustlsConnection<C>
Source§fn negotiated_protocol(&self) -> Option<&[u8]>
fn negotiated_protocol(&self) -> Option<&[u8]>
None if no protocol was negotiated. Protocol identifiers are opaque bytes; callers must decide whether the selected protocol is acceptable.Source§impl<S> TlsStream<S> for RustlsConnection<S::Socket>
impl<S> TlsStream<S> for RustlsConnection<S::Socket>
Source§async fn read(
&mut self,
scheduler: &S,
buffer: &mut [u8],
cancellation: &Cancellation,
) -> OperationResult<usize>
async fn read( &mut self, scheduler: &S, buffer: &mut [u8], cancellation: &Cancellation, ) -> OperationResult<usize>
UnexpectedEof after buffered plaintext is consumed. Empty storage returns zero after checking cancellation.Source§async fn write(
&mut self,
scheduler: &S,
buffer: &[u8],
cancellation: &Cancellation,
) -> OperationResult<usize>
async fn write( &mut self, scheduler: &S, buffer: &[u8], cancellation: &Cancellation, ) -> OperationResult<usize>
flush to send the final queued output. No bytes are accepted on an error return. Writing after local TLS shutdown fails.