pub struct S2Manager { /* private fields */ }Expand description
Security 2 state for one node: keys, SPANs, MPANs and sequence numbers.
Implementations§
Source§impl S2Manager
impl S2Manager
Sourcepub fn new(own_node: u16, home_id: u32) -> Self
pub fn new(own_node: u16, home_id: u32) -> Self
A manager for own_node in network home_id, with no keys yet.
Sourcepub fn set_home(&mut self, own_node: u16, home_id: u32)
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.
Sourcepub fn set_network_key(&mut self, class: SecurityClass, key: &NetworkKey)
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).
Sourcepub fn has_key(&self, class: SecurityClass) -> bool
pub fn has_key(&self, class: SecurityClass) -> bool
Whether a key is installed for this class.
Sourcepub fn set_peer_classes(&mut self, peer: u16, classes: &[SecurityClass])
pub fn set_peer_classes(&mut self, peer: u16, classes: &[SecurityClass])
Records the classes a peer was granted (any order).
Sourcepub fn highest_class(&self, peer: u16) -> Option<SecurityClass>
pub fn highest_class(&self, peer: u16) -> Option<SecurityClass>
The highest S2 class a peer was granted.
Sourcepub fn forget_peer(&mut self, peer: u16)
pub fn forget_peer(&mut self, peer: u16)
Forgets a peer entirely (excluded or reset).
Sourcepub fn begin_bootstrap(&mut self, peer: u16, temp: DerivedKeys)
pub fn begin_bootstrap(&mut self, peer: u16, temp: DerivedKeys)
Starts using the temporary key with peer (a key exchange in progress).
Sourcepub fn end_bootstrap(&mut self, peer: u16)
pub fn end_bootstrap(&mut self, peer: u16)
Ends the key exchange with peer and drops its SPAN.
Sourcepub fn is_bootstrapping(&self, peer: u16) -> bool
pub fn is_bootstrapping(&self, peer: u16) -> bool
Whether a key exchange with peer is in progress.
Sourcepub fn reset_span(&mut self, peer: u16)
pub fn reset_span(&mut self, peer: u16)
Drops the SPAN with peer; the next exchange needs a nonce.
Sourcepub fn can_encrypt(&self, peer: u16) -> bool
pub fn can_encrypt(&self, peer: u16) -> bool
Whether a frame to peer can be encrypted right now (with the default key).
Sourcepub fn nonce_report(&mut self, peer: u16, mos: bool) -> Result<Vec<u8>, Error>
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.
Sourcepub fn nonce_report_mos(&mut self, peer: u16) -> Result<Vec<u8>, Error>
pub fn nonce_report_mos(&mut self, peer: u16) -> Result<Vec<u8>, Error>
Builds a Nonce Report that only flags MOS (no new REI).
Sourcepub fn handle_nonce_report(
&mut self,
peer: u16,
frame: &[u8],
) -> Result<NonceReport, Error>
pub fn handle_nonce_report( &mut self, peer: u16, frame: &[u8], ) -> Result<NonceReport, Error>
Handles a received Nonce Report (frame starts at 0x9F 0x02).
Sourcepub fn encrypt(
&mut self,
peer: u16,
command: &[u8],
opts: &EncryptOptions,
) -> Result<Vec<u8>, Error>
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.
Sourcepub fn decrypt(&mut self, peer: u16, frame: &[u8]) -> Result<Decrypted, Error>
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.
Sourcepub fn create_group(
&mut self,
group: u8,
class: SecurityClass,
) -> Result<(), Error>
pub fn create_group( &mut self, group: u8, class: SecurityClass, ) -> Result<(), Error>
Creates (or rotates) an own multicast group protected with class.
Sourcepub fn encrypt_multicast(
&mut self,
group: u8,
command: &[u8],
) -> Result<Vec<u8>, Error>
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).
Sourcepub fn decrypt_multicast(
&mut self,
peer: u16,
frame: &[u8],
) -> Result<Decrypted, Error>
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.