pub struct BroadcastKey(/* private fields */);Expand description
A 32-byte ChaCha20-Poly1305 key for decrypting encrypted broadcast
notifications. Zeroized on drop; its Debug is redacted.
Implementations§
Source§impl BroadcastKey
impl BroadcastKey
Sourcepub fn derive(ikm: &[u8], salt: &[u8]) -> Result<Self>
pub fn derive(ikm: &[u8], salt: &[u8]) -> Result<Self>
Derive the broadcast key via HKDF-SHA512, info "Broadcast-Encryption-Key".
ikm is the Pair-Verify shared secret; salt the controller LTPK.
§Errors
CryptoError on an HKDF length error (never for 32-byte output).
Sourcepub fn from_bytes(key: [u8; 32]) -> Self
pub fn from_bytes(key: [u8; 32]) -> Self
Wrap raw key bytes (restored from persisted broadcast state).
Sourcepub fn as_bytes(&self) -> &[u8; 32]
pub fn as_bytes(&self) -> &[u8; 32]
The raw key bytes, for caller persistence. Handle as a secret.
Sourcepub fn seal(
&self,
gsn: u16,
plaintext: &[u8],
advertising_id: &[u8; 6],
) -> Vec<u8> ⓘ
pub fn seal( &self, gsn: u16, plaintext: &[u8], advertising_id: &[u8; 6], ) -> Vec<u8> ⓘ
Encrypt plaintext into a broadcast payload ciphertext || tag[:4] for
gsn, binding the 6-byte advertising_id as AAD. Uses the HAP 4-byte
partial Poly1305 tag — the symmetric counterpart of BroadcastKey::open.
The returned Vec<u8> is ciphertext || 4-byte-tag, ready to append to a
0x11 advertisement after the advertising id. Primarily useful for tests
and tooling (an accessory seals; a controller opens).
Sourcepub fn open(
&self,
gsn: u16,
combined_text: &[u8],
advertising_id: &[u8; 6],
) -> Result<Vec<u8>>
pub fn open( &self, gsn: u16, combined_text: &[u8], advertising_id: &[u8; 6], ) -> Result<Vec<u8>>
Decrypt one encrypted broadcast payload combined_text (= ciphertext || tag[:4]) for gsn, binding the 6-byte advertising_id as AAD. Uses the
HAP 4-byte partial Poly1305 tag.
§Errors
CryptoError::Aead if the partial tag does not match (wrong
key/gsn/aad or tampered payload) or the input is too short.
Trait Implementations§
Source§impl Clone for BroadcastKey
impl Clone for BroadcastKey
Source§fn clone(&self) -> BroadcastKey
fn clone(&self) -> BroadcastKey
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more