diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc index e1d16f49..31ee51c4 100644 --- a/crypto/bytestring/bytestring_test.cc +++ b/crypto/bytestring/bytestring_test.cc @@ -269,7 +269,7 @@ static bool TestGetOptionalASN1Bool() { } static bool TestCBBBasic() { - static const uint8_t kExpected[] = {1, 2, 3, 4, 5, 6, 7, 8}; + static const uint8_t kExpected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc}; uint8_t *buf; size_t buf_len; CBB cbb; @@ -285,7 +285,8 @@ static bool TestCBBBasic() { if (!CBB_add_u8(&cbb, 1) || !CBB_add_u16(&cbb, 0x203) || !CBB_add_u24(&cbb, 0x40506) || - !CBB_add_bytes(&cbb, (const uint8_t*) "\x07\x08", 2) || + !CBB_add_u32(&cbb, 0x708090a) || + !CBB_add_bytes(&cbb, (const uint8_t*) "\x0b\x0c", 2) || !CBB_finish(&cbb, &buf, &buf_len)) { CBB_cleanup(&cbb); return false; diff --git a/crypto/bytestring/cbb.c b/crypto/bytestring/cbb.c index 8fc51879..6cb7988c 100644 --- a/crypto/bytestring/cbb.c +++ b/crypto/bytestring/cbb.c @@ -397,6 +397,14 @@ int CBB_add_u24(CBB *cbb, uint32_t value) { return cbb_buffer_add_u(cbb->base, value, 3); } +int CBB_add_u32(CBB *cbb, uint32_t value) { + if (!CBB_flush(cbb)) { + return 0; + } + + return cbb_buffer_add_u(cbb->base, value, 4); +} + void CBB_discard_child(CBB *cbb) { if (cbb->child == NULL) { return; diff --git a/include/openssl/bytestring.h b/include/openssl/bytestring.h index 3a8d4e53..c24281a5 100644 --- a/include/openssl/bytestring.h +++ b/include/openssl/bytestring.h @@ -377,6 +377,10 @@ OPENSSL_EXPORT int CBB_add_u16(CBB *cbb, uint16_t value); * returns one on success and zero otherwise. */ OPENSSL_EXPORT int CBB_add_u24(CBB *cbb, uint32_t value); +/* CBB_add_u32 appends a 32-bit, big-endian number from |value| to |cbb|. It + * returns one on success and zero otherwise. */ +OPENSSL_EXPORT int CBB_add_u32(CBB *cbb, uint32_t value); + /* CBB_discard_child discards the current unflushed child of |cbb|. Neither the * child's contents nor the length prefix will be included in the output. */ OPENSSL_EXPORT void CBB_discard_child(CBB *cbb);