Skip to main content

S2Manager

Struct S2Manager 

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

Security 2 state for one node: keys, SPANs, MPANs and sequence numbers.

Implementations§

Source§

impl S2Manager

Source

pub fn new(own_node: u16, home_id: u32) -> Self

A manager for own_node in network home_id, with no keys yet.

Source

pub fn set_home(&mut self, own_node: u16, home_id: u32)

Changes the own node id and home id (a node that was just included); drops every SPAN and MPAN.

Source

pub fn own_node(&self) -> u16

The own node id.

Source

pub fn home_id(&self) -> u32

The home id.

Source

pub fn set_network_key(&mut self, class: SecurityClass, key: &NetworkKey)

Installs the network key for a class (derives its CCM, nonce and MPAN keys).

Source

pub fn has_key(&self, class: SecurityClass) -> bool

Whether a key is installed for this class.

Source

pub fn set_peer_classes(&mut self, peer: u16, classes: &[SecurityClass])

Records the classes a peer was granted (any order).

Source

pub fn highest_class(&self, peer: u16) -> Option<SecurityClass>

The highest S2 class a peer was granted.

Source

pub fn forget_peer(&mut self, peer: u16)

Forgets a peer entirely (excluded or reset).

Source

pub fn begin_bootstrap(&mut self, peer: u16, temp: DerivedKeys)

Starts using the temporary key with peer (a key exchange in progress).

Source

pub fn end_bootstrap(&mut self, peer: u16)

Ends the key exchange with peer and drops its SPAN.

Source

pub fn is_bootstrapping(&self, peer: u16) -> bool

Whether a key exchange with peer is in progress.

Source

pub fn reset_span(&mut self, peer: u16)

Drops the SPAN with peer; the next exchange needs a nonce.

Source

pub fn can_encrypt(&self, peer: u16) -> bool

Whether a frame to peer can be encrypted right now (with the default key).

Source

pub fn nonce_get(&mut self, peer: u16) -> Result<Vec<u8>, Error>

Builds a Nonce Get for peer.

Source

pub fn nonce_report(&mut self, peer: u16, mos: bool) -> Result<Vec<u8>, Error>

Builds a Nonce Report with a fresh REI (SOS), optionally also flagging MOS. Any SPAN with the peer is replaced.

Source

pub fn nonce_report_mos(&mut self, peer: u16) -> Result<Vec<u8>, Error>

Builds a Nonce Report that only flags MOS (no new REI).

Source

pub fn handle_nonce_report( &mut self, peer: u16, frame: &[u8], ) -> Result<NonceReport, Error>

Handles a received Nonce Report (frame starts at 0x9F 0x02).

Source

pub fn encrypt( &mut self, peer: u16, command: &[u8], opts: &EncryptOptions, ) -> Result<Vec<u8>, Error>

Encrypts command (command class id first) for peer.

Fails with Error::NoSpan when no nonce is shared yet; send nonce_get, feed the answer to handle_nonce_report and retry.

Source

pub fn decrypt(&mut self, peer: u16, frame: &[u8]) -> Result<Decrypted, Error>

Decrypts a singlecast Message Encapsulation from peer (frame starts at 0x9F 0x03).

On Error::DecryptFailed or Error::NoSpan the caller answers with nonce_report so the peer resynchronizes.

Source

pub fn create_group( &mut self, group: u8, class: SecurityClass, ) -> Result<(), Error>

Creates (or rotates) an own multicast group protected with class.

Source

pub fn encrypt_multicast( &mut self, group: u8, command: &[u8], ) -> Result<Vec<u8>, Error>

Encrypts a multicast frame for an own group (MGRP extension, nonce from the MPAN).

Source

pub fn decrypt_multicast( &mut self, peer: u16, frame: &[u8], ) -> Result<Decrypted, Error>

Decrypts a multicast frame from peer for group using the MPAN the peer gave us.

On Error::NoSpan (no MPAN known) or Error::DecryptFailed, the caller answers with nonce_report_mos.

Trait Implementations§

Source§

impl Debug for S2Manager

Source§

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

Formats the value using the given formatter. 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> 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.