Skip to main content

BroadcastKey

Struct BroadcastKey 

Source
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

Source

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

Source

pub fn from_bytes(key: [u8; 32]) -> Self

Wrap raw key bytes (restored from persisted broadcast state).

Source

pub fn as_bytes(&self) -> &[u8; 32]

The raw key bytes, for caller persistence. Handle as a secret.

Source

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

Source

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

Source§

fn clone(&self) -> BroadcastKey

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
Source§

impl Debug for BroadcastKey

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for BroadcastKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Zeroize for BroadcastKey

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

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.