aboutsummaryrefslogtreecommitdiff
path: root/include/openssl/bytestring.h
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@google.com>2016-08-19 16:08:45 -0400
committerCQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>2016-08-26 17:48:48 +0000
commit1db42fb3ca46d3d4987ddae2f7aec7732c66a70b (patch)
treee50a56e8ef1cd6561f4d6e05ebf51573cc3bfc3d /include/openssl/bytestring.h
parenta6cd185a545841d122d8f0a49c2cffdabab149b7 (diff)
downloadboringssl-1db42fb3ca46d3d4987ddae2f7aec7732c66a70b.zip
boringssl-1db42fb3ca46d3d4987ddae2f7aec7732c66a70b.tar.gz
boringssl-1db42fb3ca46d3d4987ddae2f7aec7732c66a70b.tar.bz2
Clarify CBS/CBB with respect to high tag number form.
We may need to implement high tag number form someday. CBS_get_asn1 has an unsigned output to allow for this, but CBB_add_asn1 takes a uint8_t (I think this might be my fault). Fix that which also fixes a -Wconversion warning. Simply leaving room in tag representation will still cause troubles because the class and constructed bits overlap with bits for tag numbers above 31. Probably the cleanest option would be to shift them to the top 3 bits of a u32 and thus not quite match the DER representation. Then CBS_get_asn1 and CBB_add_asn1 will internally munge that into the DER representation and consumers may continue to write things like: tag_number | CBS_ASN1_CONTEXT_SPECIFIC I haven't done that here, but in preparation for that, document that consumers need to use the values and should refrain from assuming the correspond to DER. Change-Id: Ibc76e51f0bc3b843e48e89adddfe2eaba4843d12 Reviewed-on: https://boringssl-review.googlesource.com/10502 Reviewed-by: Adam Langley <agl@google.com> Commit-Queue: Adam Langley <agl@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Diffstat (limited to 'include/openssl/bytestring.h')
-rw-r--r--include/openssl/bytestring.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/include/openssl/bytestring.h b/include/openssl/bytestring.h
index 68138bc..c055a73 100644
--- a/include/openssl/bytestring.h
+++ b/include/openssl/bytestring.h
@@ -125,6 +125,7 @@ OPENSSL_EXPORT int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out);
/* Parsing ASN.1 */
+/* The following values are tag numbers for UNIVERSAL elements. */
#define CBS_ASN1_BOOLEAN 0x1
#define CBS_ASN1_INTEGER 0x2
#define CBS_ASN1_BITSTRING 0x3
@@ -148,8 +149,27 @@ OPENSSL_EXPORT int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out);
#define CBS_ASN1_UNIVERSALSTRING 0x1c
#define CBS_ASN1_BMPSTRING 0x1e
+/* CBS_ASN1_CONSTRUCTED may be ORed into a tag to toggle the constructed
+ * bit. |CBS| and |CBB| APIs consider the constructed bit to be part of the
+ * tag. */
#define CBS_ASN1_CONSTRUCTED 0x20
+
+/* The following values specify the constructed bit or tag class and may be ORed
+ * into a tag number to produce the final tag. If none is used, the tag will be
+ * UNIVERSAL.
+ *
+ * Note that although they currently match the DER serialization, consumers must
+ * use these bits rather than make assumptions about the representation. This is
+ * to allow for tag numbers beyond 31 in the future. */
+#define CBS_ASN1_APPLICATION 0x40
#define CBS_ASN1_CONTEXT_SPECIFIC 0x80
+#define CBS_ASN1_PRIVATE 0xc0
+
+/* CBS_ASN1_CLASS_MASK may be ANDed with a tag to query its class. */
+#define CBS_ASN1_CLASS_MASK 0xc0
+
+/* CBS_ASN1_TAG_NUMBER_MASK may be ANDed with a tag to query its number. */
+#define CBS_ASN1_TAG_NUMBER_MASK 0x1f
/* CBS_get_asn1 sets |*out| to the contents of DER-encoded, ASN.1 element (not
* including tag and length bytes) and advances |cbs| over it. The ASN.1
@@ -345,7 +365,7 @@ OPENSSL_EXPORT int CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents);
* the object. Passing in |tag| number 31 will return in an error since only
* single octet identifiers are supported. It returns one on success or zero
* on error. */
-OPENSSL_EXPORT int CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag);
+OPENSSL_EXPORT int CBB_add_asn1(CBB *cbb, CBB *out_contents, unsigned tag);
/* CBB_add_bytes appends |len| bytes from |data| to |cbb|. It returns one on
* success and zero otherwise. */