49 [[nodiscard]]
const std::string&
server_name() const noexcept {
54 enum class State { ExpectServerHello, ExpectHandshake, Ready,
Failed };
58 void handle_server_hello(ByteView payload);
59 void handle_server_handshake(ByteView payload);
60 void report_error(
const std::string& what);
63 std::string expected_name_;
64 std::string server_name_;
66 noise::NoiseHandshake handshake_;
67 noise::CipherState encrypt_;
68 noise::CipherState decrypt_;
69 State state_ = State::ExpectServerHello;
75 std::size_t consumed_ = 0;
Byte buffer / view aliases and protobuf base-128 varint codec.
Noise CipherState: a keyed AEAD with an incrementing nonce.
Non-owning view over a contiguous run of bytes (a C++17 stand-in for std::span<const std::uint8_t>).
Definition bytes.hpp:17
Stateful codec sitting between the transport and the connection.
Definition frame_helper.hpp:30
std::function< void()> HandshakeReady
Definition frame_helper.hpp:58
std::function< void(const std::string &what)> HandshakeError
Definition frame_helper.hpp:59
Encrypted frame codec.
Definition noise_frame_helper.hpp:30
NoiseFrameHelper(const NoiseConfig &config)
Construct from config.
bool needs_handshake() const override
True if the transport requires a handshake before application messages (and before the connection sho...
Definition noise_frame_helper.hpp:43
const std::string & server_name() const noexcept
Definition noise_frame_helper.hpp:49
void feed(ByteView data) override
Append freshly received bytes to the internal reassembly buffer.
void set_handshake_handlers(HandshakeReady on_ready, HandshakeError on_error) override
Register callbacks fired when the handshake completes or fails.
ByteBuffer connect_bytes() override
Bytes to transmit immediately after the TCP connection is established (the client's first handshake f...
FrameStatus next(std::uint32_t &out_type, ByteView &out_payload) override
Try to extract the next complete frame.
void encode(std::uint32_t msg_type, ByteView payload, ByteBuffer &out) override
Serialize a message (numeric type id + protobuf payload) to wire bytes, appending them to out.
static constexpr std::uint8_t indicator
Indicator byte prefixing every Noise frame.
Definition noise_frame_helper.hpp:33
Abstract frame codec: turns a byte stream into ESPHome message frames and back, independent of the un...
std::array< std::uint8_t, key_len > SymmetricKey
Definition primitives.hpp:21
@ Failed
Terminated by an error.
FrameStatus
Result of attempting to pull a frame from the reassembly buffer.
Definition frame_helper.hpp:17
std::vector< std::uint8_t > ByteBuffer
Owning, growable byte buffer.
Definition bytes.hpp:13
Noise_NNpsk0_25519_ChaChaPoly_SHA256 handshake (initiator + responder).
Noise cryptographic primitives (SHA-256, HMAC, HKDF, X25519, ChaCha20- Poly1305, base64).
Configuration for an encrypted connection.
Definition noise_frame_helper.hpp:19
std::string expected_name
Optional expected device name, verified against the server hello.
Definition noise_frame_helper.hpp:23
std::string psk_base64
Base64-encoded 32-byte pre-shared key (the device's api.encryption.key).
Definition noise_frame_helper.hpp:21