• Home
  • Raw
  • Download

Lines Matching refs:cbs

31 void CBS_init(CBS *cbs, const uint8_t *data, size_t len) {  in CBS_init()  argument
32 cbs->data = data; in CBS_init()
33 cbs->len = len; in CBS_init()
36 static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) { in cbs_get() argument
37 if (cbs->len < n) { in cbs_get()
41 *p = cbs->data; in cbs_get()
42 cbs->data += n; in cbs_get()
43 cbs->len -= n; in cbs_get()
47 int CBS_skip(CBS *cbs, size_t len) { in CBS_skip() argument
49 return cbs_get(cbs, &dummy, len); in CBS_skip()
52 const uint8_t *CBS_data(const CBS *cbs) { in CBS_data() argument
53 return cbs->data; in CBS_data()
56 size_t CBS_len(const CBS *cbs) { in CBS_len() argument
57 return cbs->len; in CBS_len()
60 int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) { in CBS_stow() argument
65 if (cbs->len == 0) { in CBS_stow()
68 *out_ptr = BUF_memdup(cbs->data, cbs->len); in CBS_stow()
72 *out_len = cbs->len; in CBS_stow()
76 int CBS_strdup(const CBS *cbs, char **out_ptr) { in CBS_strdup() argument
80 *out_ptr = BUF_strndup((const char*)cbs->data, cbs->len); in CBS_strdup()
84 int CBS_contains_zero_byte(const CBS *cbs) { in CBS_contains_zero_byte() argument
85 return OPENSSL_memchr(cbs->data, 0, cbs->len) != NULL; in CBS_contains_zero_byte()
88 int CBS_mem_equal(const CBS *cbs, const uint8_t *data, size_t len) { in CBS_mem_equal() argument
89 if (len != cbs->len) { in CBS_mem_equal()
92 return CRYPTO_memcmp(cbs->data, data, len) == 0; in CBS_mem_equal()
95 static int cbs_get_u(CBS *cbs, uint32_t *out, size_t len) { in cbs_get_u() argument
99 if (!cbs_get(cbs, &data, len)) { in cbs_get_u()
110 int CBS_get_u8(CBS *cbs, uint8_t *out) { in CBS_get_u8() argument
112 if (!cbs_get(cbs, &v, 1)) { in CBS_get_u8()
119 int CBS_get_u16(CBS *cbs, uint16_t *out) { in CBS_get_u16() argument
121 if (!cbs_get_u(cbs, &v, 2)) { in CBS_get_u16()
128 int CBS_get_u24(CBS *cbs, uint32_t *out) { in CBS_get_u24() argument
129 return cbs_get_u(cbs, out, 3); in CBS_get_u24()
132 int CBS_get_u32(CBS *cbs, uint32_t *out) { in CBS_get_u32() argument
133 return cbs_get_u(cbs, out, 4); in CBS_get_u32()
136 int CBS_get_last_u8(CBS *cbs, uint8_t *out) { in CBS_get_last_u8() argument
137 if (cbs->len == 0) { in CBS_get_last_u8()
140 *out = cbs->data[cbs->len - 1]; in CBS_get_last_u8()
141 cbs->len--; in CBS_get_last_u8()
145 int CBS_get_bytes(CBS *cbs, CBS *out, size_t len) { in CBS_get_bytes() argument
147 if (!cbs_get(cbs, &v, len)) { in CBS_get_bytes()
154 int CBS_copy_bytes(CBS *cbs, uint8_t *out, size_t len) { in CBS_copy_bytes() argument
156 if (!cbs_get(cbs, &v, len)) { in CBS_copy_bytes()
163 static int cbs_get_length_prefixed(CBS *cbs, CBS *out, size_t len_len) { in cbs_get_length_prefixed() argument
165 if (!cbs_get_u(cbs, &len, len_len)) { in cbs_get_length_prefixed()
168 return CBS_get_bytes(cbs, out, len); in cbs_get_length_prefixed()
171 int CBS_get_u8_length_prefixed(CBS *cbs, CBS *out) { in CBS_get_u8_length_prefixed() argument
172 return cbs_get_length_prefixed(cbs, out, 1); in CBS_get_u8_length_prefixed()
175 int CBS_get_u16_length_prefixed(CBS *cbs, CBS *out) { in CBS_get_u16_length_prefixed() argument
176 return cbs_get_length_prefixed(cbs, out, 2); in CBS_get_u16_length_prefixed()
179 int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out) { in CBS_get_u24_length_prefixed() argument
180 return cbs_get_length_prefixed(cbs, out, 3); in CBS_get_u24_length_prefixed()
186 static int parse_base128_integer(CBS *cbs, uint64_t *out) { in parse_base128_integer() argument
190 if (!CBS_get_u8(cbs, &b)) { in parse_base128_integer()
210 static int parse_asn1_tag(CBS *cbs, unsigned *out) { in parse_asn1_tag() argument
212 if (!CBS_get_u8(cbs, &tag_byte)) { in parse_asn1_tag()
227 if (!parse_base128_integer(cbs, &v) || in parse_asn1_tag()
243 static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag, in cbs_get_any_asn1_element() argument
245 CBS header = *cbs; in cbs_get_any_asn1_element()
265 size_t header_len = CBS_len(cbs) - CBS_len(&header); in cbs_get_any_asn1_element()
288 return CBS_get_bytes(cbs, out, header_len); in cbs_get_any_asn1_element()
321 return CBS_get_bytes(cbs, out, len); in cbs_get_any_asn1_element()
324 int CBS_get_any_asn1(CBS *cbs, CBS *out, unsigned *out_tag) { in CBS_get_any_asn1() argument
326 if (!CBS_get_any_asn1_element(cbs, out, out_tag, &header_len)) { in CBS_get_any_asn1()
338 int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag, in CBS_get_any_asn1_element() argument
340 return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len, in CBS_get_any_asn1_element()
344 int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag, in CBS_get_any_ber_asn1_element() argument
346 return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len, in CBS_get_any_ber_asn1_element()
350 static int cbs_get_asn1(CBS *cbs, CBS *out, unsigned tag_value, in cbs_get_asn1() argument
360 if (!CBS_get_any_asn1_element(cbs, out, &tag, &header_len) || in cbs_get_asn1()
373 int CBS_get_asn1(CBS *cbs, CBS *out, unsigned tag_value) { in CBS_get_asn1() argument
374 return cbs_get_asn1(cbs, out, tag_value, 1 /* skip header */); in CBS_get_asn1()
377 int CBS_get_asn1_element(CBS *cbs, CBS *out, unsigned tag_value) { in CBS_get_asn1_element() argument
378 return cbs_get_asn1(cbs, out, tag_value, 0 /* include header */); in CBS_get_asn1_element()
381 int CBS_peek_asn1_tag(const CBS *cbs, unsigned tag_value) { in CBS_peek_asn1_tag() argument
382 if (CBS_len(cbs) < 1) { in CBS_peek_asn1_tag()
386 CBS copy = *cbs; in CBS_peek_asn1_tag()
391 int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) { in CBS_get_asn1_uint64() argument
393 if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_INTEGER)) { in CBS_get_asn1_uint64()
428 int CBS_get_asn1_bool(CBS *cbs, int *out) { in CBS_get_asn1_bool() argument
430 if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_BOOLEAN) || in CBS_get_asn1_bool()
444 int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present, unsigned tag) { in CBS_get_optional_asn1() argument
447 if (CBS_peek_asn1_tag(cbs, tag)) { in CBS_get_optional_asn1()
448 if (!CBS_get_asn1(cbs, out, tag)) { in CBS_get_optional_asn1()
461 int CBS_get_optional_asn1_octet_string(CBS *cbs, CBS *out, int *out_present, in CBS_get_optional_asn1_octet_string() argument
465 if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) { in CBS_get_optional_asn1_octet_string()
482 int CBS_get_optional_asn1_uint64(CBS *cbs, uint64_t *out, unsigned tag, in CBS_get_optional_asn1_uint64() argument
486 if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) { in CBS_get_optional_asn1_uint64()
500 int CBS_get_optional_asn1_bool(CBS *cbs, int *out, unsigned tag, in CBS_get_optional_asn1_bool() argument
504 if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) { in CBS_get_optional_asn1_bool()
530 int CBS_is_valid_asn1_bitstring(const CBS *cbs) { in CBS_is_valid_asn1_bitstring() argument
531 CBS in = *cbs; in CBS_is_valid_asn1_bitstring()
552 int CBS_asn1_bitstring_has_bit(const CBS *cbs, unsigned bit) { in CBS_asn1_bitstring_has_bit() argument
553 if (!CBS_is_valid_asn1_bitstring(cbs)) { in CBS_asn1_bitstring_has_bit()
563 return byte_num < CBS_len(cbs) && in CBS_asn1_bitstring_has_bit()
564 (CBS_data(cbs)[byte_num] & (1 << bit_num)) != 0; in CBS_asn1_bitstring_has_bit()
573 char *CBS_asn1_oid_to_text(const CBS *cbs) { in CBS_asn1_oid_to_text() argument
579 CBS copy = *cbs; in CBS_asn1_oid_to_text()