diff options
author | 2015-06-17 07:06:22 +0000 | |
---|---|---|
committer | 2015-06-17 07:06:22 +0000 | |
commit | df129122ce6763dc6b6d92685d7e6b0ba8918ea1 (patch) | |
tree | 0b90a1b8c06cf0fedbc4b64292a9324116b77a99 /lib/libssl/bs_cbs.c | |
parent | Add a new function CBS_offset() to report the current offset in the data. (diff) | |
download | wireguard-openbsd-df129122ce6763dc6b6d92685d7e6b0ba8918ea1.tar.xz wireguard-openbsd-df129122ce6763dc6b6d92685d7e6b0ba8918ea1.zip |
Add CBS_write_bytes() to copy the remaining CBS bytes to the caller.
This is a common operation when dealing with CBS.
ok miod@ jsing@
Diffstat (limited to 'lib/libssl/bs_cbs.c')
-rw-r--r-- | lib/libssl/bs_cbs.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/libssl/bs_cbs.c b/lib/libssl/bs_cbs.c index 1368fe0fd7f..b36ba489f3a 100644 --- a/lib/libssl/bs_cbs.c +++ b/lib/libssl/bs_cbs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbs.c,v 1.11 2015/06/17 07:00:22 doug Exp $ */ +/* $OpenBSD: bs_cbs.c,v 1.12 2015/06/17 07:06:22 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -96,6 +96,20 @@ CBS_strdup(const CBS *cbs, char **out_ptr) } int +CBS_write_bytes(const CBS *cbs, uint8_t *dst, size_t dst_len, size_t *copied) +{ + if (dst_len < cbs->len) + return 0; + + memmove(dst, cbs->data, cbs->len); + + if (copied != NULL) + *copied = cbs->len; + + return 1; +} + +int CBS_contains_zero_byte(const CBS *cbs) { return memchr(cbs->data, 0, cbs->len) != NULL; |