summaryrefslogtreecommitdiff
path: root/crypto/bytestring/bytestring_test.c
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@chromium.org>2014-10-09 19:39:15 -0400
committerAdam Langley <agl@google.com>2014-10-20 19:20:26 +0000
commitb698617007b3b2048c052ef714e4fe48a175b3c4 (patch)
treeeeb0b8045d6ef4d1b834a762f63b0a65c987a3e4 /crypto/bytestring/bytestring_test.c
parent7f7882f1a8880c369798f8eaadfab410bd7e24a3 (diff)
downloadsrc-b698617007b3b2048c052ef714e4fe48a175b3c4.tar.gz
Add CBS_peek_asn1_tag.
Intended to make parsing ASN.1 structures with OPTIONAL elements easier. (Just attempting to parse the next tag doesn't distinguish between a malformed CBS which has now been partially advanced and an optional tag mismatch.) Change-Id: Idceb3dfd6ec028e87e1bc5aaddcec177b0c32150 Reviewed-on: https://boringssl-review.googlesource.com/1995 Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/bytestring/bytestring_test.c')
-rw-r--r--crypto/bytestring/bytestring_test.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/crypto/bytestring/bytestring_test.c b/crypto/bytestring/bytestring_test.c
index e4afccd..f30179d 100644
--- a/crypto/bytestring/bytestring_test.c
+++ b/crypto/bytestring/bytestring_test.c
@@ -109,6 +109,10 @@ static int test_get_asn1(void) {
CBS data, contents;
CBS_init(&data, kData1, sizeof(kData1));
+ if (CBS_peek_asn1_tag(&data, 0x1) ||
+ !CBS_peek_asn1_tag(&data, 0x30)) {
+ return 0;
+ }
if (!CBS_get_asn1(&data, &contents, 0x30) ||
CBS_len(&contents) != 2 ||
memcmp(CBS_data(&contents), "\x01\x02", 2) != 0) {
@@ -145,6 +149,11 @@ static int test_get_asn1(void) {
return 0;
}
+ CBS_init(&data, NULL, 0);
+ if (CBS_peek_asn1_tag(&data, 0x30)) {
+ return 0;
+ }
+
return 1;
}