2 * Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include "internal/cryptlib.h"
11 #include <openssl/asn1.h>
12 #include <openssl/x509v3.h>
14 #define ASN1_GEN_FLAG 0x10000
15 #define ASN1_GEN_FLAG_IMP (ASN1_GEN_FLAG|1)
16 #define ASN1_GEN_FLAG_EXP (ASN1_GEN_FLAG|2)
17 #define ASN1_GEN_FLAG_TAG (ASN1_GEN_FLAG|3)
18 #define ASN1_GEN_FLAG_BITWRAP (ASN1_GEN_FLAG|4)
19 #define ASN1_GEN_FLAG_OCTWRAP (ASN1_GEN_FLAG|5)
20 #define ASN1_GEN_FLAG_SEQWRAP (ASN1_GEN_FLAG|6)
21 #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7)
22 #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8)
24 #define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val}
26 DEFINE_STACK_OF(ASN1_TYPE)
27 DEFINE_STACK_OF(CONF_VALUE)
29 #define ASN1_FLAG_EXP_MAX 20
30 /* Maximum number of nested sequences */
31 #define ASN1_GEN_SEQ_MAX_DEPTH 50
36 #define ASN1_GEN_FORMAT_ASCII 1
38 #define ASN1_GEN_FORMAT_UTF8 2
40 #define ASN1_GEN_FORMAT_HEX 3
42 #define ASN1_GEN_FORMAT_BITLIST 4
64 tag_exp_type exp_list[ASN1_FLAG_EXP_MAX];
68 static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth,
70 static int bitstr_cb(const char *elem, int len, void *bitstr);
71 static int asn1_cb(const char *elem, int len, void *bitstr);
72 static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class,
73 int exp_constructed, int exp_pad, int imp_ok);
74 static int parse_tagging(const char *vstart, int vlen, int *ptag,
76 static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
77 int depth, int *perr);
78 static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype);
79 static int asn1_str2tag(const char *tagstr, int len);
81 ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf)
86 return ASN1_generate_v3(str, NULL);
88 X509V3_set_nconf(&cnf, nconf);
89 return ASN1_generate_v3(str, &cnf);
92 ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf)
95 ASN1_TYPE *ret = generate_v3(str, cnf, 0, &err);
97 ASN1err(ASN1_F_ASN1_GENERATE_V3, err);
101 static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth,
105 tag_exp_arg asn1_tags;
110 unsigned char *orig_der = NULL, *new_der = NULL;
111 const unsigned char *cpy_start;
113 const unsigned char *cp;
116 int hdr_constructed = 0, hdr_tag, hdr_class;
119 asn1_tags.imp_tag = -1;
120 asn1_tags.imp_class = -1;
121 asn1_tags.format = ASN1_GEN_FORMAT_ASCII;
122 asn1_tags.exp_count = 0;
123 if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) {
124 *perr = ASN1_R_UNKNOWN_TAG;
128 if ((asn1_tags.utype == V_ASN1_SEQUENCE)
129 || (asn1_tags.utype == V_ASN1_SET)) {
131 *perr = ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG;
134 if (depth >= ASN1_GEN_SEQ_MAX_DEPTH) {
135 *perr = ASN1_R_ILLEGAL_NESTED_TAGGING;
138 ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf, depth, perr);
140 ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype);
145 /* If no tagging return base type */
146 if ((asn1_tags.imp_tag == -1) && (asn1_tags.exp_count == 0))
149 /* Generate the encoding */
150 cpy_len = i2d_ASN1_TYPE(ret, &orig_der);
153 /* Set point to start copying for modified encoding */
154 cpy_start = orig_der;
156 /* Do we need IMPLICIT tagging? */
157 if (asn1_tags.imp_tag != -1) {
158 /* If IMPLICIT we will replace the underlying tag */
159 /* Skip existing tag+len */
160 r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class,
164 /* Update copy length */
165 cpy_len -= cpy_start - orig_der;
167 * For IMPLICIT tagging the length should match the original length
168 * and constructed flag should be consistent.
171 /* Indefinite length constructed */
175 /* Just retain constructed flag */
176 hdr_constructed = r & V_ASN1_CONSTRUCTED;
178 * Work out new length with IMPLICIT tag: ignore constructed because
179 * it will mess up if indefinite length
181 len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag);
185 /* Work out length in any EXPLICIT, starting from end */
187 for (i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1;
188 i < asn1_tags.exp_count; i++, etmp--) {
189 /* Content length: number of content octets + any padding */
190 len += etmp->exp_pad;
192 /* Total object length: length including new header */
193 len = ASN1_object_size(0, len, etmp->exp_tag);
196 /* Allocate buffer for new encoding */
198 new_der = OPENSSL_malloc(len);
202 /* Generate tagged encoding */
206 /* Output explicit tags first */
208 for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count;
210 ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len,
211 etmp->exp_tag, etmp->exp_class);
216 /* If IMPLICIT, output tag */
218 if (asn1_tags.imp_tag != -1) {
219 if (asn1_tags.imp_class == V_ASN1_UNIVERSAL
220 && (asn1_tags.imp_tag == V_ASN1_SEQUENCE
221 || asn1_tags.imp_tag == V_ASN1_SET))
222 hdr_constructed = V_ASN1_CONSTRUCTED;
223 ASN1_put_object(&p, hdr_constructed, hdr_len,
224 asn1_tags.imp_tag, asn1_tags.imp_class);
227 /* Copy across original encoding */
228 memcpy(p, cpy_start, cpy_len);
232 /* Obtain new ASN1_TYPE structure */
233 ret = d2i_ASN1_TYPE(NULL, &cp, len);
236 OPENSSL_free(orig_der);
237 OPENSSL_free(new_der);
243 static int asn1_cb(const char *elem, int len, void *bitstr)
245 tag_exp_arg *arg = bitstr;
249 const char *p, *vstart = NULL;
251 int tmp_tag, tmp_class;
256 for (i = 0, p = elem; i < len; p++, i++) {
257 /* Look for the ':' in name value pairs */
260 vlen = len - (vstart - elem);
266 utype = asn1_str2tag(elem, len);
269 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG);
270 ERR_add_error_data(2, "tag=", elem);
274 /* If this is not a modifier mark end of string and exit */
275 if (!(utype & ASN1_GEN_FLAG)) {
278 /* If no value and not end of string, error */
279 if (!vstart && elem[len]) {
280 ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE);
288 case ASN1_GEN_FLAG_IMP:
289 /* Check for illegal multiple IMPLICIT tagging */
290 if (arg->imp_tag != -1) {
291 ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING);
294 if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class))
298 case ASN1_GEN_FLAG_EXP:
300 if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class))
302 if (!append_exp(arg, tmp_tag, tmp_class, 1, 0, 0))
306 case ASN1_GEN_FLAG_SEQWRAP:
307 if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1))
311 case ASN1_GEN_FLAG_SETWRAP:
312 if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1))
316 case ASN1_GEN_FLAG_BITWRAP:
317 if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1))
321 case ASN1_GEN_FLAG_OCTWRAP:
322 if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1))
326 case ASN1_GEN_FLAG_FORMAT:
328 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_FORMAT);
331 if (strncmp(vstart, "ASCII", 5) == 0)
332 arg->format = ASN1_GEN_FORMAT_ASCII;
333 else if (strncmp(vstart, "UTF8", 4) == 0)
334 arg->format = ASN1_GEN_FORMAT_UTF8;
335 else if (strncmp(vstart, "HEX", 3) == 0)
336 arg->format = ASN1_GEN_FORMAT_HEX;
337 else if (strncmp(vstart, "BITLIST", 7) == 0)
338 arg->format = ASN1_GEN_FORMAT_BITLIST;
340 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_FORMAT);
351 static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
358 tag_num = strtoul(vstart, &eptr, 10);
359 /* Check we haven't gone past max length: should be impossible */
360 if (eptr && *eptr && (eptr > vstart + vlen))
363 ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER);
367 /* If we have non numeric characters, parse them */
369 vlen -= eptr - vstart;
376 *pclass = V_ASN1_UNIVERSAL;
380 *pclass = V_ASN1_APPLICATION;
384 *pclass = V_ASN1_PRIVATE;
388 *pclass = V_ASN1_CONTEXT_SPECIFIC;
394 ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_MODIFIER);
395 ERR_add_error_data(2, "Char=", erch);
400 *pclass = V_ASN1_CONTEXT_SPECIFIC;
406 /* Handle multiple types: SET and SEQUENCE */
408 static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
409 int depth, int *perr)
411 ASN1_TYPE *ret = NULL;
412 STACK_OF(ASN1_TYPE) *sk = NULL;
413 STACK_OF(CONF_VALUE) *sect = NULL;
414 unsigned char *der = NULL;
417 sk = sk_ASN1_TYPE_new_null();
423 sect = X509V3_get_section(cnf, (char *)section);
426 for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
428 generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf,
432 if (!sk_ASN1_TYPE_push(sk, typ))
438 * Now we has a STACK of the components, convert to the correct form
441 if (utype == V_ASN1_SET)
442 derlen = i2d_ASN1_SET_ANY(sk, &der);
444 derlen = i2d_ASN1_SEQUENCE_ANY(sk, &der);
448 if ((ret = ASN1_TYPE_new()) == NULL)
450 if ((ret->value.asn1_string = ASN1_STRING_type_new(utype)) == NULL)
454 ret->value.asn1_string->data = der;
455 ret->value.asn1_string->length = derlen;
463 sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
464 X509V3_section_free(cnf, sect);
469 static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class,
470 int exp_constructed, int exp_pad, int imp_ok)
472 tag_exp_type *exp_tmp;
473 /* Can only have IMPLICIT if permitted */
474 if ((arg->imp_tag != -1) && !imp_ok) {
475 ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG);
479 if (arg->exp_count == ASN1_FLAG_EXP_MAX) {
480 ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED);
484 exp_tmp = &arg->exp_list[arg->exp_count++];
487 * If IMPLICIT set tag to implicit value then reset implicit tag since it
490 if (arg->imp_tag != -1) {
491 exp_tmp->exp_tag = arg->imp_tag;
492 exp_tmp->exp_class = arg->imp_class;
496 exp_tmp->exp_tag = exp_tag;
497 exp_tmp->exp_class = exp_class;
499 exp_tmp->exp_constructed = exp_constructed;
500 exp_tmp->exp_pad = exp_pad;
505 static int asn1_str2tag(const char *tagstr, int len)
508 static const struct tag_name_st *tntmp, tnst[] = {
509 ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN),
510 ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN),
511 ASN1_GEN_STR("NULL", V_ASN1_NULL),
512 ASN1_GEN_STR("INT", V_ASN1_INTEGER),
513 ASN1_GEN_STR("INTEGER", V_ASN1_INTEGER),
514 ASN1_GEN_STR("ENUM", V_ASN1_ENUMERATED),
515 ASN1_GEN_STR("ENUMERATED", V_ASN1_ENUMERATED),
516 ASN1_GEN_STR("OID", V_ASN1_OBJECT),
517 ASN1_GEN_STR("OBJECT", V_ASN1_OBJECT),
518 ASN1_GEN_STR("UTCTIME", V_ASN1_UTCTIME),
519 ASN1_GEN_STR("UTC", V_ASN1_UTCTIME),
520 ASN1_GEN_STR("GENERALIZEDTIME", V_ASN1_GENERALIZEDTIME),
521 ASN1_GEN_STR("GENTIME", V_ASN1_GENERALIZEDTIME),
522 ASN1_GEN_STR("OCT", V_ASN1_OCTET_STRING),
523 ASN1_GEN_STR("OCTETSTRING", V_ASN1_OCTET_STRING),
524 ASN1_GEN_STR("BITSTR", V_ASN1_BIT_STRING),
525 ASN1_GEN_STR("BITSTRING", V_ASN1_BIT_STRING),
526 ASN1_GEN_STR("UNIVERSALSTRING", V_ASN1_UNIVERSALSTRING),
527 ASN1_GEN_STR("UNIV", V_ASN1_UNIVERSALSTRING),
528 ASN1_GEN_STR("IA5", V_ASN1_IA5STRING),
529 ASN1_GEN_STR("IA5STRING", V_ASN1_IA5STRING),
530 ASN1_GEN_STR("UTF8", V_ASN1_UTF8STRING),
531 ASN1_GEN_STR("UTF8String", V_ASN1_UTF8STRING),
532 ASN1_GEN_STR("BMP", V_ASN1_BMPSTRING),
533 ASN1_GEN_STR("BMPSTRING", V_ASN1_BMPSTRING),
534 ASN1_GEN_STR("VISIBLESTRING", V_ASN1_VISIBLESTRING),
535 ASN1_GEN_STR("VISIBLE", V_ASN1_VISIBLESTRING),
536 ASN1_GEN_STR("PRINTABLESTRING", V_ASN1_PRINTABLESTRING),
537 ASN1_GEN_STR("PRINTABLE", V_ASN1_PRINTABLESTRING),
538 ASN1_GEN_STR("T61", V_ASN1_T61STRING),
539 ASN1_GEN_STR("T61STRING", V_ASN1_T61STRING),
540 ASN1_GEN_STR("TELETEXSTRING", V_ASN1_T61STRING),
541 ASN1_GEN_STR("GeneralString", V_ASN1_GENERALSTRING),
542 ASN1_GEN_STR("GENSTR", V_ASN1_GENERALSTRING),
543 ASN1_GEN_STR("NUMERIC", V_ASN1_NUMERICSTRING),
544 ASN1_GEN_STR("NUMERICSTRING", V_ASN1_NUMERICSTRING),
547 ASN1_GEN_STR("SEQUENCE", V_ASN1_SEQUENCE),
548 ASN1_GEN_STR("SEQ", V_ASN1_SEQUENCE),
549 ASN1_GEN_STR("SET", V_ASN1_SET),
552 ASN1_GEN_STR("EXP", ASN1_GEN_FLAG_EXP),
553 ASN1_GEN_STR("EXPLICIT", ASN1_GEN_FLAG_EXP),
555 ASN1_GEN_STR("IMP", ASN1_GEN_FLAG_IMP),
556 ASN1_GEN_STR("IMPLICIT", ASN1_GEN_FLAG_IMP),
557 /* OCTET STRING wrapper */
558 ASN1_GEN_STR("OCTWRAP", ASN1_GEN_FLAG_OCTWRAP),
559 /* SEQUENCE wrapper */
560 ASN1_GEN_STR("SEQWRAP", ASN1_GEN_FLAG_SEQWRAP),
562 ASN1_GEN_STR("SETWRAP", ASN1_GEN_FLAG_SETWRAP),
563 /* BIT STRING wrapper */
564 ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP),
565 ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT),
566 ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT),
570 len = strlen(tagstr);
573 for (i = 0; i < OSSL_NELEM(tnst); i++, tntmp++) {
574 if ((len == tntmp->len) && (strncmp(tntmp->strnam, tagstr, len) == 0))
581 static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
583 ASN1_TYPE *atmp = NULL;
585 unsigned char *rdata;
589 if ((atmp = ASN1_TYPE_new()) == NULL) {
590 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
601 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE);
607 if (format != ASN1_GEN_FORMAT_ASCII) {
608 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT);
613 vtmp.value = (char *)str;
614 if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) {
615 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN);
621 case V_ASN1_ENUMERATED:
622 if (format != ASN1_GEN_FORMAT_ASCII) {
623 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT);
626 if ((atmp->value.integer
627 = s2i_ASN1_INTEGER(NULL, str)) == NULL) {
628 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER);
634 if (format != ASN1_GEN_FORMAT_ASCII) {
635 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT);
638 if ((atmp->value.object = OBJ_txt2obj(str, 0)) == NULL) {
639 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT);
645 case V_ASN1_GENERALIZEDTIME:
646 if (format != ASN1_GEN_FORMAT_ASCII) {
647 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT);
650 if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) {
651 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
654 if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) {
655 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
658 atmp->value.asn1_string->type = utype;
659 if (!ASN1_TIME_check(atmp->value.asn1_string)) {
660 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE);
666 case V_ASN1_BMPSTRING:
667 case V_ASN1_PRINTABLESTRING:
668 case V_ASN1_IA5STRING:
669 case V_ASN1_T61STRING:
670 case V_ASN1_UTF8STRING:
671 case V_ASN1_VISIBLESTRING:
672 case V_ASN1_UNIVERSALSTRING:
673 case V_ASN1_GENERALSTRING:
674 case V_ASN1_NUMERICSTRING:
675 if (format == ASN1_GEN_FORMAT_ASCII)
676 format = MBSTRING_ASC;
677 else if (format == ASN1_GEN_FORMAT_UTF8)
678 format = MBSTRING_UTF8;
680 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT);
684 if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,
685 -1, format, ASN1_tag2bit(utype)) <= 0) {
686 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
692 case V_ASN1_BIT_STRING:
693 case V_ASN1_OCTET_STRING:
694 if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) {
695 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
699 if (format == ASN1_GEN_FORMAT_HEX) {
700 if ((rdata = OPENSSL_hexstr2buf(str, &rdlen)) == NULL) {
701 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX);
704 atmp->value.asn1_string->data = rdata;
705 atmp->value.asn1_string->length = rdlen;
706 atmp->value.asn1_string->type = utype;
707 } else if (format == ASN1_GEN_FORMAT_ASCII)
708 ASN1_STRING_set(atmp->value.asn1_string, str, -1);
709 else if ((format == ASN1_GEN_FORMAT_BITLIST)
710 && (utype == V_ASN1_BIT_STRING)) {
712 (str, ',', 1, bitstr_cb, atmp->value.bit_string)) {
713 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR);
719 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT);
723 if ((utype == V_ASN1_BIT_STRING) && no_unused) {
724 atmp->value.asn1_string->flags
725 &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
726 atmp->value.asn1_string->flags |= ASN1_STRING_FLAG_BITS_LEFT;
732 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE);
740 ERR_add_error_data(2, "string=", str);
743 ASN1_TYPE_free(atmp);
748 static int bitstr_cb(const char *elem, int len, void *bitstr)
754 bitnum = strtoul(elem, &eptr, 10);
755 if (eptr && *eptr && (eptr != elem + len))
758 ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER);
761 if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
762 ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE);
768 static int mask_cb(const char *elem, int len, void *arg)
770 unsigned long *pmask = arg, tmpmask;
774 if ((len == 3) && (strncmp(elem, "DIR", 3) == 0)) {
775 *pmask |= B_ASN1_DIRECTORYSTRING;
778 tag = asn1_str2tag(elem, len);
779 if (!tag || (tag & ASN1_GEN_FLAG))
781 tmpmask = ASN1_tag2bit(tag);
788 int ASN1_str2mask(const char *str, unsigned long *pmask)
791 return CONF_parse_list(str, '|', 1, mask_cb, pmask);