ESPHome 2026.8.0-dev
Loading...
Searching...
No Matches
api_noise_context.h
Go to the documentation of this file.
1#pragma once
2#include <array>
3#include <cstdint>
5
6namespace esphome::api {
7
8#ifdef USE_API_NOISE
9using psk_t = std::array<uint8_t, 32>;
10
12 public:
13 // The all-zeros PSK is reserved: it marks the device as unprovisioned and
14 // doubles as the well-known provisioning PSK that unprovisioned devices
15 // accept for Noise handshakes (passive-sniffing protection only, no
16 // authentication). It is never a valid real key.
17 static bool is_all_zeros(const psk_t &psk) {
18 uint8_t acc = 0;
19 for (uint8_t b : psk) {
20 acc |= b;
21 }
22 return acc == 0;
23 }
24 void set_psk(psk_t psk) {
25 this->psk_ = psk;
26 this->has_psk_ = !is_all_zeros(psk);
27 }
28 const psk_t &get_psk() const { return this->psk_; }
29 bool has_psk() const { return this->has_psk_; }
30
31 protected:
33 bool has_psk_{false};
34};
35#endif // USE_API_NOISE
36
37} // namespace esphome::api
static bool is_all_zeros(const psk_t &psk)
const psk_t & get_psk() const
std::array< uint8_t, 32 > psk_t