diff options
author | Lev Walkin <vlm@lionet.info> | 2017-09-06 22:15:08 -0700 |
---|---|---|
committer | Lev Walkin <vlm@lionet.info> | 2017-09-06 22:15:08 -0700 |
commit | d523ea454d0f4bcf851d883e9fd90cc10145b242 (patch) | |
tree | 863f69c02b7f51eb616fe862abe2b47ee6d29ab5 /libasn1fix | |
parent | 8460940d54c8daf8b4a54a8ef8a4a490e01488ee (diff) |
parse advanced WITH COMPONENTS
Diffstat (limited to 'libasn1fix')
-rw-r--r-- | libasn1fix/asn1fix_constraint.c | 121 |
1 files changed, 67 insertions, 54 deletions
diff --git a/libasn1fix/asn1fix_constraint.c b/libasn1fix/asn1fix_constraint.c index 823fca32..46eddaaa 100644 --- a/libasn1fix/asn1fix_constraint.c +++ b/libasn1fix/asn1fix_constraint.c @@ -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; - } - - 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; - } - - ct_expr = asn1p_constraint_clone(ct_expr); - assert(ct_expr); - - _remove_extensions(arg, ct_expr, 0); + 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 constraint kind %s at line %d", + asn1f_printable_value(ct->containedSubtype), ct->_lineno); + return -1; + } - 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); - } + ct_expr = asn1p_constraint_clone(ct_expr); + assert(ct_expr); + + _remove_extensions(arg, ct_expr, 0); + + 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); + } - ct->type = ACT_CA_SET; - asn1p_value_free(ct->containedSubtype); - ct->containedSubtype = NULL; + ct->type = ACT_CA_SET; + asn1p_value_free(ct->containedSubtype); + ct->containedSubtype = NULL; - return 0; + return 0; } static int |