pub struct TlsConnection<'a, Socket, CipherSuite>
where Socket: AsyncRead + AsyncWrite + 'a, CipherSuite: TlsCipherSuite + 'static,
{ /* private fields */ }
Expand description

Type representing an async TLS connection. An instance of this type can be used to establish a TLS connection, write and read encrypted data over this connection, and closing to free up the underlying resources.

Implementations§

source§

impl<'a, Socket, CipherSuite> TlsConnection<'a, Socket, CipherSuite>
where Socket: AsyncRead + AsyncWrite + 'a, CipherSuite: TlsCipherSuite + 'static,

source

pub fn new( delegate: Socket, record_read_buf: &'a mut [u8], record_write_buf: &'a mut [u8] ) -> Self

Create a new TLS connection with the provided context and a async I/O implementation

NOTE: The record read buffer should be sized to fit an encrypted TLS record. The size of this record depends on the server configuration, but the maximum allowed value for a TLS record is 16640 bytes, which should be a safe value to use.

The write record buffer can be smaller than the read buffer. During writes TLS_RECORD_OVERHEAD bytes of overhead is added per record, so the buffer must at least be this large. Large writes are split into multiple records if depending on the size of the write buffer. The largest of the two buffers will be used to encode the TLS handshake record, hence either of the buffers must at least be large enough to encode a handshake.

source

pub async fn open<'v, RNG, Verifier>( &mut self, context: TlsContext<'v, CipherSuite, RNG> ) -> Result<(), TlsError>
where RNG: CryptoRng + RngCore, Verifier: TlsVerifier<'v, CipherSuite>,

Open a TLS connection, performing the handshake with the configuration provided when creating the connection instance.

Returns an error if the handshake does not proceed. If an error occurs, the connection instance must be recreated.

source

pub async fn write(&mut self, buf: &[u8]) -> Result<usize, TlsError>

Encrypt and send the provided slice over the connection. The connection must be opened before writing.

The slice may be buffered internally and not written to the connection immediately. In this case Self::flush() should be called to force the currently buffered writes to be written to the connection.

Returns the number of bytes buffered/written.

source

pub async fn flush(&mut self) -> Result<(), TlsError>

Force all previously written, buffered bytes to be encoded into a tls record and written to the connection.

source

pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, TlsError>

Read and decrypt data filling the provided slice.

source

pub async fn read_buffered(&mut self) -> Result<ReadBuffer<'_>, TlsError>

Reads buffered data. If nothing is in memory, it’ll wait for a TLS record and process it.

source

pub async fn close(self) -> Result<Socket, (Socket, TlsError)>

Close a connection instance, returning the ownership of the async I/O provider.

source

pub fn split( self ) -> (TlsReader<'a, Socket, CipherSuite, ManagedSplitState>, TlsWriter<'a, Socket, CipherSuite, ManagedSplitState>)
where Socket: Clone,

source

pub fn split_with<StateContainer>( self, state: StateContainer ) -> (TlsReader<'a, Socket, CipherSuite, StateContainer::State>, TlsWriter<'a, Socket, CipherSuite, StateContainer::State>)
where Socket: Clone, StateContainer: SplitStateContainer,

source

pub fn unsplit<State>( reader: TlsReader<'a, Socket, CipherSuite, State>, writer: TlsWriter<'a, Socket, CipherSuite, State> ) -> Self
where Socket: Clone, State: SplitState,

Trait Implementations§

source§

impl<'a, Socket, CipherSuite> BufRead for TlsConnection<'a, Socket, CipherSuite>
where Socket: AsyncRead + AsyncWrite + 'a, CipherSuite: TlsCipherSuite + 'static,

source§

async fn fill_buf(&mut self) -> Result<&[u8], Self::Error>

Return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
source§

fn consume(&mut self, amt: usize)

Tell this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to fill_buf.
source§

impl<'a, Socket, CipherSuite> ErrorType for TlsConnection<'a, Socket, CipherSuite>
where Socket: AsyncRead + AsyncWrite + 'a, CipherSuite: TlsCipherSuite + 'static,

§

type Error = TlsError

Error type of all the IO operations on this type.
source§

impl<'a, Socket, CipherSuite> Read for TlsConnection<'a, Socket, CipherSuite>
where Socket: AsyncRead + AsyncWrite + 'a, CipherSuite: TlsCipherSuite + 'static,

source§

async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
source§

async fn read_exact( &mut self, buf: &mut [u8] ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
source§

impl<'a, Socket, CipherSuite> Write for TlsConnection<'a, Socket, CipherSuite>
where Socket: AsyncRead + AsyncWrite + 'a, CipherSuite: TlsCipherSuite + 'static,

source§

async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

async fn flush(&mut self) -> Result<(), Self::Error>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
source§

async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more

Auto Trait Implementations§

§

impl<'a, Socket, CipherSuite> RefUnwindSafe for TlsConnection<'a, Socket, CipherSuite>
where CipherSuite: RefUnwindSafe, Socket: RefUnwindSafe, <<<CipherSuite as TlsCipherSuite>::Hash as BlockSizeUser>::BlockSize as ArrayLength<u8>>::ArrayType: RefUnwindSafe, <<<CipherSuite as TlsCipherSuite>::Hash as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: RefUnwindSafe, <CipherSuite as TlsCipherSuite>::Hash: RefUnwindSafe,

§

impl<'a, Socket, CipherSuite> Send for TlsConnection<'a, Socket, CipherSuite>
where CipherSuite: Send, Socket: Send, <CipherSuite as TlsCipherSuite>::Hash: Send,

§

impl<'a, Socket, CipherSuite> Sync for TlsConnection<'a, Socket, CipherSuite>
where CipherSuite: Sync, Socket: Sync, <CipherSuite as TlsCipherSuite>::Hash: Sync,

§

impl<'a, Socket, CipherSuite> Unpin for TlsConnection<'a, Socket, CipherSuite>
where CipherSuite: Unpin, Socket: Unpin, <<<CipherSuite as TlsCipherSuite>::Hash as BlockSizeUser>::BlockSize as ArrayLength<u8>>::ArrayType: Unpin, <<<CipherSuite as TlsCipherSuite>::Hash as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: Unpin, <CipherSuite as TlsCipherSuite>::Hash: Unpin,

§

impl<'a, Socket, CipherSuite> !UnwindSafe for TlsConnection<'a, Socket, CipherSuite>

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.