49 const uint8_t expected[] = { 0x00, 0x01, 0x00, 0x02, 0x00, 0x01 };
50 assert_int_equal(
BLEN(&buf),
sizeof(expected));
51 assert_memory_equal(
BPTR(&buf), expected,
sizeof(expected));
56 assert_int_equal(
BPTR(&buf)[0], 0x80);
57 assert_int_equal(
BPTR(&buf)[1], 0x01);
71 assert_int_equal(
BLEN(&buf), 4);
75 assert_int_equal(hdr.
type, 0x1234);
102 assert_int_equal(
BLEN(&value), 2);
106 assert_int_equal(hdr.
type, 0x7ff);
108 assert_int_equal(
BLEN(&value), 4);
109 assert_int_equal(
buf_read_u32(&value, NULL), 0x11223344);
112 assert_int_equal(hdr.
type, 0x5);
113 assert_int_equal(
BLEN(&value), 0);
115 assert_int_equal(
BLEN(&buf), 0);
146 const uint8_t bytes[] = { 0x00, 0x01, 0x00 };
150 for (
size_t n = 0; n <=
sizeof(bytes); n++)
159 assert_int_equal(
BLEN(&buf), n);
173 assert_int_equal(
BLEN(&buf), 0);
178 assert_int_equal(
BLEN(&buf), 0);
void buf_clear(struct buffer *buf)
Zeroise and reset a buffer.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
#define BPTR(buf)
Return a pointer to the start of the buffer content.
static bool buf_write_u32(struct buffer *dest, uint32_t data)
Append a uint32_t to a buffer in network byte order.
static int buf_read_u16(struct buffer *buf)
Read and consume a uint16_t from the front of a buffer.
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Append data to a buffer.
#define BLEN(buf)
Return the length of the buffer content in bytes.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
static uint32_t buf_read_u32(struct buffer *buf, bool *good)
Read and consume a uint32_t from the front of a buffer.
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
bool ctrl_msg_tlv_write_u16(struct buffer *buf, uint16_t type, bool optional, uint16_t value)
Write a complete TLV whose value is a single 16-bit integer to buf.
bool ctrl_msg_tlv_peek_header(const struct buffer *buf, struct ctrl_msg_tlv_header *hdr)
Read a TLV header from buf without consuming it.
bool ctrl_msg_tlv_write_header(struct buffer *buf, uint16_t type, bool optional, uint16_t value_len)
Write a TLV header (type + optional flag + value length) to buf.
bool ctrl_msg_tlv_next(struct buffer *buf, struct ctrl_msg_tlv_header *hdr, struct buffer *value)
Read the next TLV from buf, advancing past its header and value.
TLV framing shared by the TLV-based control messages of the wire protocol.
#define TLV_TYPE_EARLY_NEG_FLAGS
#define CTRL_MSG_TLV_HEADER_LEN
SSL control channel wrap/unwrap and decode functions.
#define EARLY_NEG_FLAG_RESEND_WKC
Wrapper structure for dynamically allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
void test_tlv_header_roundtrip(void **state)
void test_tlv_header_truncated(void **state)
void test_tlv_next_value_truncated(void **state)
void test_tlv_write_u16_wire_format(void **state)
void test_tlv_write_no_room(void **state)
void test_tlv_next_walks_payload(void **state)