diff options
author | Emilia Kasper <emilia@openssl.org> | 2015-10-01 13:54:11 +0200 |
---|---|---|
committer | Emilia Kasper <emilia@openssl.org> | 2015-10-05 19:03:52 +0200 |
commit | 67202973cf55eaac021706c183377b8040cf0c20 (patch) | |
tree | ff46f093352c40560a72395dd56015ac944b4daa /ssl/packet_locl.h | |
parent | bf0fc41266f17311c5db1e0541d3dd12eb27deb6 (diff) |
Add PACKET_copy_all
Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'ssl/packet_locl.h')
-rw-r--r-- | ssl/packet_locl.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/ssl/packet_locl.h b/ssl/packet_locl.h index b13aa5a5c0..e73eb3dba2 100644 --- a/ssl/packet_locl.h +++ b/ssl/packet_locl.h @@ -301,7 +301,7 @@ __owur static inline int PACKET_get_4(PACKET *pkt, unsigned long *data) * underlying buffer gets freed */ __owur static inline int PACKET_peek_bytes(const PACKET *pkt, unsigned char **data, - size_t len) + size_t len) { if (PACKET_remaining(pkt) < len) return 0; @@ -356,6 +356,24 @@ __owur static inline int PACKET_copy_bytes(PACKET *pkt, unsigned char *data, } /* + * Copy packet data to |dest|, and set |len| to the number of copied bytes. + * If the packet has more than |dest_len| bytes, nothing is copied. + * Returns 1 if the packet data fits in |dest_len| bytes, 0 otherwise. + * Does not forward PACKET position (because it is typically the last thing + * done with a given PACKET). + */ +__owur static inline int PACKET_copy_all(const PACKET *pkt, unsigned char *dest, + size_t dest_len, size_t *len) { + if (PACKET_remaining(pkt) > dest_len) { + *len = 0; + return 0; + } + *len = pkt->remaining; + memcpy(dest, pkt->curr, pkt->remaining); + return 1; +} + +/* * Copy |pkt| bytes to a newly allocated buffer and store a pointer to the * result in |*data|, and the length in |len|. * If |*data| is not NULL, the old data is OPENSSL_free'd. |