Struct TlsSocket

Source
pub struct TlsSocket<'a, S: SocketState = NotReady> { /* private fields */ }
Expand description

A TLS socket. This is a wrapper around a TcpSocket that provides a TLS connection.

§Notes

For the Debug trait a dummy implementation is provided.

Implementations§

Source§

impl<'a> TlsSocket<'_>

Source

pub fn new( socket: TcpSocket<Connected>, record_read_buf: &'a mut [u8], record_write_buf: &'a mut [u8], ) -> TlsSocket<'a, NotReady>

Create a new TLS socket. This will create a new TLS connection using the provided TcpSocket.

§Parameters
  • socket: The TCP socket to use for the TLS connection
  • record_read_buf: A buffer to use for reading records
  • record_write_buf: A buffer to use for writing records
§Returns

A new TLS socket in the NotReady state. Use TlsSocket::open() to get a ready socket.

§Example
let mut read_buf = TlsSocket::new_buffer();
let mut write_buf = TlsSocket::new_buffer();
let tls_socket = TlsSocket::new(tcp_socket, &mut read_buf, &mut write_buf);
let tls_socket = tls_socket.open(&options)?;
§Notes

In most cases you can pass None for the cert parameter.

Source

pub fn new_buffer() -> [u8; 16384]

Create a new buffer. It is a utility function to create the read/write buffer to pass to Self::new().

§Returns

A new buffer of MAX_FRAGMENT_LENGTH (16_384) bytes.

§Example
let mut read_buf = TlsSocket::new_buffer();
let mut write_buf = TlsSocket::new_buffer();
let tls_socket = TlsSocket::new(tcp_socket, &mut read_buf, &mut write_buf);
Source§

impl TlsSocket<'_, Ready>

Source

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

Write all data to the TLS connection.

Writes until all data is written or an error occurs.

§Parameters
  • buf: The buffer containing the data to be sent.
§Returns
  • Ok(()) if the write was successful.
  • Err(TlsError) if the write was unsuccessful.
§Errors

embedded_tls::TlsError if the write fails.

Source

pub fn read_string(&mut self) -> Result<String, TlsError>

Read data from the TLS connection and converts it to a String.

§Returns
  • Ok(String) if the read was successful.
  • Err(TlsError) if the read was unsuccessful.
§Errors

embedded_tls::TlsError if the read fails.

Trait Implementations§

Source§

impl Debug for TlsSocket<'_>

Source§

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

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

impl<S: SocketState> ErrorType for TlsSocket<'_, S>

Source§

type Error = TlsError

The error type for the TLS socket.

Source§

impl<'a, 'b> Open<'a, 'b> for TlsSocket<'b, NotReady>
where 'a: 'b,

Source§

fn open(self, options: &'b Self::Options<'_>) -> Result<Self::Return, TlsError>
where 'b: 'a,

Open the TLS connection.

§Parameters
§Returns

A new TlsSocket<Ready>, or an error if opening fails.

§Example
let tls_socket = TlsSocket::new(tcp_socket, &mut read_buf, &mut write_buf);
let tls_socket = tls_socket.open(&options)?;
§Notes

The function takes ownership of the socket (TcpSocket<NotReady>), and returns a new socket of type TlsSocket<Ready>. Therefore, you must assign the returned socket to a variable in order to use it.

Source§

type Return = TlsSocket<'a, Ready>

Source§

impl<S: SocketState> OptionType for TlsSocket<'_, S>

Source§

type Options<'b> = TlsSocketOptions<'b>

The options type for the TLS socket.

Source§

impl Read for TlsSocket<'_, Ready>

Source§

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

Read data from the TLS connection.

§Parameters
  • buf: The buffer where the data will be stored.
§Returns
  • Ok(usize) if the read was successful. The number of bytes read
  • Err(SocketError) if the read was unsuccessful.
Source§

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 Write for TlsSocket<'_, Ready>

Source§

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

Write data to the TLS connection.

§Parameters
  • buf: The buffer containing the data to be sent.
§Returns
  • Ok(usize) if the write was successful. The number of bytes written
  • Err(SocketError) if the write was unsuccessful.
Source§

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

Flush the TLS connection.

Source§

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

Write an entire buffer into this writer. Read more
Source§

fn write_fmt( &mut self, fmt: Arguments<'_>, ) -> Result<(), WriteFmtError<Self::Error>>

Write a formatted string into this writer, returning any error encountered. Read more
Source§

impl EasySocket for TlsSocket<'_, Ready>

Auto Trait Implementations§

§

impl<'a, S> Freeze for TlsSocket<'a, S>

§

impl<'a, S> RefUnwindSafe for TlsSocket<'a, S>
where S: RefUnwindSafe,

§

impl<'a, S = NotReady> !Send for TlsSocket<'a, S>

§

impl<'a, S = NotReady> !Sync for TlsSocket<'a, S>

§

impl<'a, S> Unpin for TlsSocket<'a, S>
where S: Unpin,

§

impl<'a, S = NotReady> !UnwindSafe for TlsSocket<'a, S>

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V