#pragma once #include #include #include #include "secsgem/hsms/header.hpp" namespace secsgem::hsms { class FrameError : public std::runtime_error { public: using std::runtime_error::runtime_error; }; // One HSMS message: a header plus an optional SECS-II body (control messages // have no body). On the wire it is prefixed by a 4-byte big-endian length that // counts the header (10) plus the body. struct Frame { Header header; std::vector body; Frame() = default; explicit Frame(Header h, std::vector b = {}) : header(h), body(std::move(b)) {} // Full wire bytes including the 4-byte length prefix. std::vector encode() const; // Decode a message from its payload (header + body, i.e. the bytes that // follow the length prefix). `len` must be >= 10. static Frame decode(const uint8_t* payload, std::size_t len); }; // HSMS message length prefix is 4 bytes; payload must be at least the 10-byte // header. inline constexpr std::size_t kLengthPrefixSize = 4; inline constexpr std::size_t kHeaderSize = 10; } // namespace secsgem::hsms