Skip to main content

RustlsConnection

Struct RustlsConnection 

Source
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>

Source

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>

Source

pub fn socket(&self) -> &C

Borrow the underlying socket to inspect its addresses. Application data must pass through the TLS connection.

Source

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.

Source

pub async fn read<S>( &mut self, scheduler: &S, buffer: &mut [u8], cancellation: &Cancellation, ) -> OperationResult<usize>
where S: SocketStreamReading<Socket = C> + SocketStreamWriting + ?Sized, C: 'static,

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn close<S>( self, scheduler: &S, cancellation: &Cancellation, ) -> OperationResult<()>
where S: SocketStreamWriting<Socket = C> + SocketClose + ?Sized, C: 'static,

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.

Source

pub async fn abort<S>(self, scheduler: &S) -> Result<()>
where S: SocketClose<Socket = C> + ?Sized,

Consume and close the socket without sending a TLS close notification. Use after fatal errors or when graceful output is not required.

Trait Implementations§

Source§

impl<C: Debug> Debug for RustlsConnection<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: Send> TlsSession for RustlsConnection<C>

Source§

fn negotiated_protocol(&self) -> Option<&[u8]>

The protocol selected by ALPN, or 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>

Source§

async fn read( &mut self, scheduler: &S, buffer: &mut [u8], cancellation: &Cancellation, ) -> OperationResult<usize>

Read a possibly short plaintext prefix. A nonempty destination returns zero after an authenticated TLS close notification. Unexpected transport EOF reports 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>

Flush previous output, then accept a possibly short plaintext prefix. Return its accepted byte count without any subsequent asynchronous wait; use flush to send the final queued output. No bytes are accepted on an error return. Writing after local TLS shutdown fails.
Source§

async fn flush( &mut self, scheduler: &S, cancellation: &Cancellation, ) -> OperationResult<()>

Send queued output. Cancellation leaves the unsent ciphertext available for a subsequent flush.
Source§

async fn shutdown( &mut self, scheduler: &S, cancellation: &Cancellation, ) -> OperationResult<()>

Stop accepting plaintext writes and send a TLS close notification. Reads remain available. Retry after cancellation to finish sending the notification; this does not wait for peer closure.
Source§

async fn close( self, scheduler: &S, cancellation: &Cancellation, ) -> OperationResult<()>

Attempt TLS shutdown and consume/close the transport even if shutdown fails or is cancelled. Return the primary shutdown error if closure also fails.
Source§

async fn abort(self, scheduler: &S) -> Result<()>

Consume and close the transport without a TLS close notification, for example after a fatal handshake or application-data error.

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for RustlsConnection<C>

§

impl<C> !UnwindSafe for RustlsConnection<C>

§

impl<C> Freeze for RustlsConnection<C>
where C: Freeze,

§

impl<C> Send for RustlsConnection<C>
where C: Send,

§

impl<C> Sync for RustlsConnection<C>
where C: Sync,

§

impl<C> Unpin for RustlsConnection<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for RustlsConnection<C>
where C: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.