Skip to main content

StreamHmacState

Struct StreamHmacState 

Source
pub struct StreamHmacState { /* private fields */ }
Expand description

Chained HMAC state for stream block authentication, matching wire format.

Used by both server (StreamBuilder) and client (StreamMount).

§Wire format

  • Block 0: HMAC(key, topic.as_bytes() || capnp_data)[..16]
  • Block N: HMAC(key, prev_mac (16 bytes) || capnp_data)[..16]

Implementations§

Source§

impl StreamHmacState

Source

pub fn new(key: [u8; 32], topic: String) -> Self

Create new HMAC chain state.

Source

pub fn compute_next(&mut self, capnp_data: &[u8]) -> [u8; 16]

Compute 16-byte truncated MAC for next block, advancing the chain.

Source

pub fn verify_next(&mut self, capnp_data: &[u8], expected_mac: &[u8]) -> bool

Verify the next block’s MAC in constant time.

Advances the chain only if verification succeeds. Returns true if the MAC matches, false otherwise.

Source

pub fn topic(&self) -> &str

Get the topic.

Source

pub fn prev_mac_bytes(&self) -> &[u8] ⓘ

Get previous MAC bytes (for prevMac field in StreamBlock).

Trait Implementations§

Source§

impl Clone for StreamHmacState

Source§

fn clone(&self) -> StreamHmacState

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

Auto Trait Implementations§

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

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.