summaryrefslogtreecommitdiffstats
path: root/src/crypto/bytestring/cbb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/bytestring/cbb.c')
-rw-r--r--src/crypto/bytestring/cbb.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/crypto/bytestring/cbb.c b/src/crypto/bytestring/cbb.c
index 1da6a21..434ec13 100644
--- a/src/crypto/bytestring/cbb.c
+++ b/src/crypto/bytestring/cbb.c
@@ -70,6 +70,10 @@ int CBB_init_fixed(CBB *cbb, uint8_t *buf, size_t len) {
void CBB_cleanup(CBB *cbb) {
if (cbb->base) {
+ /* Only top-level |CBB|s are cleaned up. Child |CBB|s are non-owning. They
+ * are implicitly discarded when the parent is flushed or cleaned up. */
+ assert(cbb->is_top_level);
+
if (cbb->base->can_resize) {
OPENSSL_free(cbb->base->buf);
}
@@ -356,6 +360,20 @@ int CBB_add_u24(CBB *cbb, uint32_t value) {
return cbb_buffer_add_u(cbb->base, value, 3);
}
+void CBB_discard_child(CBB *cbb) {
+ if (cbb->child == NULL) {
+ return;
+ }
+
+ cbb->base->len = cbb->offset;
+
+ cbb->child->base = NULL;
+ cbb->child = NULL;
+ cbb->pending_len_len = 0;
+ cbb->pending_is_asn1 = 0;
+ cbb->offset = 0;
+}
+
int CBB_add_asn1_uint64(CBB *cbb, uint64_t value) {
CBB child;
size_t i;