Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@chromium.org>2015-10-10 21:13:23 +0300
committerAdam Langley <alangley@gmail.com>2015-10-20 20:56:19 +0300
commite8d53508ca92f31c0ce90468faf6c3bb4bdee8a2 (patch)
treee98010a5dbe3f7811b36056822bd7de581942022 /crypto/bytestring
parent978f16ea08a24cb740741c9956a934544c767db3 (diff)
Convert ssl3_send_client_hello to CBB.
Start converting the ones we can right now. Some of the messier ones resize init_buf rather than assume the initial size is sufficient, so those will probably wait until init_buf is gone and the handshake's undergone some more invasive surgery. The async ones will also require some thought. But some can be incrementally converted now. BUG=468889 Change-Id: I0bc22e4dca37d9d671a488c42eba864c51933638 Reviewed-on: https://boringssl-review.googlesource.com/6190 Reviewed-by: Adam Langley <alangley@gmail.com>
Diffstat (limited to 'crypto/bytestring')
-rw-r--r--crypto/bytestring/bytestring_test.cc50
-rw-r--r--crypto/bytestring/cbb.c14
2 files changed, 64 insertions, 0 deletions
diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc
index e987e1b9..eae88d9d 100644
--- a/crypto/bytestring/bytestring_test.cc
+++ b/crypto/bytestring/bytestring_test.cc
@@ -365,6 +365,55 @@ static bool TestCBBPrefixed() {
return buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
}
+static bool TestCBBDiscardChild() {
+ ScopedCBB cbb;
+ CBB contents, inner_contents, inner_inner_contents;
+
+ if (!CBB_init(cbb.get(), 0) ||
+ !CBB_add_u8(cbb.get(), 0xaa)) {
+ return false;
+ }
+
+ // Discarding |cbb|'s children preserves the byte written.
+ CBB_discard_child(cbb.get());
+
+ if (!CBB_add_u8_length_prefixed(cbb.get(), &contents) ||
+ !CBB_add_u8_length_prefixed(cbb.get(), &contents) ||
+ !CBB_add_u8(&contents, 0xbb) ||
+ !CBB_add_u16_length_prefixed(cbb.get(), &contents) ||
+ !CBB_add_u16(&contents, 0xcccc) ||
+ !CBB_add_u24_length_prefixed(cbb.get(), &contents) ||
+ !CBB_add_u24(&contents, 0xdddddd) ||
+ !CBB_add_u8_length_prefixed(cbb.get(), &contents) ||
+ !CBB_add_u8(&contents, 0xff) ||
+ !CBB_add_u8_length_prefixed(&contents, &inner_contents) ||
+ !CBB_add_u8(&inner_contents, 0x42) ||
+ !CBB_add_u16_length_prefixed(&inner_contents, &inner_inner_contents) ||
+ !CBB_add_u8(&inner_inner_contents, 0x99)) {
+ return false;
+ }
+
+ // Discard everything from |inner_contents| down.
+ CBB_discard_child(&contents);
+
+ uint8_t *buf;
+ size_t buf_len;
+ if (!CBB_finish(cbb.get(), &buf, &buf_len)) {
+ return false;
+ }
+ ScopedOpenSSLBytes scoper(buf);
+
+ static const uint8_t kExpected[] = {
+ 0xaa,
+ 0,
+ 1, 0xbb,
+ 0, 2, 0xcc, 0xcc,
+ 0, 0, 3, 0xdd, 0xdd, 0xdd,
+ 1, 0xff,
+ };
+ return buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
+}
+
static bool TestCBBMisuse() {
CBB cbb, child, contents;
uint8_t *buf;
@@ -670,6 +719,7 @@ int main(void) {
!TestCBBFinishChild() ||
!TestCBBMisuse() ||
!TestCBBPrefixed() ||
+ !TestCBBDiscardChild() ||
!TestCBBASN1() ||
!TestBerConvert() ||
!TestASN1Uint64() ||
diff --git a/crypto/bytestring/cbb.c b/crypto/bytestring/cbb.c
index 5d7485a8..434ec131 100644
--- a/crypto/bytestring/cbb.c
+++ b/crypto/bytestring/cbb.c
@@ -360,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;