From 7489a76f28fc9e40d91abd387e7e07cf8e913e7e Mon Sep 17 00:00:00 2001 From: doug <> Date: Wed, 17 Jun 2015 07:00:22 +0000 Subject: Add a new function CBS_offset() to report the current offset in the data. "why not" miod@, sure jsing@ --- src/lib/libssl/bs_cbs.c | 9 ++++++++- src/lib/libssl/bytestring.h | 8 +++++++- src/lib/libssl/src/ssl/bs_cbs.c | 9 ++++++++- src/lib/libssl/src/ssl/bytestring.h | 8 +++++++- 4 files changed, 30 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib/libssl/bs_cbs.c b/src/lib/libssl/bs_cbs.c index 1b513c9a0e..1368fe0fd7 100644 --- a/src/lib/libssl/bs_cbs.c +++ b/src/lib/libssl/bs_cbs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbs.c,v 1.10 2015/06/16 06:11:39 doug Exp $ */ +/* $OpenBSD: bs_cbs.c,v 1.11 2015/06/17 07:00:22 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -28,6 +28,7 @@ void CBS_init(CBS *cbs, const uint8_t *data, size_t len) { cbs->data = data; + cbs->initial_len = len; cbs->len = len; } @@ -43,6 +44,12 @@ cbs_get(CBS *cbs, const uint8_t **p, size_t n) return 1; } +size_t +CBS_offset(const CBS *cbs) +{ + return cbs->initial_len - cbs->len; +} + int CBS_skip(CBS *cbs, size_t len) { diff --git a/src/lib/libssl/bytestring.h b/src/lib/libssl/bytestring.h index 07be6ddd50..80ca00d77a 100644 --- a/src/lib/libssl/bytestring.h +++ b/src/lib/libssl/bytestring.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bytestring.h,v 1.9 2015/06/16 06:37:58 doug Exp $ */ +/* $OpenBSD: bytestring.h,v 1.10 2015/06/17 07:00:22 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -40,6 +40,7 @@ extern "C" { /* CRYPTO ByteString */ typedef struct cbs_st { const uint8_t *data; + size_t initial_len; size_t len; } CBS; @@ -65,6 +66,11 @@ const uint8_t *CBS_data(const CBS *cbs); */ size_t CBS_len(const CBS *cbs); +/* + * CBS_offset returns the current offset into the original data of |cbs|. + */ +size_t CBS_offset(const CBS *cbs); + /* * CBS_stow copies the current contents of |cbs| into |*out_ptr| and * |*out_len|. If |*out_ptr| is not NULL, the contents are freed with diff --git a/src/lib/libssl/src/ssl/bs_cbs.c b/src/lib/libssl/src/ssl/bs_cbs.c index 1b513c9a0e..1368fe0fd7 100644 --- a/src/lib/libssl/src/ssl/bs_cbs.c +++ b/src/lib/libssl/src/ssl/bs_cbs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbs.c,v 1.10 2015/06/16 06:11:39 doug Exp $ */ +/* $OpenBSD: bs_cbs.c,v 1.11 2015/06/17 07:00:22 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -28,6 +28,7 @@ void CBS_init(CBS *cbs, const uint8_t *data, size_t len) { cbs->data = data; + cbs->initial_len = len; cbs->len = len; } @@ -43,6 +44,12 @@ cbs_get(CBS *cbs, const uint8_t **p, size_t n) return 1; } +size_t +CBS_offset(const CBS *cbs) +{ + return cbs->initial_len - cbs->len; +} + int CBS_skip(CBS *cbs, size_t len) { diff --git a/src/lib/libssl/src/ssl/bytestring.h b/src/lib/libssl/src/ssl/bytestring.h index 07be6ddd50..80ca00d77a 100644 --- a/src/lib/libssl/src/ssl/bytestring.h +++ b/src/lib/libssl/src/ssl/bytestring.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bytestring.h,v 1.9 2015/06/16 06:37:58 doug Exp $ */ +/* $OpenBSD: bytestring.h,v 1.10 2015/06/17 07:00:22 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -40,6 +40,7 @@ extern "C" { /* CRYPTO ByteString */ typedef struct cbs_st { const uint8_t *data; + size_t initial_len; size_t len; } CBS; @@ -65,6 +66,11 @@ const uint8_t *CBS_data(const CBS *cbs); */ size_t CBS_len(const CBS *cbs); +/* + * CBS_offset returns the current offset into the original data of |cbs|. + */ +size_t CBS_offset(const CBS *cbs); + /* * CBS_stow copies the current contents of |cbs| into |*out_ptr| and * |*out_len|. If |*out_ptr| is not NULL, the contents are freed with -- cgit v1.2.3-55-g6feb