Lines Matching refs:cbs
25 void CBS_init(CBS *cbs, const uint8_t *data, size_t len) {
26 cbs->data = data;
27 cbs->len = len;
30 static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) {
31 if (cbs->len < n) {
35 *p = cbs->data;
36 cbs->data += n;
37 cbs->len -= n;
41 int CBS_skip(CBS *cbs, size_t len) {
43 return cbs_get(cbs, &dummy, len);
46 const uint8_t *CBS_data(const CBS *cbs) {
47 return cbs->data;
50 size_t CBS_len(const CBS *cbs) {
51 return cbs->len;
54 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 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)
87 return CRYPTO_memcmp(cbs->data, data, len) == 0;
90 static int cbs_get_u(CBS *cbs, uint32_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) {
125 return cbs_get_u(cbs, out, 3);
128 int CBS_get_u32(CBS *cbs, uint32_t *out) {
129 return cbs_get_u(cbs, out, 4);
132 int CBS_get_bytes(CBS *cbs, CBS *out, size_t len) {
134 if (!cbs_get(cbs, &v, len)) {
141 static int cbs_get_length_prefixed(CBS *cbs, CBS *out, size_t len_len) {
143 if (!cbs_get_u(cbs, &len, len_len)) {
146 return CBS_get_bytes(cbs, out, len);
149 int CBS_get_u8_length_prefixed(CBS *cbs, CBS *out) {
150 return cbs_get_length_prefixed(cbs, out, 1);
153 int CBS_get_u16_length_prefixed(CBS *cbs, CBS *out) {
154 return cbs_get_length_prefixed(cbs, out, 2);
157 int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out) {
158 return cbs_get_length_prefixed(cbs, out, 3);
161 int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
164 CBS header = *cbs;
165 CBS throwaway;
200 return CBS_get_bytes(cbs, out, 2);
228 return CBS_get_bytes(cbs, out, len);
231 static int cbs_get_asn1(CBS *cbs, CBS *out, unsigned tag_value,
235 CBS throwaway;
241 if (!CBS_get_any_asn1_element(cbs, out, &tag, &header_len) ||
259 int CBS_get_asn1(CBS *cbs, CBS *out, unsigned tag_value) {
260 return cbs_get_asn1(cbs, out, tag_value, 1 /* skip header */);
263 int CBS_get_asn1_element(CBS *cbs, CBS *out, unsigned tag_value) {
264 return cbs_get_asn1(cbs, out, tag_value, 0 /* include header */);
267 int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
268 CBS bytes;
272 if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_INTEGER)) {