Lines Matching refs:CBS
27 void CBS_init(CBS *cbs, const uint8_t *data, size_t len) {
28 cbs->data = data;
29 cbs->len = len;
32 static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) {
33 if (cbs->len < n) {
37 *p = cbs->data;
38 cbs->data += n;
39 cbs->len -= n;
43 int CBS_skip(CBS *cbs, size_t len) {
45 return cbs_get(cbs, &dummy, len);
48 const uint8_t *CBS_data(const CBS *cbs) {
49 return cbs->data;
52 size_t CBS_len(const CBS *cbs) {
53 return cbs->len;
56 int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) {
61 if (cbs->len == 0) {
64 *out_ptr = BUF_memdup(cbs->data, cbs->len);
68 *out_len = cbs->len;
72 int CBS_strdup(const CBS *cbs, char **out_ptr) {
76 *out_ptr = BUF_strndup((const char*)cbs->data, cbs->len);
80 int CBS_contains_zero_byte(const CBS *cbs) {
81 return OPENSSL_memchr(cbs->data, 0, cbs->len) != NULL;
84 int CBS_mem_equal(const CBS *cbs, const uint8_t *data, size_t len) {
85 if (len != cbs->len) {
88 return CRYPTO_memcmp(cbs->data, data, len) == 0;
91 static int cbs_get_u(CBS *cbs, uint64_t *out, size_t len) {
95 if (!cbs_get(cbs, &data, len)) {
106 int CBS_get_u8(CBS *cbs, uint8_t *out) {
108 if (!cbs_get(cbs, &v, 1)) {
115 int CBS_get_u16(CBS *cbs, uint16_t *out) {
117 if (!cbs_get_u(cbs, &v, 2)) {
124 int CBS_get_u24(CBS *cbs, uint32_t *out) {
126 if (!cbs_get_u(cbs, &v, 3)) {
133 int CBS_get_u32(CBS *cbs, uint32_t *out) {
135 if (!cbs_get_u(cbs, &v, 4)) {
142 int CBS_get_u64(CBS *cbs, uint64_t *out) {
143 return cbs_get_u(cbs, out, 8);
146 int CBS_get_last_u8(CBS *cbs, uint8_t *out) {
147 if (cbs->len == 0) {
150 *out = cbs->data[cbs->len - 1];
151 cbs->len--;
155 int CBS_get_bytes(CBS *cbs, CBS *out, size_t len) {
157 if (!cbs_get(cbs, &v, len)) {
164 int CBS_copy_bytes(CBS *cbs, uint8_t *out, size_t len) {
166 if (!cbs_get(cbs, &v, len)) {
173 static int cbs_get_length_prefixed(CBS *cbs, CBS *out, size_t len_len) {
175 if (!cbs_get_u(cbs, &len, len_len)) {
181 return CBS_get_bytes(cbs, out, len);
184 int CBS_get_u8_length_prefixed(CBS *cbs, CBS *out) {
185 return cbs_get_length_prefixed(cbs, out, 1);
188 int CBS_get_u16_length_prefixed(CBS *cbs, CBS *out) {
189 return cbs_get_length_prefixed(cbs, out, 2);
192 int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out) {
193 return cbs_get_length_prefixed(cbs, out, 3);
196 // parse_base128_integer reads a big-endian base-128 integer from |cbs| and sets
199 static int parse_base128_integer(CBS *cbs, uint64_t *out) {
203 if (!CBS_get_u8(cbs, &b)) {
223 static int parse_asn1_tag(CBS *cbs, unsigned *out) {
225 if (!CBS_get_u8(cbs, &tag_byte)) {
240 if (!parse_base128_integer(cbs, &v) ||
256 static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
258 CBS header = *cbs;
259 CBS throwaway;
278 size_t header_len = CBS_len(cbs) - CBS_len(&header);
301 return CBS_get_bytes(cbs, out, header_len);
334 return CBS_get_bytes(cbs, out, len);
337 int CBS_get_any_asn1(CBS *cbs, CBS *out, unsigned *out_tag) {
339 if (!CBS_get_any_asn1_element(cbs, out, out_tag, &header_len)) {
351 int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
353 return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len,
357 int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
359 return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len,
363 static int cbs_get_asn1(CBS *cbs, CBS *out, unsigned tag_value,
367 CBS throwaway;
373 if (!CBS_get_any_asn1_element(cbs, out, &tag, &header_len) ||
386 int CBS_get_asn1(CBS *cbs, CBS *out, unsigned tag_value) {
387 return cbs_get_asn1(cbs, out, tag_value, 1 /* skip header */);
390 int CBS_get_asn1_element(CBS *cbs, CBS *out, unsigned tag_value) {
391 return cbs_get_asn1(cbs, out, tag_value, 0 /* include header */);
394 int CBS_peek_asn1_tag(const CBS *cbs, unsigned tag_value) {
395 if (CBS_len(cbs) < 1) {
399 CBS copy = *cbs;
404 int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
405 CBS bytes;
406 if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_INTEGER)) {
441 int CBS_get_asn1_bool(CBS *cbs, int *out) {
442 CBS bytes;
443 if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_BOOLEAN) ||
457 int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present, unsigned tag) {
460 if (CBS_peek_asn1_tag(cbs, tag)) {
461 if (!CBS_get_asn1(cbs, out, tag)) {
474 int CBS_get_optional_asn1_octet_string(CBS *cbs, CBS *out, int *out_present,
476 CBS child;
478 if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) {
496 int CBS_get_optional_asn1_uint64(CBS *cbs, uint64_t *out, unsigned tag,
498 CBS child;
500 if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) {
514 int CBS_get_optional_asn1_bool(CBS *cbs, int *out, unsigned tag,
516 CBS child, child2;
518 if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) {
544 int CBS_is_valid_asn1_bitstring(const CBS *cbs) {
545 CBS in = *cbs;
566 int CBS_asn1_bitstring_has_bit(const CBS *cbs, unsigned bit) {
567 if (!CBS_is_valid_asn1_bitstring(cbs)) {
577 return byte_num < CBS_len(cbs) &&
578 (CBS_data(cbs)[byte_num] & (1 << bit_num)) != 0;
587 char *CBS_asn1_oid_to_text(const CBS *cbs) {
593 CBS copy = *cbs;