summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordoug <>2015-06-17 07:06:22 +0000
committerdoug <>2015-06-17 07:06:22 +0000
commit1a6ec4dba6f1322011c578d9ef1a3d4898ddfacd (patch)
tree93fbc20cc8335f820378205df913c380ea091808 /src/lib
parent7489a76f28fc9e40d91abd387e7e07cf8e913e7e (diff)
downloadopenbsd-1a6ec4dba6f1322011c578d9ef1a3d4898ddfacd.tar.gz
openbsd-1a6ec4dba6f1322011c578d9ef1a3d4898ddfacd.tar.bz2
openbsd-1a6ec4dba6f1322011c578d9ef1a3d4898ddfacd.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 'src/lib')
-rw-r--r--src/lib/libssl/bs_cbs.c16
-rw-r--r--src/lib/libssl/bytestring.h10
-rw-r--r--src/lib/libssl/src/ssl/bs_cbs.c16
-rw-r--r--src/lib/libssl/src/ssl/bytestring.h10
4 files changed, 48 insertions, 4 deletions
diff --git a/src/lib/libssl/bs_cbs.c b/src/lib/libssl/bs_cbs.c
index 1368fe0fd7..b36ba489f3 100644
--- a/src/lib/libssl/bs_cbs.c
+++ b/src/lib/libssl/bs_cbs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bs_cbs.c,v 1.11 2015/06/17 07:00:22 doug Exp $ */ 1/* $OpenBSD: bs_cbs.c,v 1.12 2015/06/17 07:06:22 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -96,6 +96,20 @@ CBS_strdup(const CBS *cbs, char **out_ptr)
96} 96}
97 97
98int 98int
99CBS_write_bytes(const CBS *cbs, uint8_t *dst, size_t dst_len, size_t *copied)
100{
101 if (dst_len < cbs->len)
102 return 0;
103
104 memmove(dst, cbs->data, cbs->len);
105
106 if (copied != NULL)
107 *copied = cbs->len;
108
109 return 1;
110}
111
112int
99CBS_contains_zero_byte(const CBS *cbs) 113CBS_contains_zero_byte(const CBS *cbs)
100{ 114{
101 return memchr(cbs->data, 0, cbs->len) != NULL; 115 return memchr(cbs->data, 0, cbs->len) != NULL;
diff --git a/src/lib/libssl/bytestring.h b/src/lib/libssl/bytestring.h
index 80ca00d77a..2eb18e207d 100644
--- a/src/lib/libssl/bytestring.h
+++ b/src/lib/libssl/bytestring.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bytestring.h,v 1.10 2015/06/17 07:00:22 doug Exp $ */ 1/* $OpenBSD: bytestring.h,v 1.11 2015/06/17 07:06:22 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -92,6 +92,14 @@ int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len);
92int CBS_strdup(const CBS *cbs, char **out_ptr); 92int CBS_strdup(const CBS *cbs, char **out_ptr);
93 93
94/* 94/*
95 * CBS_write_bytes writes all of the remaining data from |cbs| into |dst|
96 * if it is at most |dst_len| bytes. If |copied| is not NULL, it will be set
97 * to the amount copied. It returns one on success and zero otherwise.
98 */
99int CBS_write_bytes(const CBS *cbs, uint8_t *dst, size_t dst_len,
100 size_t *copied);
101
102/*
95 * CBS_contains_zero_byte returns one if the current contents of |cbs| contains 103 * CBS_contains_zero_byte returns one if the current contents of |cbs| contains
96 * a NUL byte and zero otherwise. 104 * a NUL byte and zero otherwise.
97 */ 105 */
diff --git a/src/lib/libssl/src/ssl/bs_cbs.c b/src/lib/libssl/src/ssl/bs_cbs.c
index 1368fe0fd7..b36ba489f3 100644
--- a/src/lib/libssl/src/ssl/bs_cbs.c
+++ b/src/lib/libssl/src/ssl/bs_cbs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bs_cbs.c,v 1.11 2015/06/17 07:00:22 doug Exp $ */ 1/* $OpenBSD: bs_cbs.c,v 1.12 2015/06/17 07:06:22 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -96,6 +96,20 @@ CBS_strdup(const CBS *cbs, char **out_ptr)
96} 96}
97 97
98int 98int
99CBS_write_bytes(const CBS *cbs, uint8_t *dst, size_t dst_len, size_t *copied)
100{
101 if (dst_len < cbs->len)
102 return 0;
103
104 memmove(dst, cbs->data, cbs->len);
105
106 if (copied != NULL)
107 *copied = cbs->len;
108
109 return 1;
110}
111
112int
99CBS_contains_zero_byte(const CBS *cbs) 113CBS_contains_zero_byte(const CBS *cbs)
100{ 114{
101 return memchr(cbs->data, 0, cbs->len) != NULL; 115 return memchr(cbs->data, 0, cbs->len) != NULL;
diff --git a/src/lib/libssl/src/ssl/bytestring.h b/src/lib/libssl/src/ssl/bytestring.h
index 80ca00d77a..2eb18e207d 100644
--- a/src/lib/libssl/src/ssl/bytestring.h
+++ b/src/lib/libssl/src/ssl/bytestring.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bytestring.h,v 1.10 2015/06/17 07:00:22 doug Exp $ */ 1/* $OpenBSD: bytestring.h,v 1.11 2015/06/17 07:06:22 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -92,6 +92,14 @@ int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len);
92int CBS_strdup(const CBS *cbs, char **out_ptr); 92int CBS_strdup(const CBS *cbs, char **out_ptr);
93 93
94/* 94/*
95 * CBS_write_bytes writes all of the remaining data from |cbs| into |dst|
96 * if it is at most |dst_len| bytes. If |copied| is not NULL, it will be set
97 * to the amount copied. It returns one on success and zero otherwise.
98 */
99int CBS_write_bytes(const CBS *cbs, uint8_t *dst, size_t dst_len,
100 size_t *copied);
101
102/*
95 * CBS_contains_zero_byte returns one if the current contents of |cbs| contains 103 * CBS_contains_zero_byte returns one if the current contents of |cbs| contains
96 * a NUL byte and zero otherwise. 104 * a NUL byte and zero otherwise.
97 */ 105 */