Home | History | Annotate | Download | only in bytestring

Lines Matching refs:cbs

26 void CBS_init(CBS *cbs, const uint8_t *data, size_t len) {
27 cbs->data = data;
28 cbs->len = len;
31 static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) {
32 if (cbs->len < n) {
36 *p = cbs->data;
37 cbs->data += n;
38 cbs->len -= n;
42 int CBS_skip(CBS *cbs, size_t len) {
44 return cbs_get(cbs, &dummy, len);
47 const uint8_t *CBS_data(const CBS *cbs) {
48 return cbs->data;
51 size_t CBS_len(const CBS *cbs) {
52 return cbs->len;
55 int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) {
60 if (cbs->len == 0) {
63 *out_ptr = BUF_memdup(cbs->data, cbs->len);
67 *out_len = cbs->len;
71 int CBS_strdup(const CBS *cbs, char **out_ptr) {
75 *out_ptr = BUF_strndup((const char*)cbs->data, cbs->len);
79 int CBS_contains_zero_byte(const CBS *cbs) {
80 return OPENSSL_memchr(cbs->data, 0, cbs->len) != NULL;
83 int CBS_mem_equal(const CBS *cbs, const uint8_t *data, size_t len) {
84 if (len != cbs->len) {
87 return CRYPTO_memcmp(cbs->data, data, len) == 0;
90 static int cbs_get_u(CBS *cbs, uint32_t *out, size_t len) {
94 if (!cbs_get(cbs, &data, len)) {
105 int CBS_get_u8(CBS *cbs, uint8_t *out) {
107 if (!cbs_get(cbs, &v, 1)) {
114 int CBS_get_u16(CBS *cbs, uint16_t *out) {
116 if (!cbs_get_u(cbs, &v, 2)) {
123 int CBS_get_u24(CBS *cbs, uint32_t *out) {
124 return cbs_get_u(cbs, out, 3);
127 int CBS_get_u32(CBS *cbs, uint32_t *out) {
128 return cbs_get_u(cbs, out, 4);
131 int CBS_get_last_u8(CBS *cbs, uint8_t *out) {
132 if (cbs->len == 0) {
135 *out = cbs->data[cbs->len - 1];
136 cbs->len--;
140 int CBS_get_bytes(CBS *cbs, CBS *out, size_t len) {
142 if (!cbs_get(cbs, &v, len)) {
149 int CBS_copy_bytes(CBS *cbs, uint8_t *out, size_t len) {
151 if (!cbs_get(cbs, &v, len)) {
158 static int cbs_get_length_prefixed(CBS *cbs, CBS *out, size_t len_len) {
160 if (!cbs_get_u(cbs, &len, len_len)) {
163 return CBS_get_bytes(cbs, out, len);
166 int CBS_get_u8_length_prefixed(CBS *cbs, CBS *out) {
167 return cbs_get_length_prefixed(cbs, out, 1);
170 int CBS_get_u16_length_prefixed(CBS *cbs, CBS *out) {
171 return cbs_get_length_prefixed(cbs, out, 2);
174 int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out) {
175 return cbs_get_length_prefixed(cbs, out, 3);
178 static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
181 CBS header = *cbs;
182 CBS throwaway;
229 return CBS_get_bytes(cbs, out, 2);
263 return CBS_get_bytes(cbs, out, len);
266 int CBS_get_any_asn1(CBS *cbs, CBS *out, unsigned *out_tag) {
268 if (!CBS_get_any_asn1_element(cbs, out, out_tag, &header_len)) {
280 int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
282 return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len,
286 int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
288 return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len,
292 static int cbs_get_asn1(CBS *cbs, CBS *out, unsigned tag_value,
296 CBS throwaway;
302 if (!CBS_get_any_asn1_element(cbs, out, &tag, &header_len) ||
315 int CBS_get_asn1(CBS *cbs, CBS *out, unsigned tag_value) {
316 return cbs_get_asn1(cbs, out, tag_value, 1 /* skip header */);
319 int CBS_get_asn1_element(CBS *cbs, CBS *out, unsigned tag_value) {
320 return cbs_get_asn1(cbs, out, tag_value, 0 /* include header */);
323 int CBS_peek_asn1_tag(const CBS *cbs, unsigned tag_value) {
324 if (CBS_len(cbs) < 1) {
327 return CBS_data(cbs)[0] == tag_value;
330 int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
331 CBS bytes;
332 if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_INTEGER)) {
367 int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present, unsigned tag) {
370 if (CBS_peek_asn1_tag(cbs, tag)) {
371 if (!CBS_get_asn1(cbs, out, tag)) {
384 int CBS_get_optional_asn1_octet_string(CBS *cbs, CBS *out, int *out_present,
386 CBS child;
388 if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) {
405 int CBS_get_optional_asn1_uint64(CBS *cbs, uint64_t *out, unsigned tag,
407 CBS child;
409 if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) {
423 int CBS_get_optional_asn1_bool(CBS *cbs, int *out, unsigned tag,
425 CBS child, child2;
427 if (!CBS_get_optional_asn1(cbs, &child, &present, tag)) {
453 int CBS_is_valid_asn1_bitstring(const CBS *cbs) {
454 CBS in = *cbs;
475 int CBS_asn1_bitstring_has_bit(const CBS *cbs, unsigned bit) {
476 if (!CBS_is_valid_asn1_bitstring(cbs)) {
486 return byte_num < CBS_len(cbs) &&
487 (CBS_data(cbs)[byte_num] & (1 << bit_num)) != 0;