Struct w5500_tls::TlsWriter

source ·
pub struct TlsWriter<'w, 'ks, W5500: Registers> { /* private fields */ }
Expand description

Writer for a TLS application data record.

This implements the w5500-hl IO traits, Write and Seek.

Created by Client::writer.

This writes plaintext to the socket buffers. When Write::send is called the data in the socket buffers is encrypted, and has the appropriate headers and footers added.

Example

use w5500_tls::{
    Client, Event, TlsWriter,
    {
        hl::{io::Write, Hostname},
        ll::{
            net::{Ipv4Addr, SocketAddrV4},
            Sn,
        },
    },
};

static mut RX: [u8; 2048] = [0; 2048];

const DST: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 4), 8883);
const HOSTNAME: Hostname = Hostname::new_unwrapped("server.local");
const SRC_PORT: u16 = 1234;
const TLS_SN: Sn = Sn::Sn4;

let mut tls_client: Client<2048> = Client::new(
    TLS_SN,
    SRC_PORT,
    HOSTNAME,
    DST,
    b"mykeyidentity",
    &MY_KEY,
    unsafe { &mut RX },
);

// wait until the handshake has completed
// for demonstration purposes only, please do not actually do this
while tls_client.process(&mut w5500, &mut rng, monotonic_secs()) != Ok(Event::HandshakeFinished)
{
}

let mut writer: TlsWriter<_> = tls_client.writer(&mut w5500).unwrap();
writer.write_all(&[0xAA; 5])?;
writer.send()?;

Trait Implementations§

source§

impl<'w, 'ks, W5500: Debug + Registers> Debug for TlsWriter<'w, 'ks, W5500>

source§

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

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

impl<'w, 'ks, W5500> Format for TlsWriter<'w, 'ks, W5500>
where W5500: Format + Registers,

source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
source§

impl<'w, 'ks, W5500: Registers> Seek for TlsWriter<'w, 'ks, W5500>

source§

fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), HlError<E>>

Seek to an offset, in bytes, within the socket buffer. Read more
source§

fn rewind(&mut self)

Rewind to the beginning of the stream. Read more
source§

fn stream_len(&self) -> u16

Return the length of the stream, in bytes. Read more
source§

fn stream_position(&self) -> u16

Returns the current seek position from the start of the stream.
source§

fn remain(&self) -> u16

Remaining bytes in the socket buffer from the current seek position.
source§

impl<'w, 'ks, W5500: Registers> Write<<W5500 as Registers>::Error> for TlsWriter<'w, 'ks, W5500>

source§

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

Write data to the socket buffer, and return the number of bytes written.
source§

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

Writes all the data, returning Error::OutOfMemory if the size of buf exceeds the free memory available in the socket buffer. Read more
source§

fn send(self) -> Result<(), W5500::Error>

Send all data previously written with write and write_all. Read more

Auto Trait Implementations§

§

impl<'w, 'ks, W5500> RefUnwindSafe for TlsWriter<'w, 'ks, W5500>
where W5500: RefUnwindSafe,

§

impl<'w, 'ks, W5500> Send for TlsWriter<'w, 'ks, W5500>
where W5500: Send,

§

impl<'w, 'ks, W5500> Sync for TlsWriter<'w, 'ks, W5500>
where W5500: Sync,

§

impl<'w, 'ks, W5500> Unpin for TlsWriter<'w, 'ks, W5500>

§

impl<'w, 'ks, W5500> !UnwindSafe for TlsWriter<'w, 'ks, W5500>

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

§

type Output = T

Should always be Self
source§

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

§

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

§

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.