ESPHome
2026.8.0-dev
Loading...
Searching...
No Matches
esphome
components
api
api_noise_context.h
Go to the documentation of this file.
1
#pragma once
2
#include <array>
3
#include <cstdint>
4
#include "
esphome/core/defines.h
"
5
6
namespace
esphome::api
{
7
8
#ifdef USE_API_NOISE
9
using
psk_t
= std::array<uint8_t, 32>;
10
11
class
APINoiseContext
{
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
:
32
psk_t
psk_
{};
33
bool
has_psk_
{
false
};
34
};
35
#endif
// USE_API_NOISE
36
37
}
// namespace esphome::api
esphome::api::APINoiseContext
Definition
api_noise_context.h:11
esphome::api::APINoiseContext::has_psk_
bool has_psk_
Definition
api_noise_context.h:33
esphome::api::APINoiseContext::is_all_zeros
static bool is_all_zeros(const psk_t &psk)
Definition
api_noise_context.h:17
esphome::api::APINoiseContext::psk_
psk_t psk_
Definition
api_noise_context.h:32
esphome::api::APINoiseContext::get_psk
const psk_t & get_psk() const
Definition
api_noise_context.h:28
esphome::api::APINoiseContext::set_psk
void set_psk(psk_t psk)
Definition
api_noise_context.h:24
esphome::api::APINoiseContext::has_psk
bool has_psk() const
Definition
api_noise_context.h:29
defines.h
esphome::api
Definition
api_buffer.cpp:3
esphome::api::psk_t
std::array< uint8_t, 32 > psk_t
Definition
api_noise_context.h:9
Generated by
1.12.0