pub struct Header {
pub kid: u64,
pub ctr: u64,
}Expand description
An SFrame header (RFC 9605 section 4.3): the key id that selects the key and the counter the nonce is built from.
0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+------------+------------+
|X| K |Y| C | KID... | CTR... |
+-+-+-+-+-+-+-+-+------------+------------+A value below 8 is carried in the config byte (K or C, with X or Y clear). A larger
one follows the config byte as a big-endian integer in the fewest bytes that hold it, and
the field holds that length minus one.
Fields§
§kid: u64The key id (KID).
ctr: u64The counter (CTR).
Implementations§
Source§impl Header
impl Header
Sourcepub const fn encoded_len(&self) -> usize
pub const fn encoded_len(&self) -> usize
The length in bytes of this header’s encoding: 1 to 17.
Sourcepub fn encode(&self, out: &mut [u8; 17]) -> usize
pub fn encode(&self, out: &mut [u8; 17]) -> usize
Writes the header’s (minimal) encoding at the start of out and returns its length.
Sourcepub fn decode(data: &[u8]) -> Result<(Self, usize)>
pub fn decode(data: &[u8]) -> Result<(Self, usize)>
Parses the header at the start of data. Returns it with the number of bytes it takes;
the rest of data is the AEAD output.
A value that is not in its shortest form is refused with
Error::NonMinimalHeader: RFC 9605 requires the shortest form of a sender, so a
conforming one never produces anything else. decode_lenient
accepts such headers.
Sourcepub fn decode_lenient(data: &[u8]) -> Result<(Self, usize)>
pub fn decode_lenient(data: &[u8]) -> Result<(Self, usize)>
Parses the header at the start of data, also when a KID or CTR is longer than it needs
to be (an extended value below 8, or leading zero bytes).
Decryption authenticates the header bytes as they were received, so a re-encoded header never validates; accepting the longer forms only admits a sender that does not follow the encoding rule.