From 42fa457b97a5d7987713328a587adab14baf4559 Mon Sep 17 00:00:00 2001 From: doug Date: Fri, 19 Jun 2015 00:23:36 +0000 Subject: [PATCH] Add CBS_dup() to initialize a new CBS with the same values. This is useful for when you need to check the data ahead and then continue on from the same spot. input + ok jsing@ miod@ --- lib/libssl/bs_cbs.c | 8 +++++++- lib/libssl/bytestring.h | 8 +++++++- lib/libssl/src/ssl/bs_cbs.c | 8 +++++++- lib/libssl/src/ssl/bytestring.h | 8 +++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/libssl/bs_cbs.c b/lib/libssl/bs_cbs.c index 45c253cc4b4..81731772496 100644 --- a/lib/libssl/bs_cbs.c +++ b/lib/libssl/bs_cbs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbs.c,v 1.13 2015/06/17 07:25:56 doug Exp $ */ +/* $OpenBSD: bs_cbs.c,v 1.14 2015/06/19 00:23:36 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -32,6 +32,12 @@ CBS_init(CBS *cbs, const uint8_t *data, size_t len) cbs->len = len; } +void +CBS_dup(const CBS *cbs, CBS *out) +{ + CBS_init(out, CBS_data(cbs), CBS_len(cbs)); +} + static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) { diff --git a/lib/libssl/bytestring.h b/lib/libssl/bytestring.h index 4c9d4d88847..8ea84005b49 100644 --- a/lib/libssl/bytestring.h +++ b/lib/libssl/bytestring.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bytestring.h,v 1.13 2015/06/18 23:25:07 doug Exp $ */ +/* $OpenBSD: bytestring.h,v 1.14 2015/06/19 00:23:36 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -465,6 +465,12 @@ int CBB_add_u24(CBB *cbb, size_t value); int CBB_add_asn1_uint64(CBB *cbb, uint64_t value); #ifdef LIBRESSL_INTERNAL +/* + * CBS_dup sets |out| to point to cbs's |data| and |len|. It results in two + * CBS that point to the same buffer. + */ +void CBS_dup(const CBS *cbs, CBS *out); + /* * cbs_get_any_asn1_element sets |*out| to contain the next ASN.1 element from * |*cbs| (including header bytes) and advances |*cbs|. It sets |*out_tag| to diff --git a/lib/libssl/src/ssl/bs_cbs.c b/lib/libssl/src/ssl/bs_cbs.c index 45c253cc4b4..81731772496 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.13 2015/06/17 07:25:56 doug Exp $ */ +/* $OpenBSD: bs_cbs.c,v 1.14 2015/06/19 00:23:36 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -32,6 +32,12 @@ CBS_init(CBS *cbs, const uint8_t *data, size_t len) cbs->len = len; } +void +CBS_dup(const CBS *cbs, CBS *out) +{ + CBS_init(out, CBS_data(cbs), CBS_len(cbs)); +} + static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) { diff --git a/lib/libssl/src/ssl/bytestring.h b/lib/libssl/src/ssl/bytestring.h index 4c9d4d88847..8ea84005b49 100644 --- a/lib/libssl/src/ssl/bytestring.h +++ b/lib/libssl/src/ssl/bytestring.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bytestring.h,v 1.13 2015/06/18 23:25:07 doug Exp $ */ +/* $OpenBSD: bytestring.h,v 1.14 2015/06/19 00:23:36 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -465,6 +465,12 @@ int CBB_add_u24(CBB *cbb, size_t value); int CBB_add_asn1_uint64(CBB *cbb, uint64_t value); #ifdef LIBRESSL_INTERNAL +/* + * CBS_dup sets |out| to point to cbs's |data| and |len|. It results in two + * CBS that point to the same buffer. + */ +void CBS_dup(const CBS *cbs, CBS *out); + /* * cbs_get_any_asn1_element sets |*out| to contain the next ASN.1 element from * |*cbs| (including header bytes) and advances |*cbs|. It sets |*out_tag| to -- 2.20.1