Skip to main content

Header

Struct Header 

Source
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: u64

The key id (KID).

§ctr: u64

The counter (CTR).

Implementations§

Source§

impl Header

Source

pub const fn new(kid: u64, ctr: u64) -> Self

A header with these values.

Source

pub const fn encoded_len(&self) -> usize

The length in bytes of this header’s encoding: 1 to 17.

Source

pub fn encode(&self, out: &mut [u8; 17]) -> usize

Writes the header’s (minimal) encoding at the start of out and returns its length.

Source

pub fn encode_to(&self, out: &mut Vec<u8>)

Appends the header’s encoding to out.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Header

Source§

impl Debug for Header

Source§

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

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

impl Eq for Header

Source§

impl Hash for Header

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Header

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

§

impl Forget for Header

§

impl Freeze for Header

§

impl Move for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnsafeUnpin for Header

§

impl UnwindSafe for Header

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.