summaryrefslogtreecommitdiff
path: root/lib/libssl
diff options
context:
space:
mode:
authorDoug Hogan <doug@cvs.openbsd.org>2015-06-17 07:06:23 +0000
committerDoug Hogan <doug@cvs.openbsd.org>2015-06-17 07:06:23 +0000
commitf394691868c0818998edcf198a6828d70b1a72fa (patch)
tree7187a96a0ba2ee25b45f93409fa1ae5242699650 /lib/libssl
parent27802f19d5d169e85cb0a05eba8717066c076916 (diff)
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')
-rw-r--r--lib/libssl/src/ssl/bs_cbs.c16
-rw-r--r--lib/libssl/src/ssl/bytestring.h10
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/libssl/src/ssl/bs_cbs.c b/lib/libssl/src/ssl/bs_cbs.c
index 1368fe0fd7f..b36ba489f3a 100644
--- a/lib/libssl/src/ssl/bs_cbs.c
+++ b/lib/libssl/src/ssl/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;
diff --git a/lib/libssl/src/ssl/bytestring.h b/lib/libssl/src/ssl/bytestring.h
index 80ca00d77a4..2eb18e207dc 100644
--- a/lib/libssl/src/ssl/bytestring.h
+++ b/lib/libssl/src/ssl/bytestring.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bytestring.h,v 1.10 2015/06/17 07:00:22 doug Exp $ */
+/* $OpenBSD: bytestring.h,v 1.11 2015/06/17 07:06:22 doug Exp $ */
/*
* Copyright (c) 2014, Google Inc.
*
@@ -92,6 +92,14 @@ int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len);
int CBS_strdup(const CBS *cbs, char **out_ptr);
/*
+ * CBS_write_bytes writes all of the remaining data from |cbs| into |dst|
+ * if it is at most |dst_len| bytes. If |copied| is not NULL, it will be set
+ * to the amount copied. It returns one on success and zero otherwise.
+ */
+int CBS_write_bytes(const CBS *cbs, uint8_t *dst, size_t dst_len,
+ size_t *copied);
+
+/*
* CBS_contains_zero_byte returns one if the current contents of |cbs| contains
* a NUL byte and zero otherwise.
*/