2 /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2002 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
60 #include <openssl/asn1.h>
61 #include <openssl/x509v3.h>
63 #define ASN1_GEN_FLAG 0x10000
64 #define ASN1_GEN_FLAG_IMP (ASN1_GEN_FLAG|1)
65 #define ASN1_GEN_FLAG_EXP (ASN1_GEN_FLAG|2)
66 #define ASN1_GEN_FLAG_TAG (ASN1_GEN_FLAG|3)
67 #define ASN1_GEN_FLAG_BITWRAP (ASN1_GEN_FLAG|4)
68 #define ASN1_GEN_FLAG_OCTWRAP (ASN1_GEN_FLAG|5)
69 #define ASN1_GEN_FLAG_SEQWRAP (ASN1_GEN_FLAG|6)
70 #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7)
71 #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8)
73 #define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val}
75 #define ASN1_FLAG_EXP_MAX 20
80 #define ASN1_GEN_FORMAT_ASCII 1
82 #define ASN1_GEN_FORMAT_UTF8 2
84 #define ASN1_GEN_FORMAT_HEX 3
86 #define ASN1_GEN_FORMAT_BITLIST 4
112 tag_exp_type exp_list[ASN1_FLAG_EXP_MAX];
116 static int bitstr_cb(const char *elem, int len, void *bitstr);
117 static int asn1_cb(const char *elem, int len, void *bitstr);
118 static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok);
119 static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass);
120 static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf);
121 static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype);
122 static int asn1_str2tag(const char *tagstr, int len);
124 ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf)
129 return ASN1_generate_v3(str, NULL);
131 X509V3_set_nconf(&cnf, nconf);
132 return ASN1_generate_v3(str, &cnf);
135 ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
138 tag_exp_arg asn1_tags;
143 unsigned char *orig_der = NULL, *new_der = NULL;
144 unsigned char *cpy_start, *p;
147 int hdr_constructed = 0, hdr_tag, hdr_class;
150 asn1_tags.imp_tag = -1;
151 asn1_tags.imp_class = -1;
152 asn1_tags.format = ASN1_GEN_FORMAT_ASCII;
153 asn1_tags.exp_count = 0;
154 if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0)
157 if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET))
161 ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
164 ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf);
167 ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype);
172 /* If no tagging return base type */
173 if ((asn1_tags.imp_tag == -1) && (asn1_tags.exp_count == 0))
176 /* Generate the encoding */
177 cpy_len = i2d_ASN1_TYPE(ret, &orig_der);
180 /* Set point to start copying for modified encoding */
181 cpy_start = orig_der;
183 /* Do we need IMPLICIT tagging? */
184 if (asn1_tags.imp_tag != -1)
186 /* If IMPLICIT we will replace the underlying tag */
187 /* Skip existing tag+len */
188 r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len);
191 /* Update copy length */
192 cpy_len -= cpy_start - orig_der;
193 /* For IMPLICIT tagging the length should match the
194 * original length and constructed flag should be
199 /* Indefinite length constructed */
204 /* Just retain constructed flag */
205 hdr_constructed = r & V_ASN1_CONSTRUCTED;
206 /* Work out new length with IMPLICIT tag: ignore constructed
207 * because it will mess up if indefinite length
209 len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag);
214 /* Work out length in any EXPLICIT, starting from end */
216 for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--)
218 /* Content length: number of content octets + any padding */
219 len += etmp->exp_pad;
221 /* Total object length: length including new header */
222 len = ASN1_object_size(0, len, etmp->exp_tag);
225 /* Allocate buffer for new encoding */
227 new_der = OPENSSL_malloc(len);
229 /* Generate tagged encoding */
233 /* Output explicit tags first */
235 for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++)
237 ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len,
238 etmp->exp_tag, etmp->exp_class);
243 /* If IMPLICIT, output tag */
245 if (asn1_tags.imp_tag != -1)
246 ASN1_put_object(&p, hdr_constructed, hdr_len,
247 asn1_tags.imp_tag, asn1_tags.imp_class);
249 /* Copy across original encoding */
250 memcpy(p, cpy_start, cpy_len);
254 /* Obtain new ASN1_TYPE structure */
255 ret = d2i_ASN1_TYPE(NULL, &p, len);
259 OPENSSL_free(orig_der);
261 OPENSSL_free(new_der);
267 static int asn1_cb(const char *elem, int len, void *bitstr)
269 tag_exp_arg *arg = bitstr;
273 const char *p, *vstart = NULL;
275 int tmp_tag, tmp_class;
277 for(i = 0, p = elem; i < len; p++, i++)
279 /* Look for the ':' in name value pairs */
283 vlen = len - (vstart - elem);
289 utype = asn1_str2tag(elem, len);
293 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG);
294 ERR_add_error_data(2, "tag=", elem);
298 /* If this is not a modifier mark end of string and exit */
299 if (!(utype & ASN1_GEN_FLAG))
303 /* If no value and not end of string, error */
304 if (!vstart && elem[len])
306 ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE);
315 case ASN1_GEN_FLAG_IMP:
316 /* Check for illegal multiple IMPLICIT tagging */
317 if (arg->imp_tag != -1)
319 ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING);
322 if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class))
326 case ASN1_GEN_FLAG_EXP:
328 if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class))
330 if (!append_exp(arg, tmp_tag, tmp_class, 1, 0, 0))
334 case ASN1_GEN_FLAG_SEQWRAP:
335 if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1))
339 case ASN1_GEN_FLAG_SETWRAP:
340 if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1))
344 case ASN1_GEN_FLAG_BITWRAP:
345 if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1))
349 case ASN1_GEN_FLAG_OCTWRAP:
350 if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1))
354 case ASN1_GEN_FLAG_FORMAT:
355 if (!strncmp(vstart, "ASCII", 5))
356 arg->format = ASN1_GEN_FORMAT_ASCII;
357 else if (!strncmp(vstart, "UTF8", 4))
358 arg->format = ASN1_GEN_FORMAT_UTF8;
359 else if (!strncmp(vstart, "HEX", 3))
360 arg->format = ASN1_GEN_FORMAT_HEX;
361 else if (!strncmp(vstart, "BITLIST", 3))
362 arg->format = ASN1_GEN_FORMAT_BITLIST;
365 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT);
376 static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
383 tag_num = strtoul(vstart, &eptr, 10);
384 /* Check we haven't gone past max length: should be impossible */
385 if (eptr && *eptr && (eptr > vstart + vlen))
389 ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER);
393 /* If we have non numeric characters, parse them */
395 vlen -= eptr - vstart;
404 *pclass = V_ASN1_UNIVERSAL;
408 *pclass = V_ASN1_APPLICATION;
412 *pclass = V_ASN1_PRIVATE;
416 *pclass = V_ASN1_CONTEXT_SPECIFIC;
422 ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_MODIFIER);
423 ERR_add_error_data(2, "Char=", erch);
430 *pclass = V_ASN1_CONTEXT_SPECIFIC;
436 /* Handle multiple types: SET and SEQUENCE */
438 static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
440 ASN1_TYPE *ret = NULL, *typ = NULL;
441 STACK_OF(ASN1_TYPE) *sk = NULL;
442 STACK_OF(CONF_VALUE) *sect = NULL;
443 unsigned char *der = NULL, *p;
446 sk = sk_ASN1_TYPE_new_null();
451 sect = X509V3_get_section(cnf, (char *)section);
454 for (i = 0; i < sk_CONF_VALUE_num(sect); i++)
456 typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf);
459 sk_ASN1_TYPE_push(sk, typ);
464 /* Now we has a STACK of the components, convert to the correct form */
466 if (utype == V_ASN1_SET)
472 derlen = i2d_ASN1_SET((STACK *)sk, NULL, i2d_ASN1_TYPE, utype, V_ASN1_UNIVERSAL, is_set);
473 der = OPENSSL_malloc(derlen);
475 i2d_ASN1_SET((STACK *)sk, &p, i2d_ASN1_TYPE, utype, V_ASN1_UNIVERSAL, is_set);
477 if (!(ret = ASN1_TYPE_new()))
480 if (!(ret->value.asn1_string = ASN1_STRING_type_new(utype)))
485 ret->value.asn1_string->data = der;
486 ret->value.asn1_string->length = derlen;
496 sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
500 X509V3_section_free(cnf, sect);
505 static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok)
507 tag_exp_type *exp_tmp;
508 /* Can only have IMPLICIT if permitted */
509 if ((arg->imp_tag != -1) && !imp_ok)
511 ASN1err(ASN1_F_APPEND_TAG, ASN1_R_ILLEGAL_IMPLICIT_TAG);
515 if (arg->exp_count == ASN1_FLAG_EXP_MAX)
517 ASN1err(ASN1_F_APPEND_TAG, ASN1_R_DEPTH_EXCEEDED);
521 exp_tmp = &arg->exp_list[arg->exp_count++];
523 /* If IMPLICIT set tag to implicit value then
524 * reset implicit tag since it has been used.
526 if (arg->imp_tag != -1)
528 exp_tmp->exp_tag = arg->imp_tag;
529 exp_tmp->exp_class = arg->imp_class;
535 exp_tmp->exp_tag = exp_tag;
536 exp_tmp->exp_class = exp_class;
538 exp_tmp->exp_constructed = exp_constructed;
539 exp_tmp->exp_pad = exp_pad;
545 static int asn1_str2tag(const char *tagstr, int len)
548 static struct tag_name_st *tntmp, tnst [] = {
549 ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN),
550 ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN),
551 ASN1_GEN_STR("NULL", V_ASN1_NULL),
552 ASN1_GEN_STR("INT", V_ASN1_INTEGER),
553 ASN1_GEN_STR("INTEGER", V_ASN1_INTEGER),
554 ASN1_GEN_STR("ENUM", V_ASN1_ENUMERATED),
555 ASN1_GEN_STR("ENUMERATED", V_ASN1_ENUMERATED),
556 ASN1_GEN_STR("OID", V_ASN1_OBJECT),
557 ASN1_GEN_STR("OBJECT", V_ASN1_OBJECT),
558 ASN1_GEN_STR("UTCTIME", V_ASN1_UTCTIME),
559 ASN1_GEN_STR("UTC", V_ASN1_UTCTIME),
560 ASN1_GEN_STR("GENERALIZEDTIME", V_ASN1_GENERALIZEDTIME),
561 ASN1_GEN_STR("GENTIME", V_ASN1_GENERALIZEDTIME),
562 ASN1_GEN_STR("OCT", V_ASN1_OCTET_STRING),
563 ASN1_GEN_STR("OCTETSTRING", V_ASN1_OCTET_STRING),
564 ASN1_GEN_STR("BITSTR", V_ASN1_BIT_STRING),
565 ASN1_GEN_STR("BITSTRING", V_ASN1_BIT_STRING),
566 ASN1_GEN_STR("UNIVERSALSTRING", V_ASN1_UNIVERSALSTRING),
567 ASN1_GEN_STR("UNIV", V_ASN1_UNIVERSALSTRING),
568 ASN1_GEN_STR("IA5", V_ASN1_IA5STRING),
569 ASN1_GEN_STR("IA5STRING", V_ASN1_IA5STRING),
570 ASN1_GEN_STR("UTF8", V_ASN1_UTF8STRING),
571 ASN1_GEN_STR("UTF8String", V_ASN1_UTF8STRING),
572 ASN1_GEN_STR("BMP", V_ASN1_BMPSTRING),
573 ASN1_GEN_STR("BMPSTRING", V_ASN1_BMPSTRING),
574 ASN1_GEN_STR("VISIBLESTRING", V_ASN1_VISIBLESTRING),
575 ASN1_GEN_STR("VISIBLE", V_ASN1_VISIBLESTRING),
576 ASN1_GEN_STR("PRINTABLESTRING", V_ASN1_PRINTABLESTRING),
577 ASN1_GEN_STR("PRINTABLE", V_ASN1_PRINTABLESTRING),
578 ASN1_GEN_STR("T61", V_ASN1_T61STRING),
579 ASN1_GEN_STR("T61STRING", V_ASN1_T61STRING),
580 ASN1_GEN_STR("TELETEXSTRING", V_ASN1_T61STRING),
583 ASN1_GEN_STR("SEQUENCE", V_ASN1_SEQUENCE),
584 ASN1_GEN_STR("SEQ", V_ASN1_SEQUENCE),
585 ASN1_GEN_STR("SET", V_ASN1_SET),
588 ASN1_GEN_STR("EXP", ASN1_GEN_FLAG_EXP),
589 ASN1_GEN_STR("EXPLICIT", ASN1_GEN_FLAG_EXP),
591 ASN1_GEN_STR("IMP", ASN1_GEN_FLAG_IMP),
592 ASN1_GEN_STR("IMPLICIT", ASN1_GEN_FLAG_IMP),
593 /* OCTET STRING wrapper */
594 ASN1_GEN_STR("OCTWRAP", ASN1_GEN_FLAG_OCTWRAP),
595 /* SEQUENCE wrapper */
596 ASN1_GEN_STR("SEQWRAP", ASN1_GEN_FLAG_SEQWRAP),
598 ASN1_GEN_STR("SETWRAP", ASN1_GEN_FLAG_SEQWRAP),
599 /* BIT STRING wrapper */
600 ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP),
601 ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT),
602 ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT),
606 len = strlen(tagstr);
609 for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++)
611 if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len))
618 static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
620 ASN1_TYPE *atmp = NULL;
624 unsigned char *rdata;
629 if (!(atmp = ASN1_TYPE_new()))
631 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
644 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE);
650 if (format != ASN1_GEN_FORMAT_ASCII)
652 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT);
655 vtmp.value = (char *)str;
656 if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean))
658 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN);
664 case V_ASN1_ENUMERATED:
665 if (format != ASN1_GEN_FORMAT_ASCII)
667 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT);
670 if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str)))
672 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER);
678 if (format != ASN1_GEN_FORMAT_ASCII)
680 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT);
683 if (!(atmp->value.object = OBJ_txt2obj(str, 0)))
685 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT);
691 case V_ASN1_GENERALIZEDTIME:
692 if (format != ASN1_GEN_FORMAT_ASCII)
694 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT);
697 if (!(atmp->value.asn1_string = ASN1_STRING_new()))
699 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
702 if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1))
704 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
707 atmp->value.asn1_string->type = utype;
708 if (!ASN1_TIME_check(atmp->value.asn1_string))
710 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE);
716 case V_ASN1_BMPSTRING:
717 case V_ASN1_PRINTABLESTRING:
718 case V_ASN1_IA5STRING:
719 case V_ASN1_T61STRING:
720 case V_ASN1_UTF8STRING:
721 case V_ASN1_VISIBLESTRING:
722 case V_ASN1_UNIVERSALSTRING:
724 if (format == ASN1_GEN_FORMAT_ASCII)
725 format = MBSTRING_ASC;
726 else if (format == ASN1_GEN_FORMAT_UTF8)
727 format = MBSTRING_UTF8;
730 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT);
735 if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,
736 -1, format, ASN1_tag2bit(utype)) <= 0)
738 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
745 case V_ASN1_BIT_STRING:
747 case V_ASN1_OCTET_STRING:
749 if (!(atmp->value.asn1_string = ASN1_STRING_new()))
751 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
755 if (format == ASN1_GEN_FORMAT_HEX)
758 if (!(rdata = string_to_hex((char *)str, &rdlen)))
760 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX);
764 atmp->value.asn1_string->data = rdata;
765 atmp->value.asn1_string->length = rdlen;
766 atmp->value.asn1_string->type = utype;
769 else if (format == ASN1_GEN_FORMAT_ASCII)
770 ASN1_STRING_set(atmp->value.asn1_string, str, -1);
771 else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING))
773 if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string))
775 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR);
783 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT);
787 if ((utype == V_ASN1_BIT_STRING) && no_unused)
789 atmp->value.asn1_string->flags
790 &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
791 atmp->value.asn1_string->flags
792 |= ASN1_STRING_FLAG_BITS_LEFT;
799 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE);
810 ERR_add_error_data(2, "string=", str);
813 ASN1_TYPE_free(atmp);
818 static int bitstr_cb(const char *elem, int len, void *bitstr)
824 bitnum = strtoul(elem, &eptr, 10);
825 if (eptr && *eptr && (eptr != elem + len))
829 ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER);
832 if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1))
834 ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE);