Skip to main content

Sender

Struct Sender 

Source
pub struct Sender { /* private fields */ }
Available on crate feature rustcrypto only.
Expand description

The sending half: the two group counter spaces this node owns (§4.6.1).

A group message’s counter is free-running and rolls over (§4.6.5.2.2) — unlike a session’s, which must never repeat, because a group counter’s nonce is diversified by the Source Node ID as well.

Implementations§

Source§

impl Sender

Source

pub const fn new(node: NodeId, data: u32, control: u32) -> Self

A sender for node, with its two counters started where the caller says.

§4.6.1.1 has a node choose its initial counters at random on boot, so these come from Rng rather than from zero: starting at zero would make every message this node has ever sent replayable against a peer that had not heard from it since its last boot. Pass the random words as they come — MessageCounter::new narrows each to the range §4.6.1.1 specifies.

This is the factory-reset path. §4.6.1.3 randomises these two counters once, on a factory reset, and requires them to be persisted and never to roll back after that — so a node that has run before restores them with restore instead, and calling this on every boot would rewind them and reuse a nonce.

Source

pub const fn restore(node: NodeId, data: u32, control: u32) -> Self

A sender whose counters come from durable storage, at exactly the values given.

§4.6.1.3: “Nodes are required to persist the Global Group Encrypted Message Counters in durable storage. In particular, Nodes are required to ensure that the value of the Global Group Encrypted Message Counters never rolls back”. Unlike new these values are taken as they are: they are not a random seed, they are where this node actually was, and narrowing them to §4.6.1.1’s range would roll them back by up to 2³² and reuse every nonce since.

Persist ahead of where the counter stands, as §4.6.3 describes for the Check-In counter: a node that stores every value writes flash on every message, and one that stores the value it is at loses the writes it had not flushed when it lost power.

Source

pub const fn node(&self) -> NodeId

The node these messages say they are from.

Source

pub fn send( &mut self, key: &OperationalKey, group: GroupId, protocol_header: &ProtocolHeader, payload: &[u8], control: bool, scratch: &mut [u8], out: &mut [u8], ) -> Result<usize>

Builds one group message (§4.16.2).

scratch joins the protocol header and the payload for the AEAD, as on a unicast session; out takes the finished message, which the caller sends to multicast_address on PORT.

§4.16.2 step 2c: “The Security Flags SHALL have only the P Flag set” — a group message is always privacy-obfuscated, because the whole point of the address is that anyone on the link can see it.

Trait Implementations§

Source§

impl Debug for Sender

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Sender

§

impl Freeze for Sender

§

impl Move for Sender

§

impl RefUnwindSafe for Sender

§

impl Send for Sender

§

impl Sync for Sender

§

impl Unpin for Sender

§

impl UnsafeUnpin for Sender

§

impl UnwindSafe for Sender

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