diff options
author | jsing <> | 2021-12-15 17:23:34 +0000 |
---|---|---|
committer | jsing <> | 2021-12-15 17:23:34 +0000 |
commit | 4d85c2eaad13fb1a929709a9c386d1179d1f4ac1 (patch) | |
tree | 4268f164866dbe30538093c2d1708dd0a9315cf5 | |
parent | bddefd5542d7d38c376d4fb8c063be5fed4372b6 (diff) | |
download | openbsd-4d85c2eaad13fb1a929709a9c386d1179d1f4ac1.tar.gz openbsd-4d85c2eaad13fb1a929709a9c386d1179d1f4ac1.tar.bz2 openbsd-4d85c2eaad13fb1a929709a9c386d1179d1f4ac1.zip |
Provide CBS_get_last_u8().
This will be used in the TLSv1.3 record layer.
From BoringSSL.
ok tb@
-rw-r--r-- | src/lib/libssl/bs_cbs.c | 13 | ||||
-rw-r--r-- | src/lib/libssl/bytestring.h | 8 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/lib/libssl/bs_cbs.c b/src/lib/libssl/bs_cbs.c index ab76b78927..627c609bb9 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.21 2021/10/31 06:48:54 jsing Exp $ */ | 1 | /* $OpenBSD: bs_cbs.c,v 1.22 2021/12/15 17:23:34 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014, Google Inc. | 3 | * Copyright (c) 2014, Google Inc. |
4 | * | 4 | * |
@@ -191,6 +191,17 @@ CBS_get_u32(CBS *cbs, uint32_t *out) | |||
191 | } | 191 | } |
192 | 192 | ||
193 | int | 193 | int |
194 | CBS_get_last_u8(CBS *cbs, uint8_t *out) | ||
195 | { | ||
196 | if (cbs->len == 0) | ||
197 | return 0; | ||
198 | |||
199 | *out = cbs->data[cbs->len - 1]; | ||
200 | cbs->len--; | ||
201 | return 1; | ||
202 | } | ||
203 | |||
204 | int | ||
194 | CBS_get_bytes(CBS *cbs, CBS *out, size_t len) | 205 | CBS_get_bytes(CBS *cbs, CBS *out, size_t len) |
195 | { | 206 | { |
196 | const uint8_t *v; | 207 | const uint8_t *v; |
diff --git a/src/lib/libssl/bytestring.h b/src/lib/libssl/bytestring.h index 9e55dd44d6..4ab2828d09 100644 --- a/src/lib/libssl/bytestring.h +++ b/src/lib/libssl/bytestring.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bytestring.h,v 1.19 2021/05/16 10:58:27 jsing Exp $ */ | 1 | /* $OpenBSD: bytestring.h,v 1.20 2021/12/15 17:23:34 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014, Google Inc. | 3 | * Copyright (c) 2014, Google Inc. |
4 | * | 4 | * |
@@ -134,6 +134,12 @@ int CBS_get_u24(CBS *cbs, uint32_t *out); | |||
134 | int CBS_get_u32(CBS *cbs, uint32_t *out); | 134 | int CBS_get_u32(CBS *cbs, uint32_t *out); |
135 | 135 | ||
136 | /* | 136 | /* |
137 | * CBS_get_last_u8 sets |*out| to the last uint8_t from |cbs| and shortens | ||
138 | * |cbs|. It returns one on success and zero on error. | ||
139 | */ | ||
140 | int CBS_get_last_u8(CBS *cbs, uint8_t *out); | ||
141 | |||
142 | /* | ||
137 | * CBS_get_bytes sets |*out| to the next |len| bytes from |cbs| and advances | 143 | * CBS_get_bytes sets |*out| to the next |len| bytes from |cbs| and advances |
138 | * |cbs|. It returns one on success and zero on error. | 144 | * |cbs|. It returns one on success and zero on error. |
139 | */ | 145 | */ |