pub struct TlsSocket<'a, S: SocketState = NotReady> { /* private fields */ }
Expand description
Implementations§
Source§impl<'a> TlsSocket<'_>
impl<'a> TlsSocket<'_>
Sourcepub fn new(
socket: TcpSocket<Connected>,
record_read_buf: &'a mut [u8],
record_write_buf: &'a mut [u8],
) -> TlsSocket<'a, NotReady>
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 connectionrecord_read_buf
: A buffer to use for reading recordsrecord_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.
Sourcepub fn new_buffer() -> [u8; 16384]
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>
impl TlsSocket<'_, Ready>
Sourcepub fn write_all(&mut self, buf: &[u8]) -> Result<(), TlsError>
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.
Sourcepub fn read_string(&mut self) -> Result<String, TlsError>
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<S: SocketState> ErrorType for TlsSocket<'_, S>
impl<S: SocketState> ErrorType for TlsSocket<'_, S>
Source§impl<'a, 'b> Open<'a, 'b> for TlsSocket<'b, NotReady>where
'a: 'b,
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,
fn open(self, options: &'b Self::Options<'_>) -> Result<Self::Return, TlsError>where
'b: 'a,
Open the TLS connection.
§Parameters
options
: The TLS options, of typeTlsSocketOptions
.
§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.
type Return = TlsSocket<'a, Ready>
Source§impl<S: SocketState> OptionType for TlsSocket<'_, S>
impl<S: SocketState> OptionType for TlsSocket<'_, S>
Source§type Options<'b> = TlsSocketOptions<'b>
type Options<'b> = TlsSocketOptions<'b>
The options type for the TLS socket.