From: jsing Date: Wed, 15 Dec 2021 17:23:34 +0000 (+0000) Subject: Provide CBS_get_last_u8(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a44c0c8f4154c33ce402045c98d32143fc466cfa;p=openbsd Provide CBS_get_last_u8(). This will be used in the TLSv1.3 record layer. From BoringSSL. ok tb@ --- diff --git a/lib/libssl/bs_cbs.c b/lib/libssl/bs_cbs.c index ab76b789272..627c609bb9e 100644 --- a/lib/libssl/bs_cbs.c +++ b/lib/libssl/bs_cbs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbs.c,v 1.21 2021/10/31 06:48:54 jsing Exp $ */ +/* $OpenBSD: bs_cbs.c,v 1.22 2021/12/15 17:23:34 jsing Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -190,6 +190,17 @@ CBS_get_u32(CBS *cbs, uint32_t *out) return cbs_get_u(cbs, out, 4); } +int +CBS_get_last_u8(CBS *cbs, uint8_t *out) +{ + if (cbs->len == 0) + return 0; + + *out = cbs->data[cbs->len - 1]; + cbs->len--; + return 1; +} + int CBS_get_bytes(CBS *cbs, CBS *out, size_t len) { diff --git a/lib/libssl/bytestring.h b/lib/libssl/bytestring.h index 9e55dd44d64..4ab2828d09f 100644 --- a/lib/libssl/bytestring.h +++ b/lib/libssl/bytestring.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bytestring.h,v 1.19 2021/05/16 10:58:27 jsing Exp $ */ +/* $OpenBSD: bytestring.h,v 1.20 2021/12/15 17:23:34 jsing Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -133,6 +133,12 @@ int CBS_get_u24(CBS *cbs, uint32_t *out); */ int CBS_get_u32(CBS *cbs, uint32_t *out); +/* + * CBS_get_last_u8 sets |*out| to the last uint8_t from |cbs| and shortens + * |cbs|. It returns one on success and zero on error. + */ +int CBS_get_last_u8(CBS *cbs, uint8_t *out); + /* * CBS_get_bytes sets |*out| to the next |len| bytes from |cbs| and advances * |cbs|. It returns one on success and zero on error.