Expand description
Data structures representing the messages going over the wire
This module contains de-/serialization of the protocol’s messages. Thats kind
of a lie, since no actual ser/de happens. Instead, the structures offer views
into mutable byte slices (&mut [u8]
), allowing to modify the fields of an
always serialized instance of the data in question. This is closely related
to the concept of lenses in function programming; more on that here:
https://sinusoid.es/misc/lager/lenses.pdf
§Example
The following example uses the data_lense
macro to create a lense that
might be useful when dealing with UDP headers.
use rosenpass::{data_lense, RosenpassError, msgs::LenseView};
data_lense! {UdpDatagramHeader :=
source_port: 2,
dest_port: 2,
length: 2,
checksum: 2
}
let mut buf = [0u8; 8];
// read-only lense, no check of size:
let lense = UdpDatagramHeader(&buf);
assert_eq!(lense.checksum(), &[0, 0]);
// mutable lense, runtime check of size
let mut lense = buf.as_mut().udp_datagram_header()?;
lense.source_port_mut().copy_from_slice(&53u16.to_be_bytes()); // some DNS, anyone?
// the original buffer is still available
assert_eq!(buf, [0, 53, 0, 0, 0, 0, 0, 0]);
// read-only lense, runtime check of size
let lense = buf.as_ref().udp_datagram_header()?;
assert_eq!(lense.source_port(), &[0, 53]);
Structs§
- A data lense to manipulate byte slices.
- A data lense to manipulate byte slices.
- A data lense to manipulate byte slices.
- A data lense to manipulate byte slices.
- A data lense to manipulate byte slices.
- A data lense to manipulate byte slices.
- A data lense to manipulate byte slices.
- A data lense to manipulate byte slices.
Enums§
- Recognized message types
Constants§
- Length in bytes of an encrypted Biscuit (cipher text)
- length in bytes of an unencrypted Biscuit (plain text)
- Size required to fit any message in binary form
Traits§
- Extension trait to allow checked creation of a lense over some byte slice that contains a Biscuit
- Extension trait to allow checked creation of a lense over some byte slice that contains a CookieReply
- Extension trait to allow checked creation of a lense over some byte slice that contains a DataMsg
- Extension trait to allow checked creation of a lense over some byte slice that contains a EmptyData
- Extension trait to allow checked creation of a lense over some byte slice that contains a Envelope
- Extension trait to allow checked creation of a lense over some byte slice that contains a InitConf
- Extension trait to allow checked creation of a lense over some byte slice that contains a InitHello
- Common trait shared by all Lenses
- Extension trait to allow checked creation of a lense over some byte slice that contains a RespHello