inner structures tagging fix. see 0.9.5 comment in ChangeLog

This commit is contained in:
Lev Walkin 2004-09-13 08:31:01 +00:00
parent d563d39768
commit 188ed2c714
43 changed files with 588 additions and 150 deletions

View File

@ -15,7 +15,7 @@ uint8_t buf1[] = {
2, /* L */
150,
70,
/* b BOOLEAN */
/* b [2] IMPLICIT BOOLEAN */
128 | 2, /* [2] */
1, /* L */
0xff,
@ -26,30 +26,35 @@ uint8_t buf1[] = {
10, /* [UNIVERSAL 10] */
1, /* L */
222,
/* e OCTET STRING */
4, /* [UNIVERSAL 4] */
3, /* L */
'x',
'y',
'z',
/* f OCTET STRING */
32 | 4, /* [UNIVERSAL 4], constructed */
/*
* X.690 specifies that inner structures must be tagged by
* stripping off the outer tag for each subsequent level.
*/
/* f [5] IMPLICIT VisibleString */
128 | 32 | 5, /* [5], constructed */
128, /* L indefinite */
4, /* [UNIVERSAL 4], primitive */
26, /* [UNIVERSAL 26] (VisibleString), primitive */
2,
'l',
'o',
32 | 4, /* [UNIVERSAL 4], recursively constructed */
32 | 26, /* [UNIVERSAL 26], recursively constructed */
128,
4,
4, /* [UNIVERSAL 4] (OCTET STRING), primitive */
1,
'v',
4,
4, /* [UNIVERSAL 4], primitive */
2,
'e',
'_',
0,
0,
4, /* [UNIVERSAL 4], primitive */
26, /* [UNIVERSAL 26], primitive */
2,
'i',
't',
@ -61,8 +66,8 @@ uint8_t buf1[] = {
2, /* Skip 2 bits */
147,
150, /* => 148 */
/* h BIT STRING */
32 | 3, /* [UNIVERSAL 3], constructed */
/* h [7] BIT STRING */
128 | 32 | 7, /* [7], constructed */
128, /* L indefinite */
3, /* [UNIVERSAL 3], primitive */
3, /* L */
@ -73,7 +78,7 @@ uint8_t buf1[] = {
2, /* L */
1, /* Skip 1 bit */
143, /* => 142 */
0, /* End of f */
0, /* End of h */
0,
0, /* End of the whole structure */
0,

View File

@ -29,9 +29,15 @@ static int check_if_extensible(asn1p_expr_t *expr);
static int expr_better_indirect(arg_t *arg, asn1p_expr_t *expr);
static int expr_elements_count(arg_t *arg, asn1p_expr_t *expr);
static int emit_member_table(arg_t *arg, asn1p_expr_t *expr);
static int emit_tags_vector(arg_t *arg, asn1p_expr_t *expr);
static int emit_tag2member_map(arg_t *arg, tag2el_t *tag2el, int tag2el_count);
enum tvm_compat {
_TVM_SAME = 0, /* tags and all_tags are same */
_TVM_SUBSET = 1, /* tags are subset of all_tags */
_TVM_DIFFERENT = 2, /* tags and all_tags are different */
};
static enum tvm_compat emit_tags_vectors(arg_t *arg, asn1p_expr_t *expr, int *tc, int *atc);
enum etd_cp {
ETD_CP_UNKNOWN = -2,
ETD_CP_EITHER = -1,
@ -42,7 +48,7 @@ enum etd_spec {
ETD_NO_SPECIFICS,
ETD_HAS_SPECIFICS
};
static int emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, int tags_count, int elements_count, enum etd_cp, enum etd_spec);
static int emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_count, int all_tags_count, int elements_count, enum etd_cp, enum etd_spec);
#define C99_MODE (!(arg->flags & A1C_NO_C99))
#define UNNAMED_UNIONS (arg->flags & A1C_UNNAMED_UNIONS)
@ -175,6 +181,8 @@ asn1c_lang_C_type_SEQUENCE_def(arg_t *arg) {
tag2el_t *tag2el = NULL;
int tag2el_count = 0;
int tags_count;
int all_tags_count;
enum tvm_compat tv_mode;
char *p;
/*
@ -212,9 +220,9 @@ asn1c_lang_C_type_SEQUENCE_def(arg_t *arg) {
OUT("};\n");
/*
* Print out asn1_DEF_<type>_tags[] vector.
* Print out asn1_DEF_<type>_[all_]tags[] vectors.
*/
tags_count = emit_tags_vector(arg, expr);
tv_mode = emit_tags_vectors(arg, expr, &tags_count, &all_tags_count);
/*
* Tags to elements map.
@ -238,7 +246,7 @@ asn1c_lang_C_type_SEQUENCE_def(arg_t *arg) {
/*
* Emit asn1_DEF_xxx table.
*/
emit_type_DEF(arg, expr, tags_count, elements,
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count, elements,
ETD_CP_CONSTRUCTED, ETD_HAS_SPECIFICS);
REDIR(OT_TYPE_DECLS);
@ -322,6 +330,8 @@ asn1c_lang_C_type_SET_def(arg_t *arg) {
tag2el_t *tag2el = NULL;
int tag2el_count = 0;
int tags_count;
int all_tags_count;
enum tvm_compat tv_mode;
char *p;
/*
@ -359,9 +369,9 @@ asn1c_lang_C_type_SET_def(arg_t *arg) {
OUT("};\n");
/*
* Print out asn1_DEF_<type>_tags[] vector.
* Print out asn1_DEF_<type>_[all_]tags[] vectors.
*/
tags_count = emit_tags_vector(arg, expr);
tv_mode = emit_tags_vectors(arg, expr, &tags_count, &all_tags_count);
/*
* Tags to elements map.
@ -417,7 +427,7 @@ asn1c_lang_C_type_SET_def(arg_t *arg) {
/*
* Emit asn1_DEF_xxx table.
*/
emit_type_DEF(arg, expr, tags_count, elements,
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count, elements,
ETD_CP_CONSTRUCTED, ETD_HAS_SPECIFICS);
REDIR(OT_TYPE_DECLS);
@ -483,6 +493,8 @@ asn1c_lang_C_type_SEx_OF_def(arg_t *arg, int seq_of) {
asn1p_expr_t *expr = arg->expr;
asn1p_expr_t *v;
int tags_count;
int all_tags_count;
enum tvm_compat tv_mode;
char *p;
/*
@ -511,9 +523,9 @@ asn1c_lang_C_type_SEx_OF_def(arg_t *arg, int seq_of) {
OUT("};\n");
/*
* Print out asn1_DEF_<type>_tags[] vector.
* Print out asn1_DEF_<type>_[all_]tags[] vectors.
*/
tags_count = emit_tags_vector(arg, expr);
tv_mode = emit_tags_vectors(arg, expr, &tags_count, &all_tags_count);
p = MKID(expr->Identifier);
OUT("static asn1_SET_OF_specifics_t asn1_DEF_%s_specs = {\n", p);
@ -526,7 +538,7 @@ asn1c_lang_C_type_SEx_OF_def(arg_t *arg, int seq_of) {
/*
* Emit asn1_DEF_xxx table.
*/
emit_type_DEF(arg, expr, tags_count, 1,
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count, 1,
ETD_CP_CONSTRUCTED, ETD_HAS_SPECIFICS);
REDIR(OT_TYPE_DECLS);
@ -600,6 +612,8 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) {
tag2el_t *tag2el = NULL;
int tag2el_count = 0;
int tags_count;
int all_tags_count;
enum tvm_compat tv_mode;
char *p;
/*
@ -641,9 +655,11 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) {
/*
* Our parent structure has already taken this into account.
*/
tags_count = 0;
tv_mode = _TVM_SAME;
tags_count = all_tags_count = 0;
} else {
tags_count = emit_tags_vector(arg, expr);
tv_mode = emit_tags_vectors(arg, expr,
&tags_count, &all_tags_count);
}
/*
@ -668,7 +684,7 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) {
/*
* Emit asn1_DEF_xxx table.
*/
emit_type_DEF(arg, expr, tags_count, elements,
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count, elements,
ETD_CP_CONSTRUCTED /*either?!*/, ETD_HAS_SPECIFICS);
REDIR(OT_TYPE_DECLS);
@ -724,6 +740,8 @@ int
asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
asn1p_expr_t *expr = arg->expr;
int tags_count;
int all_tags_count;
enum tvm_compat tv_mode;
char *p;
if(arg->embed) {
@ -754,11 +772,11 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
REDIR(OT_STAT_DEFS);
/*
* Print out asn1_DEF_<type>_tags[] vector.
* Print out asn1_DEF_<type>_[all_]tags[] vectors.
*/
tags_count = emit_tags_vector(arg, expr);
tv_mode = emit_tags_vectors(arg, expr, &tags_count, &all_tags_count);
emit_type_DEF(arg, expr, tags_count, 0,
emit_type_DEF(arg, expr, tv_mode, tags_count, all_tags_count, 0,
ETD_CP_UNKNOWN, ETD_NO_SPECIFICS);
REDIR(OT_CODE);
@ -816,9 +834,11 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
OUT("td->free_struct = asn1_DEF_%s.free_struct;\n", type_name);
OUT("td->print_struct = asn1_DEF_%s.print_struct;\n", type_name);
if(!terminal && !tags_count) {
OUT("/* The next two lines are because of -fknown-extern-type */\n");
OUT("/* The next four lines are here because of -fknown-extern-type */\n");
OUT("td->tags = asn1_DEF_%s.tags;\n", type_name);
OUT("td->tags_count = asn1_DEF_%s.tags_count;\n", type_name);
OUT("td->all_tags = asn1_DEF_%s.all_tags;\n", type_name);
OUT("td->all_tags_count = asn1_DEF_%s.all_tags_count;\n",type_name);
OUT("/* End of these lines */\n");
}
OUT("td->last_tag_form = asn1_DEF_%s.last_tag_form;\n", type_name);
@ -1122,33 +1142,77 @@ emit_tag2member_map(arg_t *arg, tag2el_t *tag2el, int tag2el_count) {
return 0;;
}
static int
emit_tags_vector(arg_t *arg, asn1p_expr_t *expr) {
struct asn1p_type_tag_s *tags = 0;
static enum tvm_compat
emit_tags_vectors(arg_t *arg, asn1p_expr_t *expr, int *tags_count_r, int *all_tags_count_r) {
struct asn1p_type_tag_s *tags = 0; /* Effective tags */
struct asn1p_type_tag_s *all_tags = 0; /* The full array */
int tags_count = 0;
int all_tags_count = 0;
enum tvm_compat tv_mode = _TVM_SAME;
int i;
/* Fetch a chain of tags */
tags_count = asn1f_fetch_tags(arg->asn, arg->mod, expr, &tags, 0);
if(tags_count <= 0)
return 0;
if(tags_count < 0) return -1;
OUT("static ber_tlv_tag_t asn1_DEF_%s_tags[] = {\n",
MKID(expr->Identifier));
INDENT(+1);
/* Print the array of collected tags */
for(i = 0; i < tags_count; i++) {
if(i) OUT(",\n");
_print_tag(arg, &tags[i]);
/* Fetch a chain of tags */
all_tags_count = asn1f_fetch_tags(arg->asn, arg->mod, expr,
&all_tags, AFT_FULL_COLLECT);
if(all_tags_count < 0) {
if(tags) free(tags);
return -1;
}
OUT("\n");
INDENT(-1);
OUT("};\n");
assert(tags_count <= all_tags_count);
assert((tags_count?0:1) == (all_tags_count?0:1));
free(tags);
return tags_count;
if(tags_count <= all_tags_count) {
for(i = 0; i < tags_count; i++) {
if(tags[i].tag_value != all_tags[i].tag_value
|| tags[i].tag_class != all_tags[i].tag_class) {
tv_mode = _TVM_DIFFERENT;
break;
}
}
if(i == tags_count && tags_count < all_tags_count)
tv_mode = _TVM_SUBSET;
} else {
tv_mode = _TVM_DIFFERENT;
}
#define EMIT_TAGS_TABLE(name, tags, tags_count) do { \
OUT("static ber_tlv_tag_t asn1_DEF_%s%s_tags[] = {\n", \
MKID(expr->Identifier), name); \
INDENT(+1); \
/* Print the array of collected tags */ \
for(i = 0; i < tags_count; i++) { \
if(i) OUT(",\n"); \
_print_tag(arg, &tags[i]); \
} \
OUT("\n"); \
INDENT(-1); \
OUT("};\n"); \
} while(0)
if(tags_count) {
if(tv_mode == _TVM_SUBSET)
EMIT_TAGS_TABLE("", all_tags, all_tags_count);
else
EMIT_TAGS_TABLE("", tags, tags_count);
}
if(all_tags_count) {
if(tv_mode == _TVM_DIFFERENT)
EMIT_TAGS_TABLE("_all", all_tags, all_tags_count);
}
if(tags) free(tags);
if(all_tags) free(all_tags);
*tags_count_r = tags_count;
*all_tags_count_r = all_tags_count;
return tv_mode;
}
static int
@ -1293,14 +1357,14 @@ emit_member_table(arg_t *arg, asn1p_expr_t *expr) {
}
static int
emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, int tags_count, int elements_count, enum etd_cp cp, enum etd_spec spec) {
emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_count, int all_tags_count, int elements_count, enum etd_cp cp, enum etd_spec spec) {
char *p;
p = MKID(expr->Identifier);
if(HIDE_INNER_DEFS)
OUT("static /* Use -fall-defs-global to expose */\n");
OUT("asn1_TYPE_descriptor_t asn1_DEF_%s = {\n", p);
INDENTED(
INDENT(+1);
OUT("\"%s\",\n", expr->_anonymous_type?"":expr->Identifier);
if(expr->expr_type & ASN_CONSTR_MASK) {
@ -1324,11 +1388,29 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, int tags_count, int elements_count
if(tags_count) {
OUT("asn1_DEF_%s_tags,\n", p);
OUT("sizeof(asn1_DEF_%s_tags)\n", p);
OUT("\t/sizeof(asn1_DEF_%s_tags[0]), /* %d */\n",
p, tags_count);
OUT("\t/sizeof(asn1_DEF_%s_tags[0])", p);
if(tv_mode == _TVM_SUBSET
&& tags_count != all_tags_count)
OUT(" - %d", all_tags_count - tags_count);
OUT(", /* %d */\n", tags_count);
} else {
OUT("0,\t/* No explicit tags (pointer) */\n");
OUT("0,\t/* No explicit tags (count) */\n");
OUT("0,\t/* No effective tags (pointer) */\n");
OUT("0,\t/* No effective tags (count) */\n");
}
if(all_tags_count && tv_mode == _TVM_DIFFERENT) {
OUT("asn1_DEF_%s_all_tags,\n", p);
OUT("sizeof(asn1_DEF_%s_all_tags)\n", p);
OUT("\t/sizeof(asn1_DEF_%s_all_tags[0]), /* %d */\n",
p, all_tags_count);
} else if(all_tags_count) {
OUT("asn1_DEF_%s_tags,\t/* Same as above */\n", p);
OUT("sizeof(asn1_DEF_%s_tags)\n", p);
OUT("\t/sizeof(asn1_DEF_%s_tags[0]), /* %d */\n",
p, all_tags_count);
} else {
OUT("0,\t/* No tags (pointer) */\n");
OUT("0,\t/* No tags (count) */\n");
}
switch(cp) {
@ -1371,7 +1453,7 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, int tags_count, int elements_count
case ETD_HAS_SPECIFICS:
OUT("&asn1_DEF_%s_specs\t/* Additional specs */\n", p);
}
);
INDENT(-1);
OUT("};\n");
OUT("\n");

View File

@ -2,7 +2,7 @@
#define ADD_TAG(skip, newtag) do { \
void *__p; \
if(skip) { \
if(skip && !(flags & AFT_FULL_COLLECT)) { \
if(newtag.tag_mode != TM_IMPLICIT) \
skip--; \
break; \

View File

@ -4,6 +4,7 @@
enum asn1f_aft_flags_e {
AFT_IMAGINARY_ANY = 0x01, /* Treat ANY tag as [IMAGINARY ANY] */
AFT_FETCH_OUTMOST = 0x02, /* Fetch only outmost tag */
AFT_FULL_COLLECT = 0x04, /* Collect all tags */
};
/*

View File

@ -19,6 +19,9 @@ asn1_TYPE_descriptor_t asn1_DEF_BIT_STRING = {
OCTET_STRING_free, /* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */
asn1_DEF_BIT_STRING_tags,
sizeof(asn1_DEF_BIT_STRING_tags)
/ sizeof(asn1_DEF_BIT_STRING_tags[0]),
asn1_DEF_BIT_STRING_tags, /* Same as above */
sizeof(asn1_DEF_BIT_STRING_tags)
/ sizeof(asn1_DEF_BIT_STRING_tags[0]),
-1, /* Both ways are fine */

View File

@ -8,7 +8,8 @@
* BMPString basic type description.
*/
static ber_tlv_tag_t asn1_DEF_BMPString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (30 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (30 << 2)), /* [UNIVERSAL 30] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_BMPString = {
"BMPString",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_BMPString = {
OCTET_STRING_free, /* -//- */
0, /* Use generic outmost tag fetcher */
asn1_DEF_BMPString_tags,
sizeof(asn1_DEF_BMPString_tags)
/ sizeof(asn1_DEF_BMPString_tags[0]) - 1,
asn1_DEF_BMPString_tags,
sizeof(asn1_DEF_BMPString_tags)
/ sizeof(asn1_DEF_BMPString_tags[0]),
-1, /* Both ways are fine */

View File

@ -19,7 +19,9 @@ asn1_TYPE_descriptor_t asn1_DEF_BOOLEAN = {
BOOLEAN_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_BOOLEAN_tags,
sizeof(asn1_DEF_BOOLEAN_tags)/sizeof(asn1_DEF_BOOLEAN_tags[0]),
sizeof(asn1_DEF_BOOLEAN_tags) / sizeof(asn1_DEF_BOOLEAN_tags[0]),
asn1_DEF_BOOLEAN_tags, /* Same as above */
sizeof(asn1_DEF_BOOLEAN_tags) / sizeof(asn1_DEF_BOOLEAN_tags[0]),
0, /* Always in primitive form */
0, 0, /* No members */
0 /* No specifics */

View File

@ -19,7 +19,9 @@ asn1_TYPE_descriptor_t asn1_DEF_ENUMERATED = {
INTEGER_free, /* Implemented in terms of INTEGER */
0, /* Use generic outmost tag fetcher */
asn1_DEF_ENUMERATED_tags,
sizeof(asn1_DEF_ENUMERATED_tags)/sizeof(asn1_DEF_ENUMERATED_tags[0]),
sizeof(asn1_DEF_ENUMERATED_tags) / sizeof(asn1_DEF_ENUMERATED_tags[0]),
asn1_DEF_ENUMERATED_tags, /* Same as above */
sizeof(asn1_DEF_ENUMERATED_tags) / sizeof(asn1_DEF_ENUMERATED_tags[0]),
0, /* Primitive */
0, 0, /* No members */
0 /* No specifics */

View File

@ -8,7 +8,8 @@
* GeneralString basic type description.
*/
static ber_tlv_tag_t asn1_DEF_GeneralString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (27 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (27 << 2)), /* [UNIVERSAL 27] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_GeneralString = {
"GeneralString",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_GeneralString = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_GeneralString_tags,
sizeof(asn1_DEF_GeneralString_tags)
/ sizeof(asn1_DEF_GeneralString_tags[0]) - 1,
asn1_DEF_GeneralString_tags,
sizeof(asn1_DEF_GeneralString_tags)
/ sizeof(asn1_DEF_GeneralString_tags[0]),
-1, /* Both ways are fine */

View File

@ -83,6 +83,9 @@ asn1_TYPE_descriptor_t asn1_DEF_GeneralizedTime = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_GeneralizedTime_tags,
sizeof(asn1_DEF_GeneralizedTime_tags)
/ sizeof(asn1_DEF_GeneralizedTime_tags[0]),
asn1_DEF_GeneralizedTime_tags, /* Same as above */
sizeof(asn1_DEF_GeneralizedTime_tags)
/ sizeof(asn1_DEF_GeneralizedTime_tags[0]),
-1, /* Both ways are fine */

View File

@ -8,7 +8,8 @@
* GraphicString basic type description.
*/
static ber_tlv_tag_t asn1_DEF_GraphicString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (25 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (25 << 2)), /* [UNIVERSAL 25] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_GraphicString = {
"GraphicString",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_GraphicString = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_GraphicString_tags,
sizeof(asn1_DEF_GraphicString_tags)
/ sizeof(asn1_DEF_GraphicString_tags[0]) - 1,
asn1_DEF_GraphicString_tags,
sizeof(asn1_DEF_GraphicString_tags)
/ sizeof(asn1_DEF_GraphicString_tags[0]),
-1, /* Both ways are fine */

View File

@ -8,7 +8,8 @@
* IA5String basic type description.
*/
static ber_tlv_tag_t asn1_DEF_IA5String_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (22 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (22 << 2)), /* [UNIVERSAL 22] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_IA5String = {
"IA5String",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_IA5String = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_IA5String_tags,
sizeof(asn1_DEF_IA5String_tags)
/ sizeof(asn1_DEF_IA5String_tags[0]) - 1,
asn1_DEF_IA5String_tags,
sizeof(asn1_DEF_IA5String_tags)
/ sizeof(asn1_DEF_IA5String_tags[0]),
-1, /* Both ways are fine */

View File

@ -21,7 +21,9 @@ asn1_TYPE_descriptor_t asn1_DEF_INTEGER = {
INTEGER_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_INTEGER_tags,
sizeof(asn1_DEF_INTEGER_tags)/sizeof(asn1_DEF_INTEGER_tags[0]),
sizeof(asn1_DEF_INTEGER_tags) / sizeof(asn1_DEF_INTEGER_tags[0]),
asn1_DEF_INTEGER_tags, /* Same as above */
sizeof(asn1_DEF_INTEGER_tags) / sizeof(asn1_DEF_INTEGER_tags[0]),
0, /* Always in primitive form */
0, 0, /* No members */
0 /* No specifics */

View File

@ -8,7 +8,8 @@
* ISO646String basic type description.
*/
static ber_tlv_tag_t asn1_DEF_ISO646String_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (26 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_ISO646String = {
"ISO646String",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_ISO646String = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_ISO646String_tags,
sizeof(asn1_DEF_ISO646String_tags)
/ sizeof(asn1_DEF_ISO646String_tags[0]) - 1,
asn1_DEF_ISO646String_tags,
sizeof(asn1_DEF_ISO646String_tags)
/ sizeof(asn1_DEF_ISO646String_tags[0]),
-1, /* Both ways are fine */

View File

@ -20,7 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_NULL = {
BOOLEAN_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_NULL_tags,
sizeof(asn1_DEF_NULL_tags)/sizeof(asn1_DEF_NULL_tags[0]),
sizeof(asn1_DEF_NULL_tags) / sizeof(asn1_DEF_NULL_tags[0]),
asn1_DEF_NULL_tags, /* Same as above */
sizeof(asn1_DEF_NULL_tags) / sizeof(asn1_DEF_NULL_tags[0]),
0, /* Always in primitive form */
0, 0, /* No members */
0 /* No specifics */

View File

@ -26,7 +26,9 @@ asn1_TYPE_descriptor_t asn1_DEF_NativeEnumerated = {
NativeInteger_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_NativeEnumerated_tags,
sizeof(asn1_DEF_NativeEnumerated_tags)/sizeof(asn1_DEF_NativeEnumerated_tags[0]),
sizeof(asn1_DEF_NativeEnumerated_tags) / sizeof(asn1_DEF_NativeEnumerated_tags[0]),
asn1_DEF_NativeEnumerated_tags, /* Same as above */
sizeof(asn1_DEF_NativeEnumerated_tags) / sizeof(asn1_DEF_NativeEnumerated_tags[0]),
0, /* Always in primitive form */
0, 0, /* No members */
0 /* No specifics */

View File

@ -28,7 +28,9 @@ asn1_TYPE_descriptor_t asn1_DEF_NativeInteger = {
NativeInteger_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_NativeInteger_tags,
sizeof(asn1_DEF_NativeInteger_tags)/sizeof(asn1_DEF_NativeInteger_tags[0]),
sizeof(asn1_DEF_NativeInteger_tags) / sizeof(asn1_DEF_NativeInteger_tags[0]),
asn1_DEF_NativeInteger_tags, /* Same as above */
sizeof(asn1_DEF_NativeInteger_tags) / sizeof(asn1_DEF_NativeInteger_tags[0]),
0, /* Always in primitive form */
0, 0, /* No members */
0 /* No specifics */

View File

@ -8,7 +8,8 @@
* NumericString basic type description.
*/
static ber_tlv_tag_t asn1_DEF_NumericString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (18 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (18 << 2)), /* [UNIVERSAL 18] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_NumericString = {
"NumericString",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_NumericString = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_NumericString_tags,
sizeof(asn1_DEF_NumericString_tags)
/ sizeof(asn1_DEF_NumericString_tags[0]) - 1,
asn1_DEF_NumericString_tags,
sizeof(asn1_DEF_NumericString_tags)
/ sizeof(asn1_DEF_NumericString_tags[0]),
-1, /* Both ways are fine */

View File

@ -22,6 +22,9 @@ asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER = {
INTEGER_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_OBJECT_IDENTIFIER_tags,
sizeof(asn1_DEF_OBJECT_IDENTIFIER_tags)
/ sizeof(asn1_DEF_OBJECT_IDENTIFIER_tags[0]),
asn1_DEF_OBJECT_IDENTIFIER_tags, /* Same as above */
sizeof(asn1_DEF_OBJECT_IDENTIFIER_tags)
/ sizeof(asn1_DEF_OBJECT_IDENTIFIER_tags[0]),
0, /* Always in primitive form */
@ -98,7 +101,7 @@ OBJECT_IDENTIFIER_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
int
OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, signed int add, void *rvbuf, unsigned int rvsize) {
unsigned LE = 1; /* Little endian (x86) */
unsigned LE __attribute__ ((unused)) = 1; /* Little endian (x86) */
uint8_t *arcend = arcbuf + arclen; /* End of arc */
void *rvstart = rvbuf; /* Original start of the value buffer */
unsigned int cache = 0; /* No more than 14 significant bits */

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <OCTET_STRING.h>
@ -21,6 +21,9 @@ asn1_TYPE_descriptor_t asn1_DEF_OCTET_STRING = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_OCTET_STRING_tags,
sizeof(asn1_DEF_OCTET_STRING_tags)
/ sizeof(asn1_DEF_OCTET_STRING_tags[0]),
asn1_DEF_OCTET_STRING_tags, /* Same as above */
sizeof(asn1_DEF_OCTET_STRING_tags)
/ sizeof(asn1_DEF_OCTET_STRING_tags[0]),
-1, /* Both ways are fine (primitive and constructed) */
@ -54,6 +57,7 @@ asn1_TYPE_descriptor_t asn1_DEF_OCTET_STRING = {
size_t _ns = ctx->step; /* Allocated */ \
if(_ns <= (size_t)(st->size + _bs)) { \
void *ptr; \
/* Be nice and round to the memory allocator */ \
do { _ns = _ns ? _ns<<2 : 16; } \
while(_ns <= (size_t)(st->size + _bs)); \
ptr = REALLOC(st->buf, _ns); \
@ -81,6 +85,7 @@ asn1_TYPE_descriptor_t asn1_DEF_OCTET_STRING = {
*/
struct _stack_el {
ber_tlv_len_t left; /* What's left to read */
int cont_level; /* Depth of subcontainment */
int want_nulls; /* Want null "end of content" octets? */
int bits_chopped; /* Flag in BIT STRING mode */
struct _stack_el *prev;
@ -95,17 +100,23 @@ static struct _stack_el *
_add_stack_el(struct _stack *st) {
struct _stack_el *nel;
/*
* Reuse the old stack frame or allocate a new one.
*/
if(st->cur_ptr && st->cur_ptr->next) {
nel = st->cur_ptr->next;
nel->left = 0;
nel->want_nulls = 0;
nel->bits_chopped = 0;
/* Retain nel->cont_level, it's correct. */
} else {
(void *)nel = CALLOC(1, sizeof(struct _stack_el));
if(nel == NULL)
return NULL;
if(st->tail) {
/* Increase a subcontainment depth */
nel->cont_level = st->tail->cont_level + 1;
st->tail->next = nel;
}
nel->prev = st->tail;
@ -136,13 +147,16 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
OCTET_STRING_t *st = (OCTET_STRING_t *)*os_structure;
ber_dec_rval_t rval;
ber_dec_ctx_t *ctx;
ber_tlv_tag_t terminal_tag; /* Inner tag for constructed types */
ssize_t consumed_myself = 0;
struct _stack *stck; /* A stack structure */
struct _stack_el *sel; /* Stack element */
int tlv_constr;
int is_bit_str = 0; /* See below under switch(td->specifics) */
int is_ANY_type = 0; /* See below under switch(td->specifics) */
enum type_type_e {
_TT_GENERIC = 0, /* Just a random OCTET STRING */
_TT_BIT_STRING = -1, /* BIT STRING type, a special case */
_TT_ANY = 1, /* ANY type, a special case too */
} type_type
= (enum type_type_e)(int)td->specifics; /* An ugly hack */
ASN_DEBUG("Decoding %s as %s (%ld)",
td->name, "OCTET STRING", (long)size);
@ -159,25 +173,6 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
/* Restore parsing context */
ctx = &st->_ber_dec_ctx;
switch((int)td->specifics) {
case 0:
terminal_tag = asn1_DEF_OCTET_STRING_tags[0]; /* [U4] */
break;
case -1: /* BIT STRING */
/*
* This is some sort of a hack.
* The OCTET STRING decoder is being used in BIT STRING mode.
*/
is_bit_str = 1;
terminal_tag = ASN_TAG_CLASS_UNIVERSAL | (3 << 2);
break;
default: /* Just in case; fall through */
case 1: /* ANY type */
is_ANY_type = 1;
terminal_tag = -1;
break;
}
switch(ctx->phase) {
case 0:
/*
@ -212,7 +207,7 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
stck->cur_ptr->left,
stck->cur_ptr->want_nulls);
#endif
if(is_bit_str) {
if(type_type == _TT_BIT_STRING) {
/* Number of meaningless tail bits */
APPEND("\0", 1);
}
@ -224,7 +219,8 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
* Jump into stackless primitive decoding.
*/
_CH_PHASE(ctx, 3);
if(is_ANY_type) APPEND(buf_ptr, rval.consumed);
if(type_type == _TT_ANY)
APPEND(buf_ptr, rval.consumed);
ADVANCE(rval.consumed);
goto phase3;
}
@ -241,6 +237,7 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
do {
ber_tlv_tag_t tlv_tag;
ber_tlv_len_t tlv_len;
ber_tlv_tag_t expected_tag;
ssize_t tl, ll;
ASN_DEBUG("fetch tag(size=%d), %sstack, left=%d, want0=%d",
@ -271,7 +268,7 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
&& ((uint8_t *)buf_ptr)[1] == 0)
{
ADVANCE(2);
if(is_ANY_type) APPEND("\0\0", 2);
if(type_type == _TT_ANY) APPEND("\0\0", 2);
ASN_DEBUG("Eat EOC; wn=%d--", sel->want_nulls);
@ -294,8 +291,38 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
}
continue;
} else if(tlv_tag != terminal_tag
&& terminal_tag != (ber_tlv_tag_t)-1) {
}
/*
* Set up expected tags,
* depending on ASN.1 type being decoded.
*/
switch(type_type) {
case _TT_BIT_STRING:
/* X.690: 8.6.4.1, NOTE 2 */
/* Fall through */
case _TT_GENERIC:
default:
if(sel) {
int level = sel->cont_level;
if(level < td->all_tags_count) {
expected_tag = td->all_tags[level];
break;
} else if(td->all_tags_count) {
expected_tag = td->all_tags
[td->all_tags_count - 1];
break;
}
/* else, Fall through */
}
/* Fall through */
case _TT_ANY:
expected_tag = tlv_tag;
break;
}
if(tlv_tag != expected_tag) {
char buf[2][32];
ber_tlv_tag_snprint(tlv_tag,
buf[0], sizeof(buf[0]));
@ -313,17 +340,18 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
if(sel) {
sel->want_nulls = (tlv_len==-1);
sel->left = tlv_len;
ASN_DEBUG("+EXPECT2 left=%d wn=%d",
sel->left, sel->want_nulls);
ASN_DEBUG("+EXPECT2 left=%d wn=%d, clvl=%d",
sel->left, sel->want_nulls, sel->cont_level);
} else {
RETURN(RC_FAIL);
}
if(is_ANY_type) APPEND(buf_ptr, tl + ll);
if(type_type == _TT_ANY) APPEND(buf_ptr, tl + ll);
ADVANCE(tl+ll);
} while(tlv_constr);
if(sel == NULL) {
/* Finished operation, "phase out" */
ASN_DEBUG("Phase out");
_CH_PHASE(ctx, +3);
break;
}
@ -343,7 +371,8 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
len = ((ber_tlv_len_t)size < sel->left)
? (ber_tlv_len_t)size : sel->left;
if(len > 0) {
if(is_bit_str && sel->bits_chopped == 0) {
if(type_type == _TT_BIT_STRING
&& sel->bits_chopped == 0) {
/*
* Finalize the previous chunk:
* strip down unused bits.
@ -394,7 +423,7 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
/*
* BIT STRING-specific processing.
*/
if(is_bit_str && st->size >= 2) {
if(type_type == _TT_BIT_STRING && st->size >= 2) {
/* Finalize BIT STRING: zero out unused bits. */
st->buf[st->size-1] &= 0xff << st->buf[0];
}

View File

@ -8,7 +8,8 @@
* ObjectDescriptor basic type description.
*/
static ber_tlv_tag_t asn1_DEF_ObjectDescriptor_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (7 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (7 << 2)), /* [UNIVERSAL 7] IMPLICIT ... */
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_ObjectDescriptor = {
"ObjectDescriptor",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_ObjectDescriptor = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_ObjectDescriptor_tags,
sizeof(asn1_DEF_ObjectDescriptor_tags)
/ sizeof(asn1_DEF_ObjectDescriptor_tags[0]) - 1,
asn1_DEF_ObjectDescriptor_tags,
sizeof(asn1_DEF_ObjectDescriptor_tags)
/ sizeof(asn1_DEF_ObjectDescriptor_tags[0]),
-1, /* Both ways are fine */

View File

@ -8,7 +8,8 @@
* PrintableString basic type description.
*/
static ber_tlv_tag_t asn1_DEF_PrintableString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (19 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (19 << 2)), /* [UNIVERSAL 19] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_PrintableString = {
"PrintableString",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_PrintableString = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_PrintableString_tags,
sizeof(asn1_DEF_PrintableString_tags)
/ sizeof(asn1_DEF_PrintableString_tags[0]) - 1,
asn1_DEF_PrintableString_tags,
sizeof(asn1_DEF_PrintableString_tags)
/ sizeof(asn1_DEF_PrintableString_tags[0]),
-1, /* Both ways are fine */

View File

@ -22,6 +22,9 @@ asn1_TYPE_descriptor_t asn1_DEF_RELATIVE_OID = {
INTEGER_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_RELATIVE_OID_tags,
sizeof(asn1_DEF_RELATIVE_OID_tags)
/ sizeof(asn1_DEF_RELATIVE_OID_tags[0]),
asn1_DEF_RELATIVE_OID_tags, /* Same as above */
sizeof(asn1_DEF_RELATIVE_OID_tags)
/ sizeof(asn1_DEF_RELATIVE_OID_tags[0]),
0, /* Always in primitive form */

View File

@ -8,7 +8,8 @@
* T61String basic type description.
*/
static ber_tlv_tag_t asn1_DEF_T61String_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (20 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (20 << 2)), /* [UNIVERSAL 20] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_T61String = {
"T61String",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_T61String = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_T61String_tags,
sizeof(asn1_DEF_T61String_tags)
/ sizeof(asn1_DEF_T61String_tags[0]) - 1,
asn1_DEF_T61String_tags,
sizeof(asn1_DEF_T61String_tags)
/ sizeof(asn1_DEF_T61String_tags[0]),
-1, /* Both ways are fine */

View File

@ -8,7 +8,8 @@
* TeletexString basic type description.
*/
static ber_tlv_tag_t asn1_DEF_TeletexString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (20 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (20 << 2)), /* [UNIVERSAL 20] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_TeletexString = {
"TeletexString",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_TeletexString = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_TeletexString_tags,
sizeof(asn1_DEF_TeletexString_tags)
/ sizeof(asn1_DEF_TeletexString_tags[0]) - 1,
asn1_DEF_TeletexString_tags,
sizeof(asn1_DEF_TeletexString_tags)
/ sizeof(asn1_DEF_TeletexString_tags[0]),
-1, /* Both ways are fine */

View File

@ -25,6 +25,9 @@ asn1_TYPE_descriptor_t asn1_DEF_UTCTime = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_UTCTime_tags,
sizeof(asn1_DEF_UTCTime_tags)
/ sizeof(asn1_DEF_UTCTime_tags[0]),
asn1_DEF_UTCTime_tags, /* Same as above */
sizeof(asn1_DEF_UTCTime_tags)
/ sizeof(asn1_DEF_UTCTime_tags[0]),
-1, /* Both ways are fine */

View File

@ -8,7 +8,8 @@
* UTF8String basic type description.
*/
static ber_tlv_tag_t asn1_DEF_UTF8String_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (12 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (12 << 2)), /* [UNIVERSAL 12] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_UTF8String = {
"UTF8String",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_UTF8String = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_UTF8String_tags,
sizeof(asn1_DEF_UTF8String_tags)
/ sizeof(asn1_DEF_UTF8String_tags[0]) - 1,
asn1_DEF_UTF8String_tags,
sizeof(asn1_DEF_UTF8String_tags)
/ sizeof(asn1_DEF_UTF8String_tags[0]),
-1, /* Both ways are fine */

View File

@ -8,7 +8,8 @@
* UniversalString basic type description.
*/
static ber_tlv_tag_t asn1_DEF_UniversalString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (28 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (28 << 2)), /* [UNIVERSAL 28] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_UniversalString = {
"UniversalString",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_UniversalString = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_UniversalString_tags,
sizeof(asn1_DEF_UniversalString_tags)
/ sizeof(asn1_DEF_UniversalString_tags[0]) - 1,
asn1_DEF_UniversalString_tags,
sizeof(asn1_DEF_UniversalString_tags)
/ sizeof(asn1_DEF_UniversalString_tags[0]),
-1, /* Both ways are fine */

View File

@ -8,7 +8,8 @@
* VideotexString basic type description.
*/
static ber_tlv_tag_t asn1_DEF_VideotexString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (21 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (21 << 2)), /* [UNIVERSAL 21] IMPLICIT */
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_VideotexString = {
"VideotexString",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_VideotexString = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_VideotexString_tags,
sizeof(asn1_DEF_VideotexString_tags)
/ sizeof(asn1_DEF_VideotexString_tags[0]) - 1,
asn1_DEF_VideotexString_tags,
sizeof(asn1_DEF_VideotexString_tags)
/ sizeof(asn1_DEF_VideotexString_tags[0]),
-1, /* Both ways are fine */

View File

@ -8,7 +8,8 @@
* VisibleString basic type description.
*/
static ber_tlv_tag_t asn1_DEF_VisibleString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (26 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
asn1_TYPE_descriptor_t asn1_DEF_VisibleString = {
"VisibleString",
@ -19,6 +20,9 @@ asn1_TYPE_descriptor_t asn1_DEF_VisibleString = {
OCTET_STRING_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_VisibleString_tags,
sizeof(asn1_DEF_VisibleString_tags)
/ sizeof(asn1_DEF_VisibleString_tags[0]) - 1,
asn1_DEF_VisibleString_tags,
sizeof(asn1_DEF_VisibleString_tags)
/ sizeof(asn1_DEF_VisibleString_tags[0]),
-1, /* Both ways are fine */

View File

@ -70,10 +70,13 @@ typedef struct asn1_TYPE_descriptor_s {
asn_outmost_tag_f *outmost_tag; /* <optional, internal> */
/*
* Tags that are expected, with some of their vital properties.
* Tags that are expected to occur.
*/
ber_tlv_tag_t *tags; /* At least one tag must be specified */
ber_tlv_tag_t *tags; /* Effective tags sequence for this type */
int tags_count; /* Number of tags which are expected */
ber_tlv_tag_t *all_tags;/* Every tag for BER/containment */
int all_tags_count; /* Number of tags */
int last_tag_form; /* Acceptable form of the tag (prim, constr) */
/*
@ -92,12 +95,13 @@ typedef struct asn1_TYPE_descriptor_s {
/*
* An element of the constructed type, i.e. SEQUENCE, SET, CHOICE.
*/
enum asn1_TYPE_flags_e {
ATF_NOFLAGS,
ATF_POINTER = 0x01, /* Represented by the pointer */
ATF_OPEN_TYPE = 0x02, /* ANY type, without meaningful tag */
};
typedef struct asn1_TYPE_member_s {
enum asn1_TYPE_flags_e {
ATF_NOFLAGS,
ATF_POINTER = 0x01, /* Represented by the pointer */
ATF_OPEN_TYPE = 0x02, /* ANY type, without meaningful tag */
} flags; /* Element's presentation flags */
enum asn1_TYPE_flags_e flags; /* Element's presentation flags */
int optional; /* Following optional members, including current */
int memb_offset; /* Offset of the element */
ber_tlv_tag_t tag; /* Outmost (most immediate) tag */

View File

@ -115,6 +115,9 @@ asn1_TYPE_descriptor_t asn1_DEF_toBeSigned = {
SEQUENCE_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_toBeSigned_tags,
sizeof(asn1_DEF_toBeSigned_tags)
/sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */
asn1_DEF_toBeSigned_tags, /* Same as above */
sizeof(asn1_DEF_toBeSigned_tags)
/sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */
1, /* Whether CONSTRUCTED */
@ -171,6 +174,9 @@ asn1_TYPE_descriptor_t asn1_DEF_Certificate = {
SEQUENCE_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_Certificate_tags,
sizeof(asn1_DEF_Certificate_tags)
/sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */
asn1_DEF_Certificate_tags, /* Same as above */
sizeof(asn1_DEF_Certificate_tags)
/sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */
1, /* Whether CONSTRUCTED */
@ -227,6 +233,9 @@ asn1_TYPE_descriptor_t asn1_DEF_Name = {
SEQUENCE_OF_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_Name_tags,
sizeof(asn1_DEF_Name_tags)
/sizeof(asn1_DEF_Name_tags[0]), /* 1 */
asn1_DEF_Name_tags, /* Same as above */
sizeof(asn1_DEF_Name_tags)
/sizeof(asn1_DEF_Name_tags[0]), /* 1 */
1, /* Whether CONSTRUCTED */
@ -338,6 +347,9 @@ asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName = {
SET_OF_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_RelativeDistinguishedName_tags,
sizeof(asn1_DEF_RelativeDistinguishedName_tags)
/sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */
asn1_DEF_RelativeDistinguishedName_tags, /* Same as above */
sizeof(asn1_DEF_RelativeDistinguishedName_tags)
/sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */
1, /* Whether CONSTRUCTED */