summaryrefslogtreecommitdiff
path: root/lib/str.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-09-14 11:21:51 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2018-02-19 15:29:33 +0100
commitbfed35761541fdf734ef5a0cce82d41314271ba5 (patch)
tree800adf74d3548b794214d2b06d68ab3ccd23d638 /lib/str.c
parent350d950b02791268fb2af8ba261a8c5747d1e543 (diff)
downloadgnutls-bfed35761541fdf734ef5a0cce82d41314271ba5.tar.gz
str: added helper functions to read prefixed data with 8 or 16-bit headers
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'lib/str.c')
-rw-r--r--lib/str.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/str.c b/lib/str.c
index bb7b25b08d..17e4fe3b86 100644
--- a/lib/str.c
+++ b/lib/str.c
@@ -828,6 +828,68 @@ _gnutls_buffer_pop_datum_prefix(gnutls_buffer_st * buf,
}
int
+_gnutls_buffer_pop_datum_prefix16(gnutls_buffer_st * buf,
+ gnutls_datum_t * data)
+{
+ size_t size;
+
+ if (buf->length < 2) {
+ gnutls_assert();
+ return GNUTLS_E_PARSING_ERROR;
+ }
+
+ size = _gnutls_read_uint16(buf->data);
+
+ buf->data += 2;
+ buf->length -= 2;
+
+ if (size > 0) {
+ size_t osize = size;
+ _gnutls_buffer_pop_datum(buf, data, size);
+ if (osize != data->size) {
+ gnutls_assert();
+ return GNUTLS_E_PARSING_ERROR;
+ }
+ } else {
+ data->size = 0;
+ data->data = NULL;
+ }
+
+ return 0;
+}
+
+int
+_gnutls_buffer_pop_datum_prefix8(gnutls_buffer_st * buf,
+ gnutls_datum_t * data)
+{
+ size_t size;
+
+ if (buf->length < 1) {
+ gnutls_assert();
+ return GNUTLS_E_PARSING_ERROR;
+ }
+
+ size = buf->data[0];
+
+ buf->data++;
+ buf->length--;
+
+ if (size > 0) {
+ size_t osize = size;
+ _gnutls_buffer_pop_datum(buf, data, size);
+ if (osize != data->size) {
+ gnutls_assert();
+ return GNUTLS_E_PARSING_ERROR;
+ }
+ } else {
+ data->size = 0;
+ data->data = NULL;
+ }
+
+ return 0;
+}
+
+int
_gnutls_buffer_append_data_prefix(gnutls_buffer_st * buf,
int pfx_size, const void *data,
size_t data_size)