Struct embedded_tls::TlsConnection
source · pub struct TlsConnection<'a, Socket, CipherSuite>{ /* 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>
impl<'a, Socket, CipherSuite> TlsConnection<'a, Socket, CipherSuite>
sourcepub fn new(
delegate: Socket,
record_read_buf: &'a mut [u8],
record_write_buf: &'a mut [u8]
) -> Self
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.
sourcepub async fn open<'v, RNG, Verifier>(
&mut self,
context: TlsContext<'v, CipherSuite, RNG>
) -> Result<(), TlsError>
pub async fn open<'v, RNG, Verifier>( &mut self, context: TlsContext<'v, CipherSuite, RNG> ) -> Result<(), TlsError>
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.
sourcepub async fn write(&mut self, buf: &[u8]) -> Result<usize, TlsError>
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.
sourcepub async fn flush(&mut self) -> Result<(), TlsError>
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.
sourcepub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, TlsError>
pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, TlsError>
Read and decrypt data filling the provided slice.
sourcepub async fn read_buffered(&mut self) -> Result<ReadBuffer<'_>, TlsError>
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.
sourcepub async fn close(self) -> Result<Socket, (Socket, TlsError)>
pub async fn close(self) -> Result<Socket, (Socket, TlsError)>
Close a connection instance, returning the ownership of the async I/O provider.
pub fn split(
self
) -> (TlsReader<'a, Socket, CipherSuite, ManagedSplitState>, TlsWriter<'a, Socket, CipherSuite, ManagedSplitState>)where
Socket: Clone,
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,
pub fn unsplit<State>(
reader: TlsReader<'a, Socket, CipherSuite, State>,
writer: TlsWriter<'a, Socket, CipherSuite, State>
) -> Selfwhere
Socket: Clone,
State: SplitState,
Trait Implementations§
source§impl<'a, Socket, CipherSuite> BufRead for TlsConnection<'a, Socket, CipherSuite>
impl<'a, Socket, CipherSuite> BufRead for TlsConnection<'a, Socket, CipherSuite>
source§impl<'a, Socket, CipherSuite> ErrorType for TlsConnection<'a, Socket, CipherSuite>
impl<'a, Socket, CipherSuite> ErrorType for TlsConnection<'a, Socket, CipherSuite>
source§impl<'a, Socket, CipherSuite> Read for TlsConnection<'a, Socket, CipherSuite>
impl<'a, Socket, CipherSuite> Read for TlsConnection<'a, Socket, CipherSuite>
source§async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
source§async fn read_exact(
&mut self,
buf: &mut [u8]
) -> Result<(), ReadExactError<Self::Error>>
async fn read_exact( &mut self, buf: &mut [u8] ) -> Result<(), ReadExactError<Self::Error>>
buf
. Read more