mirror of https://gerrit.osmocom.org/asn1c
parse advanced WITH COMPONENTS
This commit is contained in:
parent
8460940d54
commit
d523ea454d
|
@ -24,8 +24,18 @@ asn1c_get_information_object_set_reference_from_constraint(arg_t *arg,
|
|||
assert(ct->elements[0]->type == ACT_EL_VALUE);
|
||||
|
||||
asn1p_value_t *val = ct->elements[0]->value;
|
||||
if(val->type == ATV_VALUESET && val->value.constraint->type == ACT_EL_TYPE && val->value.constraint->containedSubtype && val->value.constraint->containedSubtype->type == ATV_REFERENCED) {
|
||||
return val->value.constraint->containedSubtype->value.reference;
|
||||
if(val->type == ATV_VALUESET && val->value.constraint->type == ACT_EL_TYPE) {
|
||||
asn1p_value_t *csub = val->value.constraint->containedSubtype;
|
||||
if(!csub) {
|
||||
/* Ignore */
|
||||
} else if(csub->type == ATV_REFERENCED) {
|
||||
return csub->value.reference;
|
||||
} else if(csub->type == ATV_TYPE) {
|
||||
if(csub->value.v_type->expr_type == A1TC_REFERENCE) {
|
||||
assert(csub->value.v_type->reference);
|
||||
return csub->value.v_type->reference;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(val->type != ATV_REFERENCED) {
|
||||
FATAL("Set reference: %s", asn1f_printable_value(val));
|
||||
|
|
|
@ -257,70 +257,83 @@ _remove_extensions(arg_t *arg, asn1p_constraint_t *ct, int forgive_last) {
|
|||
ct->elements[i] = 0;
|
||||
}
|
||||
|
||||
static asn1p_ref_t *
|
||||
get_reference_from(asn1p_constraint_t *ct) {
|
||||
if(ct->containedSubtype->type == ATV_REFERENCED) {
|
||||
return ct->containedSubtype->value.reference;
|
||||
} else if(ct->containedSubtype->type == ATV_TYPE) {
|
||||
if(ct->containedSubtype->value.v_type->expr_type == A1TC_REFERENCE) {
|
||||
return ct->containedSubtype->value.v_type->reference;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
constraint_type_resolve(arg_t *arg, asn1p_constraint_t *ct) {
|
||||
asn1p_constraint_t *ct_expr;
|
||||
int ret;
|
||||
asn1p_constraint_t *ct_expr;
|
||||
int ret;
|
||||
|
||||
DEBUG("(\"%s\")", asn1f_printable_value(ct->containedSubtype));
|
||||
DEBUG("(\"%s\")", asn1f_printable_value(ct->containedSubtype));
|
||||
|
||||
if(ct->containedSubtype->type == ATV_VALUESET) {
|
||||
ct_expr = ct->containedSubtype->value.constraint;
|
||||
DEBUG("Found %s in constraints", "ValueSet");
|
||||
} else if(ct->containedSubtype->type == ATV_REFERENCED) {
|
||||
asn1p_expr_t *rtype;
|
||||
arg_t tmparg;
|
||||
if(ct->containedSubtype->type == ATV_VALUESET) {
|
||||
ct_expr = ct->containedSubtype->value.constraint;
|
||||
DEBUG("Found %s in constraints", "ValueSet");
|
||||
} else if(get_reference_from(ct)) {
|
||||
asn1p_expr_t *rtype;
|
||||
arg_t tmparg;
|
||||
|
||||
rtype = asn1f_lookup_symbol(arg, arg->expr->rhs_pspecs,
|
||||
ct->containedSubtype->value.reference);
|
||||
get_reference_from(ct));
|
||||
if(!rtype) {
|
||||
FATAL("Cannot find type \"%s\" in constraints "
|
||||
"at line %d",
|
||||
asn1f_printable_value(ct->containedSubtype),
|
||||
ct->_lineno);
|
||||
return -1;
|
||||
}
|
||||
FATAL(
|
||||
"Cannot find type \"%s\" in constraints "
|
||||
"at line %d",
|
||||
asn1f_printable_value(ct->containedSubtype), ct->_lineno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmparg = *arg;
|
||||
tmparg.expr = rtype;
|
||||
tmparg.mod = rtype->module;
|
||||
ret = asn1constraint_pullup(&tmparg);
|
||||
if(ret) return ret;
|
||||
|
||||
ct_expr = rtype->combined_constraints;
|
||||
if(!ct_expr) return 0;
|
||||
} else {
|
||||
FATAL("Unsupported feature at line %d", ct->_lineno);
|
||||
return -1;
|
||||
}
|
||||
tmparg = *arg;
|
||||
tmparg.expr = rtype;
|
||||
tmparg.mod = rtype->module;
|
||||
ret = asn1constraint_pullup(&tmparg);
|
||||
if(ret) return ret;
|
||||
|
||||
ct_expr = asn1p_constraint_clone(ct_expr);
|
||||
assert(ct_expr);
|
||||
ct_expr = rtype->combined_constraints;
|
||||
if(!ct_expr) return 0;
|
||||
} else {
|
||||
FATAL("Unsupported constraint kind %s at line %d",
|
||||
asn1f_printable_value(ct->containedSubtype), ct->_lineno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
_remove_extensions(arg, ct_expr, 0);
|
||||
ct_expr = asn1p_constraint_clone(ct_expr);
|
||||
assert(ct_expr);
|
||||
|
||||
if(ct_expr->type == ACT_CA_SET) {
|
||||
unsigned int i;
|
||||
for(i = 0; i < ct_expr->el_count; i++) {
|
||||
if(asn1p_constraint_insert(
|
||||
ct, ct_expr->elements[i])) {
|
||||
asn1p_constraint_free(ct_expr);
|
||||
return -1;
|
||||
} else {
|
||||
ct_expr->elements[i] = 0;
|
||||
}
|
||||
}
|
||||
asn1p_constraint_free(ct_expr);
|
||||
} else {
|
||||
ret = asn1p_constraint_insert(ct, ct_expr);
|
||||
assert(ret == 0);
|
||||
}
|
||||
_remove_extensions(arg, ct_expr, 0);
|
||||
|
||||
ct->type = ACT_CA_SET;
|
||||
asn1p_value_free(ct->containedSubtype);
|
||||
ct->containedSubtype = NULL;
|
||||
if(ct_expr->type == ACT_CA_SET) {
|
||||
unsigned int i;
|
||||
for(i = 0; i < ct_expr->el_count; i++) {
|
||||
if(asn1p_constraint_insert(
|
||||
ct, ct_expr->elements[i])) {
|
||||
asn1p_constraint_free(ct_expr);
|
||||
return -1;
|
||||
} else {
|
||||
ct_expr->elements[i] = 0;
|
||||
}
|
||||
}
|
||||
asn1p_constraint_free(ct_expr);
|
||||
} else {
|
||||
ret = asn1p_constraint_insert(ct, ct_expr);
|
||||
assert(ret == 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
ct->type = ACT_CA_SET;
|
||||
asn1p_value_free(ct->containedSubtype);
|
||||
ct->containedSubtype = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -260,7 +260,7 @@
|
|||
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
#line 88 "asn1p_y.y"
|
||||
#line 90 "asn1p_y.y"
|
||||
{
|
||||
asn1p_t *a_grammar;
|
||||
asn1p_module_flags_e a_module_flags;
|
||||
|
|
|
@ -22,6 +22,8 @@ void asn1p_lexer_hack_enable_with_syntax(void);
|
|||
void asn1p_lexer_hack_push_encoding_control(void);
|
||||
#define yylineno asn1p_lineno
|
||||
extern int asn1p_lineno;
|
||||
const char *asn1p_parse_debug_filename;
|
||||
#define ASN_FILENAME asn1p_parse_debug_filename
|
||||
|
||||
/*
|
||||
* Process directives as <ASN1C:RepresentAsPointer>
|
||||
|
@ -295,6 +297,8 @@ static asn1p_module_t *currentModule;
|
|||
%type <tv_str> TypeRefName
|
||||
%type <tv_str> ObjectClassReference
|
||||
%type <tv_str> Identifier
|
||||
%type <a_ref> IdentifierAsReference
|
||||
%type <a_value> IdentifierAsValue
|
||||
%type <tv_str> optIdentifier
|
||||
%type <a_parg> ParameterArgumentName
|
||||
%type <a_plist> ParameterArgumentList
|
||||
|
@ -314,9 +318,16 @@ static asn1p_module_t *currentModule;
|
|||
%type <a_tag> TagClass TagTypeValue TagPlicit
|
||||
%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
|
||||
%type <a_constr> optConstraints
|
||||
%type <a_constr> optSizeConstraints
|
||||
%type <a_constr> Constraint
|
||||
%type <a_constr> SingleTypeConstraint
|
||||
%type <a_constr> MultipleTypeConstraints
|
||||
%type <a_constr> NamedConstraint
|
||||
%type <a_constr> FullSpecification
|
||||
%type <a_constr> PartialSpecification
|
||||
%type <a_constr> TypeConstraints
|
||||
%type <a_constr> ConstraintSpec
|
||||
%type <a_constr> SubtypeConstraint
|
||||
%type <a_constr> ConstraintSpecs
|
||||
%type <a_constr> GeneralConstraint
|
||||
%type <a_constr> SetOfConstraints
|
||||
%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
|
||||
|
@ -331,14 +342,12 @@ static asn1p_module_t *currentModule;
|
|||
%type <a_constr> ContentsConstraint
|
||||
%type <a_constr> PatternConstraint
|
||||
%type <a_constr> InnerTypeConstraint
|
||||
%type <a_constr> WithComponentsList
|
||||
%type <a_constr> WithComponentsElement
|
||||
%type <a_constr> ComponentRelationConstraint
|
||||
%type <a_constr> AtNotationList
|
||||
%type <a_ref> AtNotationElement
|
||||
%type <a_value> SingleValue
|
||||
%type <a_value> ContainedSubtype
|
||||
%type <a_ctype> ConstraintSpec
|
||||
%type <a_ctype> ConstraintType
|
||||
%type <a_ctype> ConstraintRangeSpec
|
||||
%type <a_value> RestrictedCharacterStringValue
|
||||
%type <a_wsynt> optWithSyntax
|
||||
|
@ -505,9 +514,9 @@ ModuleDefinitionFlag:
|
|||
$$ = MSF_XER_INSTRUCTIONS;
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"WARNING: %s INSTRUCTIONS at line %d: "
|
||||
"WARNING: %s INSTRUCTIONS at %s:%d: "
|
||||
"Unrecognized encoding reference\n",
|
||||
$1, yylineno);
|
||||
$1, ASN_FILENAME, yylineno);
|
||||
$$ = MSF_unk_INSTRUCTIONS;
|
||||
}
|
||||
free($1);
|
||||
|
@ -594,8 +603,8 @@ Assignment:
|
|||
{
|
||||
fprintf(stderr,
|
||||
"WARNING: ENCODING-CONTROL %s "
|
||||
"specification at line %d ignored\n",
|
||||
$2, yylineno);
|
||||
"specification at %s:%d ignored\n",
|
||||
$2, ASN_FILENAME, yylineno);
|
||||
free($2);
|
||||
$$ = 0;
|
||||
}
|
||||
|
@ -1263,11 +1272,11 @@ TypeDeclaration:
|
|||
&& ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
|
||||
fprintf(stderr,
|
||||
"INFO: Directive <ASN1C:RepresentAsPointer> "
|
||||
"applied to %s at line %d\n",
|
||||
"applied to %s at %s:%d\n",
|
||||
ASN_EXPR_TYPE2STR($$->expr_type)
|
||||
? ASN_EXPR_TYPE2STR($$->expr_type)
|
||||
: "member",
|
||||
$$->_lineno
|
||||
ASN_FILENAME, $$->_lineno
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1295,7 +1304,7 @@ TypeDeclarationSet:
|
|||
$$->expr_type = ASN_CONSTR_SET;
|
||||
$$->meta_type = AMT_TYPE;
|
||||
}
|
||||
| TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
|
||||
| TOK_SEQUENCE optSizeConstraints TOK_OF optIdentifier optTag TypeDeclaration {
|
||||
$$ = NEW_EXPR();
|
||||
checkmem($$);
|
||||
$$->constraints = $2;
|
||||
|
@ -1305,7 +1314,7 @@ TypeDeclarationSet:
|
|||
$6->tag = $5;
|
||||
asn1p_expr_add($$, $6);
|
||||
}
|
||||
| TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
|
||||
| TOK_SET optSizeConstraints TOK_OF optIdentifier optTag TypeDeclaration {
|
||||
$$ = NEW_EXPR();
|
||||
checkmem($$);
|
||||
$$->constraints = $2;
|
||||
|
@ -1705,56 +1714,45 @@ BasicString:
|
|||
UnionMark: '|' | TOK_UNION;
|
||||
IntersectionMark: '^' | TOK_INTERSECTION;
|
||||
|
||||
/* empty | Constraint */
|
||||
optConstraints:
|
||||
{ $$ = 0; }
|
||||
| Constraint {
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
| Constraint;
|
||||
|
||||
Constraint:
|
||||
SubtypeConstraint
|
||||
;
|
||||
|
||||
SubtypeConstraint:
|
||||
SetOfConstraints {
|
||||
CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
|
||||
}
|
||||
| TOK_SIZE '(' ConstraintSpecs ')' {
|
||||
/*
|
||||
* This is a special case, for compatibility purposes.
|
||||
* It goes without parentheses.
|
||||
*/
|
||||
/* empty | Constraint | SIZE(...) */
|
||||
optSizeConstraints:
|
||||
{ $$ = 0; }
|
||||
| Constraint
|
||||
| TOK_SIZE '(' ConstraintSpec ')' {
|
||||
CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
|
||||
}
|
||||
;
|
||||
|
||||
Constraint:
|
||||
SetOfConstraints {
|
||||
CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
|
||||
}
|
||||
;
|
||||
|
||||
SetOfConstraints:
|
||||
'(' ConstraintSpecs ')' {
|
||||
'(' ConstraintSpec ')' {
|
||||
$$ = $2;
|
||||
}
|
||||
| SetOfConstraints '(' ConstraintSpecs ')' {
|
||||
| SetOfConstraints '(' ConstraintSpec ')' {
|
||||
CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
|
||||
}
|
||||
;
|
||||
|
||||
ConstraintSpecs:
|
||||
ElementSetSpecs {
|
||||
$$ = $1;
|
||||
}
|
||||
| GeneralConstraint {
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
ConstraintSpec: SubtypeConstraint | GeneralConstraint;
|
||||
|
||||
SubtypeConstraint: ElementSetSpecs;
|
||||
|
||||
ElementSetSpecs:
|
||||
TOK_ThreeDots {
|
||||
$$ = asn1p_constraint_new(yylineno, currentModule);
|
||||
$$->type = ACT_EL_EXT;
|
||||
}
|
||||
| ElementSetSpec {
|
||||
$$ = $1;
|
||||
}
|
||||
| ElementSetSpec
|
||||
| ElementSetSpec ',' TOK_ThreeDots {
|
||||
asn1p_constraint_t *ct;
|
||||
ct = asn1p_constraint_new(yylineno, currentModule);
|
||||
|
@ -1801,7 +1799,7 @@ IntersectionElements:
|
|||
;
|
||||
|
||||
ConstraintSubtypeElement:
|
||||
ConstraintSpec '(' ElementSetSpecs ')' {
|
||||
ConstraintType '(' ElementSetSpecs ')' {
|
||||
int ret;
|
||||
$$ = asn1p_constraint_new(yylineno, currentModule);
|
||||
checkmem($$);
|
||||
|
@ -1861,12 +1859,8 @@ ConstraintSubtypeElement:
|
|||
$$->range_start->type = ATV_MIN;
|
||||
$$->range_stop->type = ATV_MAX;
|
||||
}
|
||||
| InnerTypeConstraint {
|
||||
$$ = $1;
|
||||
}
|
||||
| PatternConstraint {
|
||||
$$ = $1;
|
||||
}
|
||||
| InnerTypeConstraint
|
||||
| PatternConstraint
|
||||
| '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
|
||||
$$ = asn1p_constraint_new(yylineno, currentModule);
|
||||
checkmem($$);
|
||||
|
@ -1893,7 +1887,7 @@ PatternConstraint:
|
|||
}
|
||||
;
|
||||
|
||||
ConstraintSpec:
|
||||
ConstraintType:
|
||||
TOK_SIZE {
|
||||
$$ = ACT_CT_SIZE;
|
||||
}
|
||||
|
@ -1943,62 +1937,66 @@ BitStringValue:
|
|||
;
|
||||
|
||||
ContainedSubtype:
|
||||
ComplexTypeReference {
|
||||
$$ = asn1p_value_fromref($1, 0);
|
||||
Type {
|
||||
$$ = asn1p_value_fromtype($1);
|
||||
checkmem($$);
|
||||
}
|
||||
/*
|
||||
TypeRefName {
|
||||
asn1p_ref_t *ref;
|
||||
int ret;
|
||||
ref = asn1p_ref_new(yylineno, currentModule);
|
||||
checkmem(ref);
|
||||
ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
|
||||
checkmem(ret == 0);
|
||||
$$ = asn1p_value_fromref(ref, 0);
|
||||
checkmem($$);
|
||||
free($1);
|
||||
}
|
||||
*/
|
||||
}
|
||||
;
|
||||
|
||||
/*
|
||||
* X.680 08/2015
|
||||
* #51.8.5
|
||||
*/
|
||||
InnerTypeConstraint:
|
||||
TOK_WITH TOK_COMPONENT SetOfConstraints {
|
||||
TOK_WITH TOK_COMPONENT SingleTypeConstraint {
|
||||
CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
|
||||
}
|
||||
| TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
|
||||
CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
|
||||
| TOK_WITH TOK_COMPONENTS MultipleTypeConstraints {
|
||||
assert($3->type == ACT_CA_CSV);
|
||||
$3->type = ACT_CT_WCOMPS;
|
||||
$$ = $3;
|
||||
}
|
||||
;
|
||||
|
||||
WithComponentsList:
|
||||
WithComponentsElement {
|
||||
$$ = $1;
|
||||
}
|
||||
| WithComponentsList ',' WithComponentsElement {
|
||||
CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
|
||||
}
|
||||
;
|
||||
|
||||
WithComponentsElement:
|
||||
TOK_ThreeDots {
|
||||
SingleTypeConstraint: Constraint;
|
||||
MultipleTypeConstraints: FullSpecification | PartialSpecification;
|
||||
FullSpecification: '{' TypeConstraints '}' { $$ = $2; };
|
||||
PartialSpecification:
|
||||
'{' TOK_ThreeDots ',' TypeConstraints '}' {
|
||||
assert($4->type == ACT_CA_CSV);
|
||||
$$ = asn1p_constraint_new(yylineno, currentModule);
|
||||
$$->type = ACT_CA_CSV;
|
||||
asn1p_constraint_t *ct = asn1p_constraint_new(yylineno, currentModule);
|
||||
checkmem($$);
|
||||
$$->type = ACT_EL_EXT;
|
||||
$$->value = asn1p_value_frombuf("...", 3, 1);
|
||||
}
|
||||
| Identifier optConstraints optPresenceConstraint {
|
||||
$$ = asn1p_constraint_new(yylineno, currentModule);
|
||||
checkmem($$);
|
||||
$$->type = ACT_EL_VALUE;
|
||||
$$->value = asn1p_value_frombuf($1, strlen($1), 0);
|
||||
$$->presence = $3;
|
||||
if($2) asn1p_constraint_insert($$, $2);
|
||||
ct->type = ACT_EL_EXT;
|
||||
asn1p_constraint_insert($$, ct);
|
||||
for(unsigned i = 0; i < $4->el_count; i++) {
|
||||
asn1p_constraint_insert($$, $4->elements[i]);
|
||||
}
|
||||
};
|
||||
TypeConstraints:
|
||||
NamedConstraint {
|
||||
$$ = asn1p_constraint_new(yylineno, currentModule);
|
||||
$$->type = ACT_CA_CSV;
|
||||
asn1p_constraint_insert($$, $1);
|
||||
}
|
||||
| TypeConstraints ',' NamedConstraint {
|
||||
$$ = $1;
|
||||
asn1p_constraint_insert($$, $3);
|
||||
}
|
||||
;
|
||||
NamedConstraint:
|
||||
IdentifierAsValue optConstraints optPresenceConstraint {
|
||||
$$ = asn1p_constraint_new(yylineno, currentModule);
|
||||
checkmem($$);
|
||||
$$->type = ACT_EL_VALUE;
|
||||
$$->value = $1;
|
||||
if($2) asn1p_constraint_insert($$, $2);
|
||||
$$->presence = $3;
|
||||
}
|
||||
;
|
||||
|
||||
/*
|
||||
* presence constraint for WithComponents
|
||||
* presence constraint for NamedConstraint
|
||||
*/
|
||||
optPresenceConstraint:
|
||||
{ $$ = ACPRES_DEFAULT; }
|
||||
|
@ -2361,6 +2359,17 @@ Identifier:
|
|||
}
|
||||
;
|
||||
|
||||
IdentifierAsReference:
|
||||
Identifier {
|
||||
$$ = asn1p_ref_new(yylineno, currentModule);
|
||||
asn1p_ref_add_component($$, $1, RLT_lowercase);
|
||||
};
|
||||
|
||||
IdentifierAsValue:
|
||||
IdentifierAsReference {
|
||||
$$ = asn1p_value_fromref($1, 0);
|
||||
};
|
||||
|
||||
%%
|
||||
|
||||
|
||||
|
@ -2505,8 +2514,8 @@ yyerror(const char *msg) {
|
|||
extern char *asn1p_text;
|
||||
fprintf(stderr,
|
||||
"ASN.1 grammar parse error "
|
||||
"near line %d (token \"%s\"): %s\n",
|
||||
yylineno, asn1p_text, msg);
|
||||
"near %s:%d (token \"%s\"): %s\n",
|
||||
ASN_FILENAME, yylineno, asn1p_text, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,9 @@ asn1p_parse_buffer(const char *buffer, int size /* = -1 */, enum asn1p_flags fla
|
|||
if(size < 0)
|
||||
size = (int)strlen(buffer);
|
||||
|
||||
asn1p_parse_debug_filename = "<stdin>";
|
||||
ybuf = asn1p__scan_bytes(buffer, size);
|
||||
asn1p_parse_debug_filename = NULL;
|
||||
if(!ybuf) {
|
||||
assert(ybuf);
|
||||
return 0;
|
||||
|
@ -106,7 +108,9 @@ asn1p_parse_file(const char *filename, enum asn1p_flags flags) {
|
|||
asn1p_restart(fp);
|
||||
|
||||
ap = (void *)&a;
|
||||
asn1p_parse_debug_filename = filename;
|
||||
ret = asn1p_parse(ap);
|
||||
asn1p_parse_debug_filename = NULL;
|
||||
|
||||
fclose(fp);
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ asn1p_t *asn1p_parse_file(const char *filename,
|
|||
asn1p_t *asn1p_parse_buffer(const char *buffer, int size /* = -1 */,
|
||||
enum asn1p_flags);
|
||||
|
||||
extern const char *asn1p_parse_debug_filename;
|
||||
|
||||
int asn1p_lex_destroy();
|
||||
|
||||
#endif /* ASN1PARSER_H */
|
||||
|
|
|
@ -337,6 +337,7 @@ asn1p_constraint_string(const asn1p_constraint_t *ct) {
|
|||
static int
|
||||
asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
|
||||
int symno = 0;
|
||||
int perhaps_subconstraints = 0;
|
||||
|
||||
if(ct == 0) return 0;
|
||||
|
||||
|
@ -346,9 +347,11 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
|
|||
switch(ct->type) {
|
||||
case ACT_EL_TYPE:
|
||||
asn1print_value(ct->containedSubtype, flags);
|
||||
perhaps_subconstraints = 1;
|
||||
break;
|
||||
case ACT_EL_VALUE:
|
||||
asn1print_value(ct->value, flags);
|
||||
perhaps_subconstraints = 1;
|
||||
break;
|
||||
case ACT_EL_RANGE:
|
||||
case ACT_EL_LLRANGE:
|
||||
|
@ -382,9 +385,8 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
|
|||
case ACT_CT_WCOMP:
|
||||
assert(ct->el_count != 0);
|
||||
assert(ct->el_count == 1);
|
||||
safe_printf("WITH COMPONENT (");
|
||||
asn1print_constraint(ct->elements[0], flags);
|
||||
safe_printf(")");
|
||||
safe_printf("WITH COMPONENT");
|
||||
perhaps_subconstraints = 1;
|
||||
break;
|
||||
case ACT_CT_WCOMPS: {
|
||||
unsigned int i;
|
||||
|
@ -392,14 +394,7 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
|
|||
for(i = 0; i < ct->el_count; i++) {
|
||||
asn1p_constraint_t *cel = ct->elements[i];
|
||||
if(i) safe_printf(", ");
|
||||
safe_fwrite(cel->value->value.string.buf,
|
||||
cel->value->value.string.size);
|
||||
if(cel->el_count) {
|
||||
assert(cel->el_count == 1);
|
||||
safe_printf(" ");
|
||||
asn1print_constraint(cel->elements[0],
|
||||
flags);
|
||||
}
|
||||
asn1print_constraint(cel, flags);
|
||||
switch(cel->presence) {
|
||||
case ACPRES_DEFAULT: break;
|
||||
case ACPRES_PRESENT: safe_printf(" PRESENT"); break;
|
||||
|
@ -441,22 +436,27 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
|
|||
if(ct->type == ACT_CA_CRC) safe_printf("{");
|
||||
asn1print_constraint(ct->elements[i], flags);
|
||||
if(ct->type == ACT_CA_CRC) safe_printf("}");
|
||||
if(i+1 < ct->el_count
|
||||
&& ct->type == ACT_CA_SET)
|
||||
safe_printf(")");
|
||||
if(ct->type == ACT_CA_SET && i+1 < ct->el_count)
|
||||
safe_printf(") ");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ACT_CA_AEX:
|
||||
assert(ct->el_count == 1);
|
||||
safe_printf("ALL EXCEPT ");
|
||||
asn1print_constraint(ct->elements[0], flags);
|
||||
safe_printf("ALL EXCEPT");
|
||||
perhaps_subconstraints = 1;
|
||||
break;
|
||||
case ACT_INVALID:
|
||||
assert(ct->type != ACT_INVALID);
|
||||
break;
|
||||
}
|
||||
|
||||
if(perhaps_subconstraints && ct->el_count) {
|
||||
safe_printf(" ");
|
||||
assert(ct->el_count == 1);
|
||||
asn1print_constraint(ct->elements[0], flags);
|
||||
}
|
||||
|
||||
if(ct->type == ACT_CA_SET)
|
||||
safe_printf(")");
|
||||
|
||||
|
@ -591,8 +591,25 @@ asn1print_constraint_explain(const char *dbg_name, asn1p_expr_type_e expr_type,
|
|||
static int
|
||||
asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level) {
|
||||
int SEQ_OF = 0;
|
||||
int has_space = 0;
|
||||
|
||||
if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT))
|
||||
#define HAS_SPACE() \
|
||||
do { \
|
||||
has_space = 1; \
|
||||
} while(0)
|
||||
#define ENSURE_SPACE() \
|
||||
do { \
|
||||
if(!has_space) { \
|
||||
has_space = 1; \
|
||||
safe_printf(" "); \
|
||||
} \
|
||||
} while(0)
|
||||
#define WANT_SPACE() \
|
||||
do { \
|
||||
has_space = 0; \
|
||||
} while(0)
|
||||
|
||||
if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT))
|
||||
INDENT("-- #line %d\n", tc->_lineno);
|
||||
|
||||
/* Reconstruct compiler directive information */
|
||||
|
@ -606,8 +623,10 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
|
|||
|
||||
if(tc->Identifier
|
||||
&& (!(tc->meta_type == AMT_VALUE && tc->expr_type == A1TC_REFERENCE)
|
||||
|| level == 0))
|
||||
|| level == 0)) {
|
||||
INDENT("%s", tc->Identifier);
|
||||
WANT_SPACE();
|
||||
}
|
||||
|
||||
if(tc->lhs_params) {
|
||||
asn1print_params(tc->lhs_params, flags);
|
||||
|
@ -619,14 +638,17 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
|
|||
if(level) {
|
||||
if(tc->Identifier && !(flags & APF_NOINDENT))
|
||||
safe_printf("\t");
|
||||
} else {
|
||||
safe_printf(" ::=");
|
||||
} else if(tc->Identifier) {
|
||||
ENSURE_SPACE();
|
||||
safe_printf("::=");
|
||||
WANT_SPACE();
|
||||
}
|
||||
}
|
||||
|
||||
if(tc->tag.tag_class) {
|
||||
safe_printf(" ");
|
||||
ENSURE_SPACE();
|
||||
asn1print_tag(tc, flags);
|
||||
WANT_SPACE();
|
||||
}
|
||||
|
||||
switch(tc->expr_type) {
|
||||
|
@ -639,12 +661,14 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
|
|||
case A1TC_COMPONENTS_OF:
|
||||
SEQ_OF = 1; /* Equivalent to SET OF for printint purposes */
|
||||
safe_printf(" COMPONENTS OF");
|
||||
WANT_SPACE();
|
||||
break;
|
||||
case A1TC_REFERENCE:
|
||||
case A1TC_UNIVERVAL:
|
||||
break;
|
||||
case A1TC_CLASSDEF:
|
||||
safe_printf(" CLASS");
|
||||
WANT_SPACE();
|
||||
break;
|
||||
case A1TC_CLASSFIELD_TFS ... A1TC_CLASSFIELD_OSFS:
|
||||
/* Nothing to print here */
|
||||
|
@ -652,22 +676,26 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
|
|||
case ASN_CONSTR_SET_OF:
|
||||
case ASN_CONSTR_SEQUENCE_OF:
|
||||
SEQ_OF = 1;
|
||||
ENSURE_SPACE();
|
||||
if(tc->expr_type == ASN_CONSTR_SET_OF)
|
||||
safe_printf(" SET");
|
||||
safe_printf("SET");
|
||||
else
|
||||
safe_printf(" SEQUENCE");
|
||||
safe_printf("SEQUENCE");
|
||||
if(tc->constraints) {
|
||||
safe_printf(" ");
|
||||
asn1print_constraint(tc->constraints, flags);
|
||||
}
|
||||
safe_printf(" OF");
|
||||
WANT_SPACE();
|
||||
break;
|
||||
case A1TC_VALUESET:
|
||||
break;
|
||||
default:
|
||||
{
|
||||
char *p = ASN_EXPR_TYPE2STR(tc->expr_type);
|
||||
safe_printf(" %s", p?p:"<unknown type!>");
|
||||
ENSURE_SPACE();
|
||||
safe_printf("%s", p?p:"<unknown type!>");
|
||||
WANT_SPACE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -676,12 +704,16 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
|
|||
* Put the name of the referred type.
|
||||
*/
|
||||
if(tc->reference) {
|
||||
safe_printf(" ");
|
||||
ENSURE_SPACE();
|
||||
asn1print_ref(tc->reference, flags);
|
||||
WANT_SPACE();
|
||||
}
|
||||
|
||||
if(tc->meta_type == AMT_VALUESET && level == 0)
|
||||
safe_printf(" ::=");
|
||||
if(tc->meta_type == AMT_VALUESET && level == 0) {
|
||||
ENSURE_SPACE();
|
||||
safe_printf("::=");
|
||||
WANT_SPACE();
|
||||
}
|
||||
|
||||
/*
|
||||
* Display the descendants (children) of the current type.
|
||||
|
@ -775,7 +807,7 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
|
|||
safe_printf(")");
|
||||
}
|
||||
} else {
|
||||
if(level == 0) safe_printf(" ::= ");
|
||||
if(level == 0 && tc->Identifier) safe_printf(" ::= ");
|
||||
asn1print_value(tc->value, flags);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ BEGIN
|
|||
PCLASS {Type, INTEGER:value, INTEGER:ValueSet} ::= CLASS {
|
||||
&valueField1 Type,
|
||||
&valueField2 INTEGER DEFAULT value,
|
||||
&valueField3 INTEGER (ValueSet),
|
||||
&valueField3 INTEGER ({ValueSet}),
|
||||
&ValueSetField INTEGER DEFAULT {ValueSet}
|
||||
} WITH SYNTAX {
|
||||
&valueField1, &valueField2, &valueField3, &ValueSetField }
|
||||
|
|
|
@ -6,7 +6,7 @@ BEGIN
|
|||
PCLASS{Type, INTEGER:value, INTEGER:ValueSet} ::= CLASS {
|
||||
&valueField1 Type,
|
||||
&valueField2 INTEGER DEFAULT value,
|
||||
&valueField3 INTEGER (ValueSet),
|
||||
&valueField3 INTEGER ({ValueSet}),
|
||||
&ValueSetField INTEGER DEFAULT {ValueSet}
|
||||
} WITH SYNTAX {
|
||||
&valueField1, &valueField2, &valueField3, &ValueSetField }
|
||||
|
|
Binary file not shown.
|
@ -3,6 +3,6 @@ ModuleMultiConstraint { iso org(3) dod(6) internet(1) private(4) enterprise(1)
|
|||
DEFINITIONS AUTOMATIC TAGS ::=
|
||||
BEGIN
|
||||
|
||||
T ::= VisibleString (PATTERN "^[a-z]+$")(CONSTRAINED BY { ... })
|
||||
T ::= VisibleString (PATTERN "^[a-z]+$") (CONSTRAINED BY { ... })
|
||||
|
||||
END
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
-- SE: Semantic error
|
||||
|
||||
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
|
||||
-- .spelio.software.asn1c.test (9363.1.5.1)
|
||||
-- .149
|
||||
|
||||
ModuleComplexWithComponents
|
||||
{ iso org(3) dod(6) internet(1) private(4) enterprise(1)
|
||||
spelio(9363) software(1) asn1c(5) test(1) 149 }
|
||||
DEFINITIONS ::= BEGIN
|
||||
|
||||
Certificate ::= ExplicitCertificate (WITH COMPONENTS { ...,
|
||||
issuer (WITH COMPONENTS {sha256AndDigest}),
|
||||
toBeSigned (WITH COMPONENTS { ...,
|
||||
id (WITH COMPONENTS {
|
||||
name ("foo" | "bar") -- Some comment
|
||||
}),
|
||||
crlSeries(ScmsSpclComponentCrlSeries),
|
||||
validityPeriod (WITH COMPONENTS { ...,
|
||||
duration (CrlgCertExpiration)
|
||||
}),
|
||||
region (WITH COMPONENTS {
|
||||
identifiedRegion (SequenceOfIdentifiedRegion (SIZE(3)) (CONSTRAINED BY {
|
||||
IdentifiedRegion ( WITH COMPONENTS { countryOnly(Canada) }),
|
||||
IdentifiedRegion ( WITH COMPONENTS { countryOnly(Mexico) }),
|
||||
IdentifiedRegion ( WITH COMPONENTS { countryOnly(USA) })
|
||||
}))
|
||||
}),
|
||||
canRequestRollover (NULL),
|
||||
encryptionKey ABSENT,
|
||||
verifyKeyIndicator (WITH COMPONENTS {
|
||||
verificationKey (WITH COMPONENTS {
|
||||
ecdsaNistP256 (WITH COMPONENTS {
|
||||
compressed-y-0, compressed-y-1
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
END
|
|
@ -0,0 +1,12 @@
|
|||
ModuleComplexWithComponents { iso org(3) dod(6) internet(1) private(4)
|
||||
enterprise(1) spelio(9363) software(1) asn1c(5) test(1) 149 }
|
||||
DEFINITIONS ::=
|
||||
BEGIN
|
||||
|
||||
Certificate ::= ExplicitCertificate (WITH COMPONENTS { ..., issuer (WITH COMPONENTS { sha256AndDigest }), toBeSigned (WITH COMPONENTS { ..., id (WITH COMPONENTS { name ("foo" | "bar") }), crlSeries ( ScmsSpclComponentCrlSeries), validityPeriod (WITH COMPONENTS { ..., duration ( CrlgCertExpiration) }), region (WITH COMPONENTS { identifiedRegion ( SequenceOfIdentifiedRegion (SIZE(3)) (CONSTRAINED BY {
|
||||
IdentifiedRegion ( WITH COMPONENTS { countryOnly(Canada) }),
|
||||
IdentifiedRegion ( WITH COMPONENTS { countryOnly(Mexico) }),
|
||||
IdentifiedRegion ( WITH COMPONENTS { countryOnly(USA) })
|
||||
})) }), canRequestRollover ( NULL), encryptionKey ABSENT, verifyKeyIndicator (WITH COMPONENTS { verificationKey (WITH COMPONENTS { ecdsaNistP256 (WITH COMPONENTS { compressed-y-0, compressed-y-1 }) }) }) }) })
|
||||
|
||||
END
|
|
@ -3,9 +3,9 @@ ModuleTestConstraint1 { iso org(3) dod(6) internet(1) private(4) enterprise(1)
|
|||
DEFINITIONS ::=
|
||||
BEGIN
|
||||
|
||||
Type0 ::= IA5String (((SIZE(1..10))(FROM("a".."z" | "#"))))
|
||||
Type0 ::= IA5String (((SIZE(1..10)) (FROM("a".."z" | "#"))))
|
||||
|
||||
Type6 ::= IA5String ((SIZE(1..10))(FROM("a".."z" | "#")))
|
||||
Type6 ::= IA5String ((SIZE(1..10)) (FROM("a".."z" | "#")))
|
||||
|
||||
END
|
||||
|
||||
|
@ -14,7 +14,7 @@ ModuleTestConstraint2 { iso org(3) dod(6) internet(1) private(4) enterprise(1)
|
|||
DEFINITIONS ::=
|
||||
BEGIN
|
||||
|
||||
Type1 ::= IA5String (SIZE(1..10,...))(FROM("a".."z" | "#",...))
|
||||
Type1 ::= IA5String (SIZE(1..10,...)) (FROM("a".."z" | "#",...))
|
||||
|
||||
Type2 ::= IA5String (SIZE(MIN..4) | FROM("abc"))
|
||||
|
||||
|
|
Binary file not shown.
|
@ -14,7 +14,7 @@ BEGIN
|
|||
SIGNED { ToBeSigned } ::= SEQUENCE {
|
||||
toBeSigned ToBeSigned,
|
||||
algorithm OBJECT IDENTIFIER,
|
||||
signature BIT STRING SIZE(0..256)
|
||||
signature BIT STRING (SIZE(0..256))
|
||||
}
|
||||
|
||||
Certificate ::= SIGNED { SEQUENCE {
|
||||
|
|
|
@ -6,7 +6,7 @@ BEGIN
|
|||
SIGNED{ToBeSigned} ::= SEQUENCE {
|
||||
toBeSigned ToBeSigned,
|
||||
algorithm OBJECT IDENTIFIER,
|
||||
signature BIT STRING SIZE(0..256)
|
||||
signature BIT STRING (SIZE(0..256))
|
||||
}
|
||||
|
||||
Certificate ::= SIGNED{ SEQUENCE {
|
||||
|
|
Binary file not shown.
|
@ -31,13 +31,13 @@ BEGIN
|
|||
Type2 ::= CHOICE {
|
||||
one-name SEQUENCE {
|
||||
another-name SEQUENCE {
|
||||
a BIT STRING { one(0) } SIZE(2),
|
||||
a BIT STRING { one(0) } (SIZE(2)),
|
||||
b INTEGER
|
||||
}
|
||||
},
|
||||
two-name SET {
|
||||
another-name SEQUENCE {
|
||||
a BIT STRING { one(0) } SIZE(2),
|
||||
a BIT STRING { one(0) } (SIZE(2)),
|
||||
b INTEGER
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ Int ::= INTEGER {
|
|||
-- PER-visible constraints (Int): (123)
|
||||
|
||||
EnumRef ::= Enum (1)
|
||||
-- Combined constraints: (1 | 0)(1)
|
||||
-- Combined constraints: (1 | 0) (1)
|
||||
-- Practical constraints (Enum): (1)
|
||||
-- OER-visible constraints (Enum): (1)
|
||||
-- PER-visible constraints (Enum): (1)
|
||||
|
|
|
@ -5,7 +5,7 @@ BEGIN
|
|||
|
||||
BunchOfStrings ::= SEQUENCE OF VisibleString
|
||||
|
||||
Address ::= BunchOfStrings (SIZE(1..6))(WITH COMPONENT (SIZE(1..32)))
|
||||
Address ::= BunchOfStrings (SIZE(1..6)) (WITH COMPONENT (SIZE(1..32)))
|
||||
|
||||
Type ::= SEQUENCE {
|
||||
one INTEGER DEFAULT 1
|
||||
|
|
|
@ -11,10 +11,10 @@ ModuleTestWithComponents2
|
|||
DEFINITIONS ::=
|
||||
BEGIN
|
||||
|
||||
Type1 ::= SET {}
|
||||
Type1 ::= SET { foo INTEGER OPTIONAL }
|
||||
|
||||
Type2 ::= SET {
|
||||
COMPONENTS OF Type1 (WITH COMPONENTS { ... })
|
||||
COMPONENTS OF Type1 (WITH COMPONENTS { ..., foo ABSENT })
|
||||
}
|
||||
|
||||
END
|
||||
|
|
Loading…
Reference in New Issue