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>
impl EspTls<InternalSocket>
sourcepub fn new() -> Result<Self, EspError>
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
sourcepub fn connect(
&mut self,
host: &str,
port: u16,
cfg: &Config<'_>,
) -> Result<CompletedHandshake, EspError>
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
ifcfg.alpn_protos
exceeds 9 elements or avg 10 bytes/ALPNESP_FAIL
if connection could not be establishedESP_TLS_ERR_SSL_WANT_READ
if the socket is in non-blocking mode and it is not ready for readingESP_TLS_ERR_SSL_WANT_WRITE
if the socket is in non-blocking mode and it is not ready for writingEWOULDBLOCK
if the socket is in non-blocking mode and it is not ready either for reading or writing (a peculiarity/bug of theesp-tls
C module)
source§impl<S> EspTls<S>where
S: Socket,
impl<S> EspTls<S>where
S: Socket,
sourcepub fn adopt(socket: S) -> Result<Self, EspError>
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
sourcepub fn negotiate(
&mut self,
host: &str,
cfg: &Config<'_>,
) -> Result<CompletedHandshake, EspError>
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
ifcfg.alpn_protos
exceeds 9 elements or avg 10 bytes/ALPNESP_FAIL
if connection could not be establishedESP_TLS_ERR_SSL_WANT_READ
if the socket is in non-blocking mode and it is not ready for readingESP_TLS_ERR_SSL_WANT_WRITE
if the socket is in non-blocking mode and it is not ready for writingEWOULDBLOCK
if the socket is in non-blocking mode and it is not ready either for reading or writing (a peculiarity/bug of theesp-tls
C module)
sourcepub fn read(&mut self, buf: &mut [u8]) -> Result<usize, EspError>
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 readingESP_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
sourcepub fn write(&mut self, buf: &[u8]) -> Result<usize, EspError>
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 readingESP_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
pub fn write_all(&mut self, buf: &[u8]) -> Result<(), EspError>
pub fn context_handle(&self) -> *mut esp_tls
Trait Implementations§
source§impl<S> ErrorType for EspTls<S>where
S: Socket,
impl<S> ErrorType for EspTls<S>where
S: Socket,
§type Error = EspIOError
type Error = EspIOError
Error type of all the IO operations on this type.
source§impl<S> Read for EspTls<S>where
S: Socket,
impl<S> Read for EspTls<S>where
S: Socket,
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, EspIOError>
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>>
fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
Read the exact number of bytes required to fill
buf
. Read moresource§impl<S> Write for EspTls<S>where
S: Socket,
impl<S> Write for EspTls<S>where
S: Socket,
source§fn write(&mut self, buf: &[u8]) -> Result<usize, EspIOError>
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>
fn flush(&mut self) -> Result<(), EspIOError>
Flush this output stream, blocking until all intermediately buffered contents reach their destination.