Skip to main content

secure_serial/
transport.rs

1//! Traits for byte I/O and CRC computation used by [`crate::run_read`] and [`crate::run_write`].
2//!
3//! Implement these for your UART driver, USB bulk endpoint, or a host-side test double.
4
5/// Async byte input: fills `data` and returns how many bytes were read.
6pub trait TransportRead {
7    type Error;
8    async fn read(&mut self, data: &mut [u8]) -> Result<usize, Self::Error>;
9}
10
11/// Async byte output: writes the full slice (implementations may fragment internally).
12pub trait TransportWrite {
13    type Error;
14    async fn write(&mut self, data: &[u8]) -> Result<(), Self::Error>;
15}
16
17/// CRC over the bytes that precede the 4-byte little-endian CRC trailer on the wire.
18pub trait CrcDevice {
19    async fn crc(&mut self, data: &[u8]) -> u32;
20}