-/* $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.
*
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)
{
-/* $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.
*
*/
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.