10#include "noise/protocol.h"
19class ProtoWriteBuffer;
84 template<
typename StateEnum>
86 const std::string &info, StateEnum &
state, StateEnum failed_state);
96 :
socket_(std::move(socket)),
ctx_(std::move(ctx)) {
112 return this->
socket_->getpeername(addr, addrlen);
115 APIError shutdown(
int how)
override;
153 std::shared_ptr<APINoiseContext>
ctx_;
172#ifdef USE_API_PLAINTEXT
191 return this->
socket_->getpeername(addr, addrlen);
194 APIError shutdown(
int how)
override;
virtual uint8_t frame_footer_size()=0
APIError write_raw_(const struct iovec *iov, int iovcnt, socket::Socket *socket, std::vector< uint8_t > &tx_buf, const std::string &info, StateEnum &state, StateEnum failed_state)
virtual APIError read_packet(ReadPacketBuffer *buffer)=0
virtual APIError close()=0
virtual bool can_write_without_blocking()=0
virtual APIError loop()=0
virtual std::string getpeername()=0
uint8_t frame_header_padding_
virtual APIError init()=0
uint8_t frame_footer_size_
virtual uint8_t frame_header_padding()=0
virtual APIError shutdown(int how)=0
virtual APIError write_protobuf_packet(uint16_t type, ProtoWriteBuffer buffer)=0
virtual ~APIFrameHelper()=default
virtual int getpeername(struct sockaddr *addr, socklen_t *addrlen)=0
virtual void set_log_info(std::string info)=0
APIError write_protobuf_packet(uint16_t type, ProtoWriteBuffer buffer) override
NoiseCipherState * send_cipher_
APIError read_packet(ReadPacketBuffer *buffer) override
NoiseCipherState * recv_cipher_
APIError try_read_frame_(ParsedFrame *frame)
Read a packet into the rx_buf_.
enum esphome::api::APINoiseFrameHelper::State state_
~APINoiseFrameHelper() override
std::vector< uint8_t > prologue_
APIError state_action_()
To be called from read/write methods.
APIError write_frame_(const uint8_t *data, size_t len)
bool can_write_without_blocking() override
APIError loop() override
Run through handshake messages (if in that phase)
std::vector< uint8_t > tx_buf_
NoiseHandshakeState * handshake_
APIError close() override
uint8_t rx_header_buf_[3]
uint8_t frame_header_padding() override
int getpeername(struct sockaddr *addr, socklen_t *addrlen) override
void set_log_info(std::string info) override
std::shared_ptr< APINoiseContext > ctx_
APIError write_raw_(const struct iovec *iov, int iovcnt)
APIError try_send_tx_buf_()
uint8_t frame_footer_size() override
APIError init() override
Initialize the frame helper, returns OK if successful.
std::unique_ptr< socket::Socket > socket_
std::string getpeername() override
APIError check_handshake_finished_()
void send_explicit_handshake_reject_(const std::string &reason)
size_t rx_header_buf_len_
APIError init_handshake_()
Initiate the data structures for the handshake.
std::vector< uint8_t > rx_buf_
APINoiseFrameHelper(std::unique_ptr< socket::Socket > socket, std::shared_ptr< APINoiseContext > ctx)
std::vector< uint8_t > rx_buf_
APIPlaintextFrameHelper(std::unique_ptr< socket::Socket > socket)
enum esphome::api::APIPlaintextFrameHelper::State state_
std::string getpeername() override
int getpeername(struct sockaddr *addr, socklen_t *addrlen) override
APIError init() override
Initialize the frame helper, returns OK if successful.
bool can_write_without_blocking() override
std::vector< uint8_t > tx_buf_
std::unique_ptr< socket::Socket > socket_
APIError loop() override
Not used for plaintext.
~APIPlaintextFrameHelper() override=default
uint8_t frame_header_padding() override
APIError try_send_tx_buf_()
APIError read_packet(ReadPacketBuffer *buffer) override
APIError write_protobuf_packet(uint16_t type, ProtoWriteBuffer buffer) override
uint8_t frame_footer_size() override
uint8_t rx_header_buf_pos_
uint8_t rx_header_buf_[5]
uint32_t rx_header_parsed_type_
APIError close() override
APIError try_read_frame_(ParsedFrame *frame)
Read a packet into the rx_buf_.
void set_log_info(std::string info) override
uint32_t rx_header_parsed_len_
APIError write_raw_(const struct iovec *iov, int iovcnt)
@ HANDSHAKESTATE_READ_FAILED
@ HANDSHAKESTATE_BAD_STATE
@ HANDSHAKESTATE_SPLIT_FAILED
@ BAD_HANDSHAKE_PACKET_LEN
@ BAD_HANDSHAKE_ERROR_BYTE
@ HANDSHAKESTATE_SETUP_FAILED
@ CIPHERSTATE_ENCRYPT_FAILED
@ CIPHERSTATE_DECRYPT_FAILED
@ HANDSHAKESTATE_WRITE_FAILED
const char * api_error_to_str(APIError err)
Providing packet encoding functions for exchanging data with a remote host.
std::vector< uint8_t > msg
std::vector< uint8_t > msg
const std::vector< uint8_t > container
std::vector< uint8_t > container