Struct esp_idf_svc::tls::EspTls

source ·
pub struct EspTls<S>
where S: Socket,
{ /* private fields */ }
Expand description

Wrapper for esp-tls module. Only supports synchronous operation for now.

Implementations§

source§

impl EspTls<InternalSocket>

source

pub fn new() -> Result<Self, EspError>

Create a new EspTls instance using internally-managed socket.

§Errors
  • ESP_ERR_NO_MEM if not enough memory to create the TLS connection
source

pub fn connect( &mut self, host: &str, port: u16, cfg: &Config<'_>, ) -> Result<CompletedHandshake, EspError>

Establish a TLS/SSL connection with the specified host and port, using an internally-managed socket.

§Errors
  • ESP_ERR_INVALID_SIZE if cfg.alpn_protos exceeds 9 elements or avg 10 bytes/ALPN
  • ESP_FAIL if connection could not be established
  • ESP_TLS_ERR_SSL_WANT_READ if the socket is in non-blocking mode and it is not ready for reading
  • ESP_TLS_ERR_SSL_WANT_WRITE if the socket is in non-blocking mode and it is not ready for writing
  • EWOULDBLOCK if the socket is in non-blocking mode and it is not ready either for reading or writing (a peculiarity/bug of the esp-tls C module)
source§

impl<S> EspTls<S>
where S: Socket,

source

pub fn adopt(socket: S) -> Result<Self, EspError>

Create a new EspTls instance adopting the supplied socket. The socket should be in a connected state.

§Errors
  • ESP_ERR_NO_MEM if not enough memory to create the TLS connection
source

pub fn negotiate( &mut self, host: &str, cfg: &Config<'_>, ) -> Result<CompletedHandshake, EspError>

Establish a TLS/SSL connection using the adopted socket.

§Errors
  • ESP_ERR_INVALID_SIZE if cfg.alpn_protos exceeds 9 elements or avg 10 bytes/ALPN
  • ESP_FAIL if connection could not be established
  • ESP_TLS_ERR_SSL_WANT_READ if the socket is in non-blocking mode and it is not ready for reading
  • ESP_TLS_ERR_SSL_WANT_WRITE if the socket is in non-blocking mode and it is not ready for writing
  • EWOULDBLOCK if the socket is in non-blocking mode and it is not ready either for reading or writing (a peculiarity/bug of the esp-tls C module)
source

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

Read in the supplied buffer. Returns the number of bytes read.

§Errors
  • ESP_TLS_ERR_SSL_WANT_READ if the socket is in non-blocking mode and it is not ready for reading
  • ESP_TLS_ERR_SSL_WANT_WRITE if the socket is in non-blocking mode and it is not ready for writing
  • Any other EspError for a general error
source

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

Write the supplied buffer. Returns the number of bytes written.

§Errors
  • ESP_TLS_ERR_SSL_WANT_READ if the socket is in non-blocking mode and it is not ready for reading
  • ESP_TLS_ERR_SSL_WANT_WRITE if the socket is in non-blocking mode and it is not ready for writing
  • Any other EspError for a general error
source

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

source

pub fn context_handle(&self) -> *mut esp_tls

Trait Implementations§

source§

impl<S> Drop for EspTls<S>
where S: Socket,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<S> ErrorType for EspTls<S>
where S: Socket,

§

type Error = EspIOError

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

impl<S> Read for EspTls<S>
where S: Socket,

source§

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

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
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<S> Write for EspTls<S>
where S: Socket,

source§

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

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

fn flush(&mut self) -> Result<(), EspIOError>

Flush this output stream, blocking until all intermediately buffered contents reach their destination.
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

Auto Trait Implementations§

§

impl<S> Freeze for EspTls<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for EspTls<S>
where S: RefUnwindSafe,

§

impl<S> !Send for EspTls<S>

§

impl<S> !Sync for EspTls<S>

§

impl<S> Unpin for EspTls<S>
where S: Unpin,

§

impl<S> UnwindSafe for EspTls<S>
where S: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

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

Performs the conversion.