2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2001
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "../lib/util/asn1.h"
25 size_t taglen; /* for parsing */
29 /* allocate an asn1 structure */
30 struct asn1_data *asn1_init(TALLOC_CTX *mem_ctx)
32 struct asn1_data *ret = talloc_zero(mem_ctx, struct asn1_data);
34 DEBUG(0,("asn1_init failed! out of memory\n"));
39 /* free an asn1 structure */
40 void asn1_free(struct asn1_data *data)
45 bool asn1_has_error(const struct asn1_data *data)
47 return data->has_error;
50 void asn1_set_error(struct asn1_data *data)
52 data->has_error = true;
55 /* write to the ASN1 buffer, advancing the buffer pointer */
56 bool asn1_write(struct asn1_data *data, const void *p, int len)
58 if (data->has_error) return false;
60 if ((len < 0) || (data->ofs + (size_t)len < data->ofs)) {
61 data->has_error = true;
65 if (data->length < data->ofs+len) {
67 newp = talloc_realloc(data, data->data, uint8_t, data->ofs+len);
69 data->has_error = true;
73 data->length = data->ofs+len;
75 memcpy(data->data + data->ofs, p, len);
80 /* useful fn for writing a uint8_t */
81 bool asn1_write_uint8(struct asn1_data *data, uint8_t v)
83 return asn1_write(data, &v, 1);
86 /* push a tag onto the asn1 data buffer. Used for nested structures */
87 bool asn1_push_tag(struct asn1_data *data, uint8_t tag)
89 struct nesting *nesting;
91 if (!asn1_write_uint8(data, tag)) {
94 nesting = talloc(data, struct nesting);
96 data->has_error = true;
100 nesting->start = data->ofs;
101 nesting->next = data->nesting;
102 data->nesting = nesting;
103 return asn1_write_uint8(data, 0xff);
107 bool asn1_pop_tag(struct asn1_data *data)
109 struct nesting *nesting;
112 if (data->has_error) {
116 nesting = data->nesting;
119 data->has_error = true;
122 len = data->ofs - (nesting->start+1);
123 /* yes, this is ugly. We don't know in advance how many bytes the length
124 of a tag will take, so we assumed 1 byte. If we were wrong then we
125 need to correct our mistake */
126 if (len > 0xFFFFFF) {
127 data->data[nesting->start] = 0x84;
128 if (!asn1_write_uint8(data, 0)) return false;
129 if (!asn1_write_uint8(data, 0)) return false;
130 if (!asn1_write_uint8(data, 0)) return false;
131 if (!asn1_write_uint8(data, 0)) return false;
132 memmove(data->data+nesting->start+5, data->data+nesting->start+1, len);
133 data->data[nesting->start+1] = (len>>24) & 0xFF;
134 data->data[nesting->start+2] = (len>>16) & 0xFF;
135 data->data[nesting->start+3] = (len>>8) & 0xFF;
136 data->data[nesting->start+4] = len&0xff;
137 } else if (len > 0xFFFF) {
138 data->data[nesting->start] = 0x83;
139 if (!asn1_write_uint8(data, 0)) return false;
140 if (!asn1_write_uint8(data, 0)) return false;
141 if (!asn1_write_uint8(data, 0)) return false;
142 memmove(data->data+nesting->start+4, data->data+nesting->start+1, len);
143 data->data[nesting->start+1] = (len>>16) & 0xFF;
144 data->data[nesting->start+2] = (len>>8) & 0xFF;
145 data->data[nesting->start+3] = len&0xff;
146 } else if (len > 255) {
147 data->data[nesting->start] = 0x82;
148 if (!asn1_write_uint8(data, 0)) return false;
149 if (!asn1_write_uint8(data, 0)) return false;
150 memmove(data->data+nesting->start+3, data->data+nesting->start+1, len);
151 data->data[nesting->start+1] = len>>8;
152 data->data[nesting->start+2] = len&0xff;
153 } else if (len > 127) {
154 data->data[nesting->start] = 0x81;
155 if (!asn1_write_uint8(data, 0)) return false;
156 memmove(data->data+nesting->start+2, data->data+nesting->start+1, len);
157 data->data[nesting->start+1] = len;
159 data->data[nesting->start] = len;
162 data->nesting = nesting->next;
163 talloc_free(nesting);
167 /* "i" is the one's complement representation, as is the normal result of an
168 * implicit signed->unsigned conversion */
170 static bool push_int_bigendian(struct asn1_data *data, unsigned int i, bool negative)
172 uint8_t lowest = i & 0xFF;
176 if (!push_int_bigendian(data, i, negative))
179 if (data->nesting->start+1 == data->ofs) {
181 /* We did not write anything yet, looking at the highest
185 /* Don't write leading 0xff's */
189 if ((lowest & 0x80) == 0) {
190 /* The only exception for a leading 0xff is if
191 * the highest bit is 0, which would indicate
192 * a positive value */
193 if (!asn1_write_uint8(data, 0xff))
198 /* The highest bit of a positive integer is 1,
199 * this would indicate a negative number. Push
200 * a 0 to indicate a positive one */
201 if (!asn1_write_uint8(data, 0))
207 return asn1_write_uint8(data, lowest);
210 /* write an Integer without the tag framing. Needed for example for the LDAP
211 * Abandon Operation */
213 bool asn1_write_implicit_Integer(struct asn1_data *data, int i)
215 if (data->has_error) {
220 /* -1 is special as it consists of all-0xff bytes. In
221 push_int_bigendian this is the only case that is not
222 properly handled, as all 0xff bytes would be handled as
223 leading ones to be ignored. */
224 return asn1_write_uint8(data, 0xff);
226 return push_int_bigendian(data, i, i<0);
231 /* write an integer */
232 bool asn1_write_Integer(struct asn1_data *data, int i)
234 if (!asn1_push_tag(data, ASN1_INTEGER)) return false;
235 if (!asn1_write_implicit_Integer(data, i)) return false;
236 return asn1_pop_tag(data);
239 /* write a BIT STRING */
240 bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length, uint8_t padding)
242 if (!asn1_push_tag(data, ASN1_BIT_STRING)) return false;
243 if (!asn1_write_uint8(data, padding)) return false;
244 if (!asn1_write(data, p, length)) return false;
245 return asn1_pop_tag(data);
248 bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID)
251 const char *p = (const char *)OID;
255 if (!isdigit(*p)) return false;
256 v = strtoul(p, &newp, 10);
257 if (newp[0] != '.') return false;
260 if (!isdigit(*p)) return false;
261 v2 = strtoul(p, &newp, 10);
262 if (newp[0] != '.') return false;
265 /*the ber representation can't use more space then the string one */
266 *blob = data_blob_talloc(mem_ctx, NULL, strlen(OID));
267 if (!blob->data) return false;
269 blob->data[0] = 40*v + v2;
273 if (!isdigit(*p)) return false;
274 v = strtoul(p, &newp, 10);
275 if (newp[0] == '.') {
277 /* check for empty last component */
278 if (!*p) return false;
279 } else if (newp[0] == '\0') {
282 data_blob_free(blob);
285 if (v >= (1<<28)) blob->data[i++] = (0x80 | ((v>>28)&0x7f));
286 if (v >= (1<<21)) blob->data[i++] = (0x80 | ((v>>21)&0x7f));
287 if (v >= (1<<14)) blob->data[i++] = (0x80 | ((v>>14)&0x7f));
288 if (v >= (1<<7)) blob->data[i++] = (0x80 | ((v>>7)&0x7f));
289 blob->data[i++] = (v&0x7f);
298 * Serialize partial OID string.
299 * Partial OIDs are in the form:
303 bool ber_write_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *partial_oid)
305 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
306 char *oid = talloc_strdup(tmp_ctx, partial_oid);
309 /* truncate partial part so ber_write_OID_String() works */
310 p = strchr(oid, ':');
316 if (!ber_write_OID_String(mem_ctx, blob, oid)) {
317 talloc_free(tmp_ctx);
321 /* Add partially encoded sub-identifier */
323 DATA_BLOB tmp_blob = strhex_to_data_blob(tmp_ctx, p);
324 if (!data_blob_append(mem_ctx, blob, tmp_blob.data,
326 talloc_free(tmp_ctx);
331 talloc_free(tmp_ctx);
336 /* write an object ID to a ASN1 buffer */
337 bool asn1_write_OID(struct asn1_data *data, const char *OID)
341 if (!asn1_push_tag(data, ASN1_OID)) return false;
343 if (!ber_write_OID_String(NULL, &blob, OID)) {
344 data->has_error = true;
348 if (!asn1_write(data, blob.data, blob.length)) {
349 data_blob_free(&blob);
350 data->has_error = true;
353 data_blob_free(&blob);
354 return asn1_pop_tag(data);
357 /* write an octet string */
358 bool asn1_write_OctetString(struct asn1_data *data, const void *p, size_t length)
360 if (!asn1_push_tag(data, ASN1_OCTET_STRING)) return false;
361 if (!asn1_write(data, p, length)) return false;
362 return asn1_pop_tag(data);
365 /* write a LDAP string */
366 bool asn1_write_LDAPString(struct asn1_data *data, const char *s)
368 return asn1_write(data, s, strlen(s));
371 /* write a LDAP string from a DATA_BLOB */
372 bool asn1_write_DATA_BLOB_LDAPString(struct asn1_data *data, const DATA_BLOB *s)
374 return asn1_write(data, s->data, s->length);
377 /* write a general string */
378 bool asn1_write_GeneralString(struct asn1_data *data, const char *s)
380 if (!asn1_push_tag(data, ASN1_GENERAL_STRING)) return false;
381 if (!asn1_write_LDAPString(data, s)) return false;
382 return asn1_pop_tag(data);
385 bool asn1_write_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *blob)
387 if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(num))) return false;
388 if (!asn1_write(data, blob->data, blob->length)) return false;
389 return asn1_pop_tag(data);
392 /* write a BOOLEAN */
393 bool asn1_write_BOOLEAN(struct asn1_data *data, bool v)
395 if (!asn1_push_tag(data, ASN1_BOOLEAN)) return false;
396 if (!asn1_write_uint8(data, v ? 0xFF : 0)) return false;
397 return asn1_pop_tag(data);
400 bool asn1_read_BOOLEAN(struct asn1_data *data, bool *v)
403 if (!asn1_start_tag(data, ASN1_BOOLEAN)) return false;
405 if (!asn1_read_uint8(data, &tmp)) return false;
409 return asn1_end_tag(data);
412 /* write a BOOLEAN in a simple context */
413 bool asn1_write_BOOLEAN_context(struct asn1_data *data, bool v, int context)
415 if (!asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(context))) return false;
416 if (!asn1_write_uint8(data, v ? 0xFF : 0)) return false;
417 return asn1_pop_tag(data);
420 bool asn1_read_BOOLEAN_context(struct asn1_data *data, bool *v, int context)
423 if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(context))) return false;
425 if (!asn1_read_uint8(data, &tmp)) return false;
429 return asn1_end_tag(data);
432 /* check a BOOLEAN */
433 bool asn1_check_BOOLEAN(struct asn1_data *data, bool v)
437 if (!asn1_read_uint8(data, &b)) return false;
438 if (b != ASN1_BOOLEAN) {
439 data->has_error = true;
442 if (!asn1_read_uint8(data, &b)) return false;
444 data->has_error = true;
447 return !data->has_error;
451 /* load a struct asn1_data structure with a lump of data, ready to be parsed */
452 bool asn1_load(struct asn1_data *data, DATA_BLOB blob)
455 data->data = (uint8_t *)talloc_memdup(data, blob.data, blob.length);
457 data->has_error = true;
460 data->length = blob.length;
464 /* Peek into an ASN1 buffer, not advancing the pointer */
465 bool asn1_peek(struct asn1_data *data, void *p, int len)
470 if (len < 0 || data->ofs + len < data->ofs || data->ofs + len < len)
473 if (data->ofs + len > data->length) {
474 /* we need to mark the buffer as consumed, so the caller knows
475 this was an out of data error, and not a decode error */
476 data->ofs = data->length;
480 memcpy(p, data->data + data->ofs, len);
484 /* read from a ASN1 buffer, advancing the buffer pointer */
485 bool asn1_read(struct asn1_data *data, void *p, int len)
487 if (!asn1_peek(data, p, len)) {
488 data->has_error = true;
496 /* read a uint8_t from a ASN1 buffer */
497 bool asn1_read_uint8(struct asn1_data *data, uint8_t *v)
499 return asn1_read(data, v, 1);
502 bool asn1_peek_uint8(struct asn1_data *data, uint8_t *v)
504 return asn1_peek(data, v, 1);
507 bool asn1_peek_tag(struct asn1_data *data, uint8_t tag)
511 if (asn1_tag_remaining(data) <= 0) {
515 if (!asn1_peek_uint8(data, &b))
522 * just get the needed size the tag would consume
524 bool asn1_peek_tag_needed_size(struct asn1_data *data, uint8_t tag, size_t *size)
526 off_t start_ofs = data->ofs;
530 if (data->has_error) {
534 if (!asn1_read_uint8(data, &b)) {
535 data->ofs = start_ofs;
536 data->has_error = false;
541 data->ofs = start_ofs;
542 data->has_error = false;
546 if (!asn1_read_uint8(data, &b)) {
547 data->ofs = start_ofs;
548 data->has_error = false;
554 if (!asn1_read_uint8(data, &b)) {
555 data->ofs = start_ofs;
556 data->has_error = false;
561 * We should not allow more than 4 bytes
562 * for the encoding of the tag length.
564 * Otherwise we'd overflow the taglen
565 * variable on 32 bit systems.
567 data->ofs = start_ofs;
568 data->has_error = false;
573 if (!asn1_read_uint8(data, &b)) {
574 data->ofs = start_ofs;
575 data->has_error = false;
578 taglen = (taglen << 8) | b;
585 *size = (data->ofs - start_ofs) + taglen;
587 data->ofs = start_ofs;
588 data->has_error = false;
592 /* start reading a nested asn1 structure */
593 bool asn1_start_tag(struct asn1_data *data, uint8_t tag)
596 struct nesting *nesting;
598 if (!asn1_read_uint8(data, &b))
602 data->has_error = true;
605 nesting = talloc(data, struct nesting);
607 data->has_error = true;
611 if (!asn1_read_uint8(data, &b)) {
617 if (!asn1_read_uint8(data, &b))
621 if (!asn1_read_uint8(data, &b))
623 nesting->taglen = (nesting->taglen << 8) | b;
629 nesting->start = data->ofs;
630 nesting->next = data->nesting;
631 data->nesting = nesting;
632 if (asn1_tag_remaining(data) == -1) {
635 return !data->has_error;
638 /* stop reading a tag */
639 bool asn1_end_tag(struct asn1_data *data)
641 struct nesting *nesting;
643 /* make sure we read it all */
644 if (asn1_tag_remaining(data) != 0) {
645 data->has_error = true;
649 nesting = data->nesting;
652 data->has_error = true;
656 data->nesting = nesting->next;
657 talloc_free(nesting);
661 /* work out how many bytes are left in this nested tag */
662 int asn1_tag_remaining(struct asn1_data *data)
665 if (data->has_error) {
669 if (!data->nesting) {
670 data->has_error = true;
673 remaining = data->nesting->taglen - (data->ofs - data->nesting->start);
674 if (remaining > (data->length - data->ofs)) {
675 data->has_error = true;
682 * Internal implementation for reading binary OIDs
683 * Reading is done as far in the buffer as valid OID
684 * till buffer ends or not valid sub-identifier is found.
686 static bool _ber_read_OID_String_impl(TALLOC_CTX *mem_ctx, DATA_BLOB blob,
687 char **OID, size_t *bytes_eaten)
692 char *tmp_oid = NULL;
694 if (blob.length < 2) return false;
698 tmp_oid = talloc_asprintf(mem_ctx, "%u", b[0]/40);
699 if (!tmp_oid) goto nomem;
700 tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", b[0]%40);
701 if (!tmp_oid) goto nomem;
703 if (bytes_eaten != NULL) {
707 for(i = 1, v = 0; i < blob.length; i++) {
708 v = (v<<7) | (b[i]&0x7f);
709 if ( ! (b[i] & 0x80)) {
710 tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", v);
715 if (!tmp_oid) goto nomem;
725 /* read an object ID from a data blob */
726 bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, char **OID)
730 if (!_ber_read_OID_String_impl(mem_ctx, blob, OID, &bytes_eaten))
733 return (bytes_eaten == blob.length);
737 * Deserialize partial OID string.
738 * Partial OIDs are in the form:
742 bool ber_read_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob,
747 char *identifier = NULL;
748 char *tmp_oid = NULL;
750 if (!_ber_read_OID_String_impl(mem_ctx, blob, &tmp_oid, &bytes_eaten))
753 if (bytes_eaten < blob.length) {
754 bytes_left = blob.length - bytes_eaten;
755 identifier = hex_encode_talloc(mem_ctx, &blob.data[bytes_eaten], bytes_left);
756 if (!identifier) goto nomem;
758 *partial_oid = talloc_asprintf_append_buffer(tmp_oid, ":0x%s", identifier);
759 if (!*partial_oid) goto nomem;
760 TALLOC_FREE(identifier);
762 *partial_oid = tmp_oid;
768 TALLOC_FREE(identifier);
769 TALLOC_FREE(tmp_oid);
773 /* read an object ID from a ASN1 buffer */
774 bool asn1_read_OID(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **OID)
779 if (!asn1_start_tag(data, ASN1_OID)) return false;
781 len = asn1_tag_remaining(data);
783 data->has_error = true;
787 blob = data_blob(NULL, len);
789 data->has_error = true;
793 if (!asn1_read(data, blob.data, len)) return false;
794 if (!asn1_end_tag(data)) {
795 data_blob_free(&blob);
799 if (!ber_read_OID_String(mem_ctx, blob, OID)) {
800 data->has_error = true;
801 data_blob_free(&blob);
805 data_blob_free(&blob);
809 /* check that the next object ID is correct */
810 bool asn1_check_OID(struct asn1_data *data, const char *OID)
814 if (!asn1_read_OID(data, data, &id)) return false;
816 if (strcmp(id, OID) != 0) {
818 data->has_error = true;
825 /* read a LDAPString from a ASN1 buffer */
826 bool asn1_read_LDAPString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s)
829 len = asn1_tag_remaining(data);
831 data->has_error = true;
834 *s = talloc_array(mem_ctx, char, len+1);
836 data->has_error = true;
840 return asn1_read(data, *s, len);
844 /* read a GeneralString from a ASN1 buffer */
845 bool asn1_read_GeneralString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s)
847 if (!asn1_start_tag(data, ASN1_GENERAL_STRING)) return false;
848 if (!asn1_read_LDAPString(data, mem_ctx, s)) return false;
849 return asn1_end_tag(data);
853 /* read a octet string blob */
854 bool asn1_read_OctetString(struct asn1_data *data, TALLOC_CTX *mem_ctx, DATA_BLOB *blob)
858 if (!asn1_start_tag(data, ASN1_OCTET_STRING)) return false;
859 len = asn1_tag_remaining(data);
861 data->has_error = true;
864 *blob = data_blob_talloc(mem_ctx, NULL, len+1);
865 if (!blob->data || blob->length < len) {
866 data->has_error = true;
869 if (!asn1_read(data, blob->data, len)) goto err;
870 if (!asn1_end_tag(data)) goto err;
877 data_blob_free(blob);
878 *blob = data_blob_null;
882 bool asn1_read_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *blob)
886 if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(num))) return false;
887 len = asn1_tag_remaining(data);
889 data->has_error = true;
892 *blob = data_blob(NULL, len);
893 if ((len != 0) && (!blob->data)) {
894 data->has_error = true;
897 if (!asn1_read(data, blob->data, len)) return false;
898 return asn1_end_tag(data);
901 /* read an integer without tag*/
902 bool asn1_read_implicit_Integer(struct asn1_data *data, int *i)
905 bool first_byte = true;
908 while (!data->has_error && asn1_tag_remaining(data)>0) {
909 if (!asn1_read_uint8(data, &b)) return false;
912 /* Number is negative.
913 Set i to -1 for sign extend. */
920 return !data->has_error;
924 /* read an integer */
925 bool asn1_read_Integer(struct asn1_data *data, int *i)
929 if (!asn1_start_tag(data, ASN1_INTEGER)) return false;
930 if (!asn1_read_implicit_Integer(data, i)) return false;
931 return asn1_end_tag(data);
934 /* read a BIT STRING */
935 bool asn1_read_BitString(struct asn1_data *data, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, uint8_t *padding)
939 if (!asn1_start_tag(data, ASN1_BIT_STRING)) return false;
940 len = asn1_tag_remaining(data);
942 data->has_error = true;
945 if (!asn1_read_uint8(data, padding)) return false;
947 *blob = data_blob_talloc(mem_ctx, NULL, len+1);
948 if (!blob->data || blob->length < len) {
949 data->has_error = true;
952 if (asn1_read(data, blob->data, len - 1)) {
958 if (data->has_error) {
959 data_blob_free(blob);
960 *blob = data_blob_null;
967 /* read an integer */
968 bool asn1_read_enumerated(struct asn1_data *data, int *v)
972 if (!asn1_start_tag(data, ASN1_ENUMERATED)) return false;
973 while (!data->has_error && asn1_tag_remaining(data)>0) {
975 if (!asn1_read_uint8(data, &b)) {
980 return asn1_end_tag(data);
983 /* check a enumerated value is correct */
984 bool asn1_check_enumerated(struct asn1_data *data, int v)
987 if (!asn1_start_tag(data, ASN1_ENUMERATED)) return false;
988 if (!asn1_read_uint8(data, &b)) return false;
989 if (!asn1_end_tag(data)) return false;
992 data->has_error = false;
994 return !data->has_error;
997 /* write an enumerated value to the stream */
998 bool asn1_write_enumerated(struct asn1_data *data, uint8_t v)
1000 if (!asn1_push_tag(data, ASN1_ENUMERATED)) return false;
1001 if (!asn1_write_uint8(data, v)) return false;
1002 return asn1_pop_tag(data);
1006 Get us the data just written without copying
1008 bool asn1_blob(const struct asn1_data *asn1, DATA_BLOB *blob)
1010 if (asn1->has_error) {
1013 if (asn1->nesting != NULL) {
1016 blob->data = asn1->data;
1017 blob->length = asn1->length;
1021 bool asn1_extract_blob(struct asn1_data *asn1, TALLOC_CTX *mem_ctx,
1026 if (!asn1_blob(asn1, &blob)) {
1030 *pblob = (DATA_BLOB) { .length = blob.length };
1031 pblob->data = talloc_move(mem_ctx, &blob.data);
1034 * Stop access from here on
1036 asn1->has_error = true;
1042 Fill in an asn1 struct without making a copy
1044 void asn1_load_nocopy(struct asn1_data *data, uint8_t *buf, size_t len)
1051 int asn1_peek_full_tag(DATA_BLOB blob, uint8_t tag, size_t *packet_size)
1053 struct asn1_data asn1;
1058 asn1.data = blob.data;
1059 asn1.length = blob.length;
1061 ok = asn1_peek_tag_needed_size(&asn1, tag, &size);
1066 if (size > blob.length) {
1067 *packet_size = size;
1071 *packet_size = size;