Skip to content

Commit

Permalink
fix WITH DESCENDANTS; tests for WITH DESCENDANTS
Browse files Browse the repository at this point in the history
  • Loading branch information
DanyaFilatov authored and v0-e committed Nov 9, 2023
1 parent d3faf7f commit 6d97ce9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
11 changes: 9 additions & 2 deletions libasn1fix/asn1fix_retrieve.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ asn1f_lookup_module(arg_t *arg, const char *module_name, const asn1p_oid_t *oid,
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
if(oid) {
if(mod->module_oid) {
if(0 == asn1p_oid_compare_opt(oid,
mod->module_oid, oid_option)) {
int r = asn1p_oid_compare(oid, mod->module_oid);
if(oid_option == XPT_WITH_SUCCESSORS) {
if(r == oid->arcs_count && r == mod->module_oid->arcs_count) /* positive and last arc */
r = 0;
} else if(oid_option == XPT_WITH_DESCENDANTS) {
if(oid->arcs_count == (-1 - r))
r = 0;
}
if(0 == r) {
/* Match! Even if name doesn't. */
oid = mod->module_oid;
ret = mod;
Expand Down
15 changes: 0 additions & 15 deletions libasn1parser/asn1p_oid.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,3 @@ asn1p_oid_compare(const asn1p_oid_t *a, const asn1p_oid_t *b) {
return 1+i;
}
}

int
asn1p_oid_compare_opt(const asn1p_oid_t *a, const asn1p_oid_t *b, int oid_options) {
int r = asn1p_oid_compare(a, b);
if(oid_options == OID_WITH_SUCCESSORS) {
if(r == a->arcs_count && r == b->arcs_count) /* positive and last arc */
r = 0;
} else if(oid_options == OID_WITH_DESCENDANTS) {
if(a->arcs_count == (0 - r))
r = 0;
}
return r;
}


5 changes: 0 additions & 5 deletions libasn1parser/asn1p_oid.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,4 @@ void asn1p_oid_free(asn1p_oid_t *);
*/
int asn1p_oid_compare(const asn1p_oid_t *a, const asn1p_oid_t *b);

#define OID_WITH_SUCCESSORS 1
#define OID_WITH_DESCENDANTS 2
int asn1p_oid_compare_opt(const asn1p_oid_t *a, const asn1p_oid_t *b, int oid_option);


#endif /* ASN1_PARSER_OID_H */
5 changes: 4 additions & 1 deletion libasn1parser/asn1p_xports.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ typedef struct asn1p_xports_s {
asn1p_value_t *value; /* DefinedValue */
} identifier;

int option; /* (0) | WITH SUCCESSORS (1) | WITH DESCENDANTS (2) */
enum asn1p_import_option {
XPT_WITH_SUCCESSORS = 1,
XPT_WITH_DESCENDANTS
} option;

/*
* Number of entities to import.
Expand Down
4 changes: 2 additions & 2 deletions libasn1parser/asn1p_y.y
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,10 @@ ImportsElement:

ImportSelectionOption:
TOK_WITH TOK_SUCCESSORS {
$$ = OID_WITH_SUCCESSORS;
$$ = XPT_WITH_SUCCESSORS;
}
| TOK_WITH TOK_DESCENDANTS {
$$ = OID_WITH_DESCENDANTS;
$$ = XPT_WITH_DESCENDANTS;
}
;

Expand Down
36 changes: 36 additions & 0 deletions tests/tests-asn1c-compiler/163-imports-with-descendants-OK.asn1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

-- OK: Everything is fine

-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .121

ModuleIMPORTS
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 161 }
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

IMPORTS ImportedType
FROM ImportedModule1
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 163 major-version-1(1) }
WITH DESCENDANTS
;

Type ::= ImportedType

END


ImportedModule1
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 163 major-version-1(1) super-minor-version(1) super-minor-version(1)}
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

IMPORTS -- nothing --;

ImportedType ::= INTEGER

END

0 comments on commit 6d97ce9

Please sign in to comment.