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
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);
121 static ASN1_TYPE *asn1_str2type(
const char *str,
int format,
int utype);
122 static int asn1_str2tag(
const char *tagstr,
int len);
143 unsigned char *orig_der = NULL, *new_der = NULL;
144 const unsigned char *cpy_start;
146 const unsigned char *cp;
149 int hdr_constructed = 0, hdr_tag, hdr_class;
166 ret = asn1_multi(asn1_tags.
utype, asn1_tags.
str, cnf);
169 ret = asn1_str2type(asn1_tags.
str, asn1_tags.
format, asn1_tags.
utype);
179 cpy_len = i2d_ASN1_TYPE(ret, &orig_der);
183 cpy_start = orig_der;
190 r =
ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len);
194 cpy_len -= cpy_start - orig_der;
260 memcpy(p, cpy_start, cpy_len);
265 ret = d2i_ASN1_TYPE(NULL, &cp, len);
277 static int asn1_cb(
const char *elem,
int len,
void *bitstr)
283 const char *
p, *vstart = NULL;
285 int tmp_tag, tmp_class;
287 for(i = 0, p = elem; i <
len; p++, i++)
293 vlen = len - (vstart - elem);
299 utype = asn1_str2tag(elem, len);
314 if (!vstart && elem[len])
338 if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class))
340 if (!append_exp(arg, tmp_tag, tmp_class, 1, 0, 0))
365 if (!strncmp(vstart,
"ASCII", 5))
367 else if (!strncmp(vstart,
"UTF8", 4))
369 else if (!strncmp(vstart,
"HEX", 3))
371 else if (!strncmp(vstart,
"BITLIST", 3))
386 static int parse_tagging(
const char *vstart,
int vlen,
int *ptag,
int *pclass)
393 tag_num = strtoul(vstart, &eptr, 10);
395 if (eptr && *eptr && (eptr > vstart + vlen))
405 vlen -= eptr - vstart;
453 unsigned char *der = NULL;
463 sect = X509V3_get_section(cnf, (
char *)section);
479 derlen = i2d_ASN1_SET_ANY(sk, &der);
481 derlen = i2d_ASN1_SEQUENCE_ANY(sk, &der);
486 if (!(ret = ASN1_TYPE_new()))
512 static int append_exp(
tag_exp_arg *arg,
int exp_tag,
int exp_class,
int exp_constructed,
int exp_pad,
int imp_ok)
516 if ((arg->
imp_tag != -1) && !imp_ok)
552 static int asn1_str2tag(
const char *tagstr,
int len)
555 static const struct tag_name_st *tntmp, tnst [] = {
617 len = strlen(tagstr);
620 for (i = 0; i <
sizeof(tnst) /
sizeof(
struct tag_name_st); i++, tntmp++)
622 if ((len == tntmp->
len) && !strncmp(tntmp->
strnam, tagstr, len))
629 static ASN1_TYPE *asn1_str2type(
const char *str,
int format,
int utype)
635 unsigned char *rdata;
640 if (!(atmp = ASN1_TYPE_new()))
668 vtmp.
value = (
char *)str;
828 ASN1_TYPE_free(atmp);
833 static int bitstr_cb(
const char *elem,
int len,
void *bitstr)
839 bitnum = strtoul(elem, &eptr, 10);
840 if (eptr && *eptr && (eptr != elem + len))