From b2b3024e0eef58589f7a49ebd48da98d4564a348 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Tue, 13 Sep 2016 11:32:52 +0100 Subject: Add a WPACKET_sub_allocate_bytes() function Updated the construction code to use the new function. Also added some convenience macros for WPACKET_sub_memcpy(). Reviewed-by: Rich Salz --- ssl/packet_locl.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'ssl/packet_locl.h') diff --git a/ssl/packet_locl.h b/ssl/packet_locl.h index daef69e30e..6f16a7aaf1 100644 --- a/ssl/packet_locl.h +++ b/ssl/packet_locl.h @@ -674,6 +674,27 @@ int WPACKET_start_sub_packet(WPACKET *pkt); int WPACKET_allocate_bytes(WPACKET *pkt, size_t bytes, unsigned char **allocbytes); +/* + * The same as WPACKET_allocate_bytes() except additionally a new sub-packet is + * started for the allocated bytes, and then closed immediately afterwards. The + * number of length bytes for the sub-packet is in |lenbytes|. + */ +int WPACKET_sub_allocate_bytes(WPACKET *pkt, size_t len, + unsigned char **allocbytes, size_t lenbytes); + +/* + * Convenience macros for calling WPACKET_sub_allocate_bytes with different + * lengths + */ +#define WPACKET_sub_allocate_bytes_u8(pkt, len, bytes) \ + WPACKET_sub_allocate_bytes((pkt), (len), (bytes), 1) +#define WPACKET_sub_allocate_bytes_u16(pkt, len, bytes) \ + WPACKET_sub_allocate_bytes((pkt), (len), (bytes), 2) +#define WPACKET_sub_allocate_bytes_u24(pkt, len, bytes) \ + WPACKET_sub_allocate_bytes((pkt), (len), (bytes), 3) +#define WPACKET_sub_allocate_bytes_u32(pkt, len, bytes) \ + WPACKET_sub_allocate_bytes((pkt), (len), (bytes), 4) + /* * Write the value stored in |val| into the WPACKET. The value will consume * |bytes| amount of storage. An error will occur if |val| cannot be @@ -695,6 +716,16 @@ int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len); int WPACKET_sub_memcpy(WPACKET *pkt, const void *src, size_t len, size_t lenbytes); +/* Convenience macros for calling WPACKET_sub_memcpy with different lengths */ +#define WPACKET_sub_memcpy_u8(pkt, src, len) \ + WPACKET_sub_memcpy((pkt), (src), (len), 1) +#define WPACKET_sub_memcpy_u16(pkt, src, len) \ + WPACKET_sub_memcpy((pkt), (src), (len), 2) +#define WPACKET_sub_memcpy_bytes_u24(pkt, src, len) \ + WPACKET_sub_memcpy((pkt), (src), (len), 3) +#define WPACKET_sub_memcpy_bytes_u32(pkt, src, len) \ + WPACKET_sub_memcpy((pkt), (src), (len), 4) + /* * Return the total number of bytes written so far to the underlying buffer * including any storage allocated for length bytes -- cgit v1.2.3