Struct embedded_tls::TlsConnection
source · [−]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
sourceimpl<'a, Socket, CipherSuite> TlsConnection<'a, Socket, CipherSuite> where
Socket: AsyncRead + AsyncWrite + 'a,
CipherSuite: TlsCipherSuite + 'static,
impl<'a, Socket, CipherSuite> TlsConnection<'a, Socket, CipherSuite> where
Socket: AsyncRead + AsyncWrite + 'a,
CipherSuite: TlsCipherSuite + 'static,
sourcepub fn new(delegate: Socket, record_buf: &'a mut [u8]) -> Self
pub fn new(delegate: Socket, record_buf: &'a mut [u8]) -> Self
Create a new TLS connection with the provided context and a async I/O implementation
NOTE: The record buffer should be sized to fit an encrypted TLS record and the TLS handshake record. The maximum value of a TLS record is 16 kB, which should be a safe value to use.
sourcepub async fn open<'m, RNG: CryptoRng + RngCore + 'm, Clock: TlsClock + 'static, const CERT_SIZE: usize>(
&mut self,
context: TlsContext<'m, CipherSuite, RNG>
) -> Result<(), TlsError> where
'a: 'm,
pub async fn open<'m, RNG: CryptoRng + RngCore + 'm, Clock: TlsClock + 'static, const CERT_SIZE: usize>(
&mut self,
context: TlsContext<'m, CipherSuite, RNG>
) -> Result<(), TlsError> where
'a: 'm,
Open a TLS connection, performing the handshake with the configuration provided when creating the connection instance.
The handshake may support certificates up to CERT_SIZE.
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.
Returns the number of bytes written.
Trait Implementations
sourceimpl<'a, Socket, CipherSuite> Io for TlsConnection<'a, Socket, CipherSuite> where
Socket: AsyncRead + AsyncWrite + 'a,
CipherSuite: TlsCipherSuite + 'static,
impl<'a, Socket, CipherSuite> Io for TlsConnection<'a, Socket, CipherSuite> where
Socket: AsyncRead + AsyncWrite + 'a,
CipherSuite: TlsCipherSuite + 'static,
sourceimpl<'a, Socket, CipherSuite> Read for TlsConnection<'a, Socket, CipherSuite> where
Socket: AsyncRead + AsyncWrite + 'a,
CipherSuite: TlsCipherSuite + 'static,
impl<'a, Socket, CipherSuite> Read for TlsConnection<'a, Socket, CipherSuite> where
Socket: AsyncRead + AsyncWrite + 'a,
CipherSuite: TlsCipherSuite + 'static,
type ReadFuture<'m>
where
Self: 'm = impl Future<Output = Result<usize, <TlsConnection<'a, Socket, CipherSuite> as Io>::Error>>
type ReadFuture<'m>
where
Self: 'm = impl Future<Output = Result<usize, <TlsConnection<'a, Socket, CipherSuite> as Io>::Error>>
Future returned by read
.
sourcefn read<'m>(&'m mut self, buf: &'m mut [u8]) -> Self::ReadFuture<'m>
fn read<'m>(&'m mut self, buf: &'m mut [u8]) -> Self::ReadFuture<'m>
Pull some bytes from this source into the specified buffer, returning how many bytes were read.
sourcefn read_exact(
&'a mut self,
buf: &'a mut [u8]
) -> impl Future<Output = Result<(), ReadExactError<Self::Error>>>
fn read_exact(
&'a mut self,
buf: &'a mut [u8]
) -> impl Future<Output = Result<(), ReadExactError<Self::Error>>>
Read the exact number of bytes required to fill buf
.
sourceimpl<'a, Socket, CipherSuite> Write for TlsConnection<'a, Socket, CipherSuite> where
Socket: AsyncRead + AsyncWrite + 'a,
CipherSuite: TlsCipherSuite + 'static,
impl<'a, Socket, CipherSuite> Write for TlsConnection<'a, Socket, CipherSuite> where
Socket: AsyncRead + AsyncWrite + 'a,
CipherSuite: TlsCipherSuite + 'static,
type WriteFuture<'m>
where
Self: 'm = impl Future<Output = Result<usize, <TlsConnection<'a, Socket, CipherSuite> as Io>::Error>>
type WriteFuture<'m>
where
Self: 'm = impl Future<Output = Result<usize, <TlsConnection<'a, Socket, CipherSuite> as Io>::Error>>
Future returned by write
.
sourcefn write<'m>(&'m mut self, buf: &'m [u8]) -> Self::WriteFuture<'m>
fn write<'m>(&'m mut self, buf: &'m [u8]) -> Self::WriteFuture<'m>
Write a buffer into this writer, returning how many bytes were written.
type FlushFuture<'m>
where
Self: 'm = impl Future<Output = Result<(), <TlsConnection<'a, Socket, CipherSuite> as Io>::Error>>
type FlushFuture<'m>
where
Self: 'm = impl Future<Output = Result<(), <TlsConnection<'a, Socket, CipherSuite> as Io>::Error>>
Future returned by flush
.
sourcefn flush<'m>(&'m mut self) -> Self::FlushFuture<'m>
fn flush<'m>(&'m mut self) -> Self::FlushFuture<'m>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
Auto Trait Implementations
impl<'a, Socket, CipherSuite> RefUnwindSafe for TlsConnection<'a, Socket, CipherSuite> where
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,
<CipherSuite as TlsCipherSuite>::IvLen: RefUnwindSafe,
<CipherSuite as TlsCipherSuite>::KeyLen: RefUnwindSafe,
impl<'a, Socket, CipherSuite> Send for TlsConnection<'a, Socket, CipherSuite> where
Socket: Send,
<CipherSuite as TlsCipherSuite>::Hash: Send,
<CipherSuite as TlsCipherSuite>::IvLen: Send,
<CipherSuite as TlsCipherSuite>::KeyLen: Send,
impl<'a, Socket, CipherSuite> Sync for TlsConnection<'a, Socket, CipherSuite> where
Socket: Sync,
<CipherSuite as TlsCipherSuite>::Hash: Sync,
<CipherSuite as TlsCipherSuite>::IvLen: Sync,
<CipherSuite as TlsCipherSuite>::KeyLen: Sync,
impl<'a, Socket, CipherSuite> Unpin for TlsConnection<'a, Socket, CipherSuite> where
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,
<CipherSuite as TlsCipherSuite>::IvLen: Unpin,
<CipherSuite as TlsCipherSuite>::KeyLen: Unpin,
impl<'a, Socket, CipherSuite> !UnwindSafe for TlsConnection<'a, Socket, CipherSuite>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more