diff options
Diffstat (limited to 'src/crypto/bytestring/cbs.c')
-rw-r--r-- | src/crypto/bytestring/cbs.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/crypto/bytestring/cbs.c b/src/crypto/bytestring/cbs.c index b8caedd..10f1a99 100644 --- a/src/crypto/bytestring/cbs.c +++ b/src/crypto/bytestring/cbs.c @@ -157,8 +157,8 @@ int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out) { return cbs_get_length_prefixed(cbs, out, 3); } -static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag, - size_t *out_header_len, int ber_ok) { +int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag, + size_t *out_header_len) { uint8_t tag, length_byte; CBS header = *cbs; CBS throwaway; @@ -193,11 +193,9 @@ static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag, const size_t num_bytes = length_byte & 0x7f; uint32_t len32; - if (ber_ok && (tag & CBS_ASN1_CONSTRUCTED) != 0 && num_bytes == 0) { + if ((tag & CBS_ASN1_CONSTRUCTED) != 0 && num_bytes == 0) { /* indefinite length */ - if (out_header_len != NULL) { - *out_header_len = 2; - } + *out_header_len = 2; return CBS_get_bytes(cbs, out, 2); } @@ -229,18 +227,6 @@ static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag, return CBS_get_bytes(cbs, out, len); } -int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag, - size_t *out_header_len) { - return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len, - 0 /* DER only */); -} - -int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag, - size_t *out_header_len) { - return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len, - 1 /* BER allowed */); -} - static int cbs_get_asn1(CBS *cbs, CBS *out, unsigned tag_value, int skip_header) { size_t header_len; @@ -252,7 +238,12 @@ static int cbs_get_asn1(CBS *cbs, CBS *out, unsigned tag_value, } if (!CBS_get_any_asn1_element(cbs, out, &tag, &header_len) || - tag != tag_value) { + tag != tag_value || + (header_len > 0 && + /* This ensures that the tag is either zero length or + * indefinite-length. */ + CBS_len(out) == header_len && + CBS_data(out)[header_len - 1] == 0x80)) { return 0; } |