diff options
author | Matt Caswell <matt@openssl.org> | 2016-09-13 11:32:52 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-09-14 00:02:34 +0100 |
commit | b2b3024e0eef58589f7a49ebd48da98d4564a348 (patch) | |
tree | 579578a6ae0230d93b2817e23a18e6aa3bc97f22 /ssl/packet_locl.h | |
parent | f1ec23c0bcc8ebb40331120b87a0e99f6823da67 (diff) |
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 <rsalz@openssl.org>
Diffstat (limited to 'ssl/packet_locl.h')
-rw-r--r-- | ssl/packet_locl.h | 31 |
1 files changed, 31 insertions, 0 deletions
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 @@ -675,6 +675,27 @@ 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 * accommodated in |bytes| storage, e.g. attempting to write the value 256 into @@ -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 |