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_MEMif 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_SIZEifcfg.alpn_protosexceeds 9 elements or avg 10 bytes/ALPNESP_FAILif connection could not be establishedESP_TLS_ERR_SSL_WANT_READif the socket is in non-blocking mode and it is not ready for readingESP_TLS_ERR_SSL_WANT_WRITEif the socket is in non-blocking mode and it is not ready for writingEWOULDBLOCKif the socket is in non-blocking mode and it is not ready either for reading or writing (a peculiarity/bug of theesp-tlsC 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_MEMif 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_SIZEifcfg.alpn_protosexceeds 9 elements or avg 10 bytes/ALPNESP_FAILif connection could not be establishedESP_TLS_ERR_SSL_WANT_READif the socket is in non-blocking mode and it is not ready for readingESP_TLS_ERR_SSL_WANT_WRITEif the socket is in non-blocking mode and it is not ready for writingEWOULDBLOCKif the socket is in non-blocking mode and it is not ready either for reading or writing (a peculiarity/bug of theesp-tlsC module)
Sourcepub fn negotiate_server(
&mut self,
cfg: &ServerConfig<'_>,
) -> Result<(), EspError>
pub fn negotiate_server( &mut self, cfg: &ServerConfig<'_>, ) -> Result<(), EspError>
Establish a TLS/SSL connection using the adopted connection, acting as the server.
This call is blocking. On ESP-IDF >= 5.5.0 the duration is bounded by
cfg.tls_handshake_timeout_ms (or the ESP-TLS default of 10 s when that
field is 0). When the caller cannot afford to stall, prefer
EspAsyncTls::negotiate_server, or drive a non-blocking socket manually
with negotiate_server_init + negotiate_server_continue
(both ESP-IDF >= 5.5.0).
§Errors
ESP_FAILif connection could not be established
Sourcepub fn negotiate_server_init(
&mut self,
cfg: &ServerConfig<'_>,
) -> Result<(), EspError>
pub fn negotiate_server_init( &mut self, cfg: &ServerConfig<'_>, ) -> Result<(), EspError>
Begin a server-side TLS handshake on an already-adopted socket.
Requires ESP-IDF >= 5.5.0 with mbedTLS. The socket should typically be
non-blocking. Complete the handshake by repeatedly calling
Self::negotiate_server_continue until it returns Ok(()).
Certificate material referenced by cfg must remain valid for the
duration of this call (mbedTLS parses it here).
§Errors
ESP_FAIL/ other ESP-TLS errors if session setup fails
Sourcepub fn negotiate_server_continue(&mut self) -> Result<(), EspError>
pub fn negotiate_server_continue(&mut self) -> Result<(), EspError>
Continue a server-side handshake started with Self::negotiate_server_init.
Requires ESP-IDF >= 5.5.0 with mbedTLS.
Returns Ok(()) once the handshake is complete and the session is
ready for read/write.
§Errors
ESP_TLS_ERR_SSL_WANT_READif the socket is in non-blocking mode and it is not ready for readingESP_TLS_ERR_SSL_WANT_WRITEif the socket is in non-blocking mode and it is not ready for writingESP_FAILif the handshake failed; drop the connection
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_READif the socket is in non-blocking mode and it is not ready for readingESP_TLS_ERR_SSL_WANT_WRITEif the socket is in non-blocking mode and it is not ready for writing- Any other
EspErrorfor 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_READif the socket is in non-blocking mode and it is not ready for readingESP_TLS_ERR_SSL_WANT_WRITEif the socket is in non-blocking mode and it is not ready for writing- Any other
EspErrorfor 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,
Source§type Error = EspIOError
type Error = EspIOError
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>
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>>
buf. Read more