Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
ea6635bd
Commit
ea6635bd
authored
Aug 06, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better parsing information object class sets
parent
e700b208
Changes
27
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
779 additions
and
91 deletions
+779
-91
libasn1compiler/asn1c_C.c
libasn1compiler/asn1c_C.c
+79
-1
libasn1fix/asn1fix.c
libasn1fix/asn1fix.c
+4
-4
libasn1fix/asn1fix_class.c
libasn1fix/asn1fix_class.c
+1
-1
libasn1fix/asn1fix_class.h
libasn1fix/asn1fix_class.h
+1
-1
libasn1fix/asn1fix_constraint.c
libasn1fix/asn1fix_constraint.c
+1
-1
libasn1fix/asn1fix_cws.c
libasn1fix/asn1fix_cws.c
+226
-60
libasn1fix/asn1fix_export.c
libasn1fix/asn1fix_export.c
+2
-2
libasn1fix/asn1fix_export.h
libasn1fix/asn1fix_export.h
+3
-3
libasn1fix/asn1fix_misc.c
libasn1fix/asn1fix_misc.c
+2
-7
libasn1fix/asn1fix_retrieve.c
libasn1fix/asn1fix_retrieve.c
+3
-3
libasn1fix/asn1fix_retrieve.h
libasn1fix/asn1fix_retrieve.h
+2
-2
libasn1parser/asn1p_class.c
libasn1parser/asn1p_class.c
+30
-0
libasn1parser/asn1p_class.h
libasn1parser/asn1p_class.h
+7
-0
libasn1parser/asn1p_constr.c
libasn1parser/asn1p_constr.c
+39
-0
libasn1parser/asn1p_constr.h
libasn1parser/asn1p_constr.h
+8
-0
libasn1parser/asn1p_expr.c
libasn1parser/asn1p_expr.c
+76
-0
libasn1parser/asn1p_expr.h
libasn1parser/asn1p_expr.h
+3
-0
libasn1parser/asn1p_oid.c
libasn1parser/asn1p_oid.c
+1
-1
libasn1parser/asn1p_oid.h
libasn1parser/asn1p_oid.h
+1
-1
libasn1parser/asn1p_ref.c
libasn1parser/asn1p_ref.c
+58
-4
libasn1parser/asn1p_ref.h
libasn1parser/asn1p_ref.h
+14
-0
libasn1parser/asn1p_value.c
libasn1parser/asn1p_value.c
+78
-0
libasn1parser/asn1p_value.h
libasn1parser/asn1p_value.h
+3
-0
tests/139-component-relation-OK.asn1
tests/139-component-relation-OK.asn1
+36
-0
tests/139-component-relation-OK.asn1.-EFprint-class-matrix
tests/139-component-relation-OK.asn1.-EFprint-class-matrix
+31
-0
tests/140-component-relation-OK.asn1
tests/140-component-relation-OK.asn1
+35
-0
tests/140-component-relation-OK.asn1.-EFprint-class-matrix
tests/140-component-relation-OK.asn1.-EFprint-class-matrix
+35
-0
No files found.
libasn1compiler/asn1c_C.c
View file @
ea6635bd
...
...
@@ -298,15 +298,91 @@ asn1c_lang_C_type_BIT_STRING(arg_t *arg) {
return
asn1c_lang_C_type_SIMPLE_TYPE
(
arg
);
}
/*
* Given the table constraint or component relation constraint
* ({ObjectSetName}{...}) returns "ObjectSetName" as a reference.
*/
static
const
asn1p_ref_t
*
asn1c_get_information_object_set_reference_from_constraint
(
const
asn1p_constraint_t
*
ct
)
{
if
(
!
ct
)
return
NULL
;
assert
(
ct
->
type
==
ACT_CA_CRC
);
assert
(
ct
->
el_count
>=
1
);
assert
(
ct
->
elements
[
0
]
->
type
==
ACT_EL_VALUE
);
asn1p_value_t
*
val
=
ct
->
elements
[
0
]
->
value
;
assert
(
val
->
type
==
ATV_REFERENCED
);
return
val
->
value
.
reference
;
}
typedef
struct
asn1c_ioc_table_s
{
}
asn1c_ioc_table_t
;
static
asn1c_ioc_table_t
*
asn1c_construct_ioc_table_from_objset
(
arg_t
*
arg
,
const
asn1p_ref_t
*
objset_ref
,
asn1p_expr_t
*
objset
)
{
asn1c_ioc_table_t
*
itable
=
NULL
;
itable
=
calloc
(
1
,
sizeof
(
*
itable
));
assert
(
itable
);
return
itable
;
};
static
asn1c_ioc_table_t
*
asn1c_construct_ioc_table
(
arg_t
*
arg
)
{
asn1p_expr_t
*
expr
=
arg
->
expr
;
asn1p_expr_t
*
memb
;
asn1p_expr_t
*
objset
=
0
;
const
asn1p_ref_t
*
objset_ref
=
NULL
;
TQ_FOR
(
memb
,
&
(
expr
->
members
),
next
)
{
const
asn1p_ref_t
*
tmpref
=
asn1c_get_information_object_set_reference_from_constraint
(
asn1p_get_component_relation_constraint
(
memb
->
constraints
));
if
(
tmpref
)
{
if
(
objset_ref
&&
asn1p_ref_compare
(
objset_ref
,
tmpref
)
!=
0
)
{
FATAL
(
"Object set reference on line %d differs from object set "
"reference on line %d"
,
objset_ref
->
_lineno
,
tmpref
->
_lineno
);
errno
=
EINVAL
;
return
NULL
;
}
objset_ref
=
tmpref
;
}
}
if
(
!
objset_ref
)
{
errno
=
0
;
/* "Safe" error. */
return
NULL
;
}
objset
=
asn1f_lookup_symbol_ex
(
arg
->
asn
,
arg
->
expr
,
objset_ref
);
if
(
!
objset
)
{
FATAL
(
"Cannot found %s"
,
asn1p_ref_string
(
objset_ref
));
return
NULL
;
}
return
asn1c_construct_ioc_table_from_objset
(
arg
,
objset_ref
,
objset
);
}
int
asn1c_lang_C_type_SEQUENCE
(
arg_t
*
arg
)
{
asn1p_expr_t
*
expr
=
arg
->
expr
;
asn1p_expr_t
*
v
;
int
comp_mode
=
0
;
/* {root,ext=1,root,root,...} */
int
saved_target
=
arg
->
target
->
target
;
asn1c_ioc_table_t
*
itable
=
NULL
;
DEPENDENCIES
;
itable
=
asn1c_construct_ioc_table
(
arg
);
if
(
!
itable
&&
errno
!=
0
)
{
return
-
1
;
}
if
(
arg
->
embed
)
{
/* Use _anonymous_type field to indicate it's called from
...
...
@@ -450,11 +526,13 @@ asn1c_lang_C_type_SEQUENCE_def(arg_t *arg) {
++
elm
;
}
OUT
(
" };
\n
"
);
if
(
roms_count
>
65536
)
if
(
roms_count
>
65536
)
{
FATAL
(
"Too many optional elements in %s "
"at line %d!"
,
arg
->
expr
->
Identifier
,
arg
->
expr
->
_lineno
);
return
-
1
;
}
}
else
{
roms_count
=
0
;
aoms_count
=
0
;
...
...
libasn1fix/asn1fix.c
View file @
ea6635bd
...
...
@@ -339,15 +339,15 @@ phase_1_1(arg_t *arg, int prm2) {
RET2RVAL
(
ret
,
rvalue
);
/*
*
Parse class objects and fill up the object class with data
.
*
Resolve references in constraints
.
*/
ret
=
asn1f_
parse_class_object
(
arg
);
ret
=
asn1f_
recurse_expr
(
arg
,
asn1f_resolve_constraints
);
RET2RVAL
(
ret
,
rvalue
);
/*
*
Resolve references in constrain
ts.
*
Parse class information object se
ts.
*/
ret
=
asn1f_
recurse_expr
(
arg
,
asn1f_resolve_constraints
);
ret
=
asn1f_
parse_class_object
(
arg
);
RET2RVAL
(
ret
,
rvalue
);
/*
...
...
libasn1fix/asn1fix_class.c
View file @
ea6635bd
#include "asn1fix_internal.h"
asn1p_expr_t
*
asn1f_class_access
(
arg_t
*
arg
,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
rhs_pspecs
,
asn1p_ref_t
*
ref
)
{
asn1f_class_access
(
arg_t
*
arg
,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
rhs_pspecs
,
const
asn1p_ref_t
*
ref
)
{
asn1p_expr_t
*
ioclass
;
asn1p_expr_t
*
classfield
;
asn1p_expr_t
*
expr
;
...
...
libasn1fix/asn1fix_class.h
View file @
ea6635bd
...
...
@@ -4,6 +4,6 @@
/*
* Fetch the element from the class-related stuff (thing) by its reference.
*/
asn1p_expr_t
*
asn1f_class_access
(
arg_t
*
,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
rhs_pspecs
,
asn1p_ref_t
*
);
asn1p_expr_t
*
asn1f_class_access
(
arg_t
*
,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
rhs_pspecs
,
const
asn1p_ref_t
*
);
#endif
/* ASN1FIX_CLASS_H */
libasn1fix/asn1fix_constraint.c
View file @
ea6635bd
...
...
@@ -356,7 +356,7 @@ constraint_object_resolve(arg_t *arg, asn1p_value_t *value) {
asn1p_expr_t
tmp_expr
=
*
arg
->
expr
;
asn1p_expr_t
*
saved_expr
=
arg
->
expr
;
tmp_expr
.
meta_type
=
AMT_VALUE
;
tmp_expr
.
meta_type
=
AMT_VALUE
SET
;
tmp_expr
.
expr_type
=
A1TC_REFERENCE
;
tmp_expr
.
value
=
value
;
arg
->
expr
=
&
tmp_expr
;
...
...
libasn1fix/asn1fix_cws.c
View file @
ea6635bd
This diff is collapsed.
Click to expand it.
libasn1fix/asn1fix_export.c
View file @
ea6635bd
...
...
@@ -8,7 +8,7 @@ asn1p_expr_t *
asn1f_lookup_symbol_ex
(
asn1p_t
*
asn
,
asn1p_expr_t
*
expr
,
asn1p_ref_t
*
ref
)
{
const
asn1p_ref_t
*
ref
)
{
arg_t
arg
;
memset
(
&
arg
,
0
,
sizeof
(
arg
));
...
...
@@ -28,7 +28,7 @@ asn1f_class_access_ex(asn1p_t *asn,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
expr
,
asn1p_expr_t
*
rhs_pspecs
,
asn1p_ref_t
*
ref
)
{
const
asn1p_ref_t
*
ref
)
{
arg_t
arg
;
memset
(
&
arg
,
0
,
sizeof
(
arg
));
...
...
libasn1fix/asn1fix_export.h
View file @
ea6635bd
...
...
@@ -10,7 +10,7 @@
/*
* Create a human-readable representation of a reference and value.
*/
char
const
*
asn1f_printable_reference
(
asn1p_ref_t
*
ref
);
char
const
*
asn1f_printable_reference
(
const
asn1p_ref_t
*
ref
);
char
const
*
asn1f_printable_value
(
asn1p_value_t
*
value
);
/*
...
...
@@ -19,13 +19,13 @@ char const *asn1f_printable_value(asn1p_value_t *value);
asn1p_expr_t
*
asn1f_lookup_symbol_ex
(
asn1p_t
*
asn
,
asn1p_expr_t
*
expr
,
asn1p_ref_t
*
ref
);
const
asn1p_ref_t
*
ref
);
/*
* Exportable version of an asn1f_class_access().
*/
asn1p_expr_t
*
asn1f_class_access_ex
(
asn1p_t
*
asn
,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
expr
,
asn1p_expr_t
*
rhs_rspecs
,
asn1p_ref_t
*
);
asn1p_expr_t
*
expr
,
asn1p_expr_t
*
rhs_rspecs
,
const
asn1p_ref_t
*
);
/*
* Exportable version of asn1f_find_terminal_type().
...
...
libasn1fix/asn1fix_misc.c
View file @
ea6635bd
...
...
@@ -2,14 +2,9 @@
#include "asn1fix.h"
char
const
*
asn1f_printable_reference
(
asn1p_ref_t
*
ref
)
{
asn1f_printable_reference
(
const
asn1p_ref_t
*
ref
)
{
if
(
ref
)
{
asn1p_value_t
v
;
v
.
type
=
ATV_REFERENCED
;
v
.
value
.
reference
=
ref
;
return
asn1f_printable_value
(
&
v
);
return
asn1p_ref_string
(
ref
);
}
else
{
return
"<no ref>"
;
}
...
...
libasn1fix/asn1fix_retrieve.c
View file @
ea6635bd
...
...
@@ -80,7 +80,7 @@ asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const char *name) {
}
asn1p_module_t
*
asn1f_lookup_module
(
arg_t
*
arg
,
const
char
*
module_name
,
asn1p_oid_t
*
oid
)
{
asn1f_lookup_module
(
arg_t
*
arg
,
const
char
*
module_name
,
const
asn1p_oid_t
*
oid
)
{
asn1p_module_t
*
mod
;
assert
(
module_name
);
...
...
@@ -147,7 +147,7 @@ asn1f_lookup_module(arg_t *arg, const char *module_name, asn1p_oid_t *oid) {
}
static
asn1p_expr_t
*
asn1f_lookup_symbol_impl
(
arg_t
*
arg
,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
rhs_pspecs
,
asn1p_ref_t
*
ref
,
int
recursion_depth
)
{
asn1f_lookup_symbol_impl
(
arg_t
*
arg
,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
rhs_pspecs
,
const
asn1p_ref_t
*
ref
,
int
recursion_depth
)
{
asn1p_expr_t
*
ref_tc
;
/* Referenced tc */
asn1p_module_t
*
imports_from
;
char
*
modulename
;
...
...
@@ -369,7 +369,7 @@ asn1f_lookup_symbol_impl(arg_t *arg, asn1p_module_t *mod, asn1p_expr_t *rhs_pspe
asn1p_expr_t
*
asn1f_lookup_symbol
(
arg_t
*
arg
,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
rhs_pspecs
,
asn1p_ref_t
*
ref
)
{
asn1p_module_t
*
mod
,
asn1p_expr_t
*
rhs_pspecs
,
const
asn1p_ref_t
*
ref
)
{
return
asn1f_lookup_symbol_impl
(
arg
,
mod
,
rhs_pspecs
,
ref
,
0
);
}
...
...
libasn1fix/asn1fix_retrieve.h
View file @
ea6635bd
...
...
@@ -31,7 +31,7 @@ asn1p_module_t *asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const c
*/
asn1p_module_t
*
asn1f_lookup_module
(
arg_t
*
arg
,
const
char
*
module_name
,
asn1p_oid_t
*
module_oid
);
const
asn1p_oid_t
*
module_oid
);
/*
* Return the reference to a destination of the given reference,
...
...
@@ -40,7 +40,7 @@ asn1p_module_t *asn1f_lookup_module(arg_t *arg,
asn1p_expr_t
*
asn1f_lookup_symbol
(
arg_t
*
arg
,
asn1p_module_t
*
mod
,
asn1p_expr_t
*
rhs_pspecs
,
asn1p_ref_t
*
ref
);
const
asn1p_ref_t
*
ref
);
/*
* Recursively find the original type for the given expression.
...
...
libasn1parser/asn1p_class.c
View file @
ea6635bd
...
...
@@ -62,6 +62,36 @@ asn1p_ioc_row_delete(asn1p_ioc_row_t *row) {
}
}
int
asn1p_ioc_row_match
(
const
asn1p_ioc_row_t
*
a
,
const
asn1p_ioc_row_t
*
b
)
{
assert
(
a
&&
b
);
if
(
a
->
columns
!=
b
->
columns
)
return
-
1
;
/* Bad! */
for
(
size_t
i
=
0
;
i
<
a
->
columns
;
i
++
)
{
assert
(
a
->
column
[
i
].
field
);
assert
(
b
->
column
[
i
].
field
);
if
(
strcmp
(
a
->
column
[
i
].
field
->
Identifier
,
b
->
column
[
i
].
field
->
Identifier
)
!=
0
)
{
return
-
1
;
/* Bad! */
}
if
((
a
->
column
[
i
].
value
&&
!
b
->
column
[
i
].
value
)
||
(
!
a
->
column
[
i
].
value
&&
b
->
column
[
i
].
value
))
{
return
1
;
/* Not match */
}
if
(
a
->
column
[
i
].
value
&&
b
->
column
[
i
].
value
)
{
if
(
asn1p_expr_compare
(
a
->
column
[
i
].
value
,
b
->
column
[
i
].
value
)
!=
0
)
{
return
1
;
/* Not match */
}
}
}
return
0
;
}
struct
asn1p_ioc_cell_s
*
asn1p_ioc_row_cell_fetch
(
asn1p_ioc_row_t
*
row
,
const
char
*
fieldname
)
{
int
i
;
...
...
libasn1parser/asn1p_class.h
View file @
ea6635bd
...
...
@@ -20,6 +20,13 @@ typedef struct asn1p_ioc_row_s {
asn1p_ioc_row_t
*
asn1p_ioc_row_new
(
struct
asn1p_expr_s
*
oclass
);
void
asn1p_ioc_row_delete
(
asn1p_ioc_row_t
*
);
/*
* Match is similar to a comparison,
* but -1 means error and 1 means not equal. 0 is OK
*/
int
asn1p_ioc_row_match
(
const
asn1p_ioc_row_t
*
,
const
asn1p_ioc_row_t
*
);
struct
asn1p_ioc_cell_s
*
asn1p_ioc_row_cell_fetch
(
asn1p_ioc_row_t
*
,
const
char
*
fieldname
);
...
...
libasn1parser/asn1p_constr.c
View file @
ea6635bd
...
...
@@ -6,6 +6,28 @@
#include "asn1parser.h"
void
asn1p_constraint_set_source
(
asn1p_constraint_t
*
ct
,
struct
asn1p_module_s
*
module
,
int
lineno
)
{
if
(
ct
)
{
ct
->
module
=
module
;
ct
->
_lineno
=
lineno
;
asn1p_value_set_source
(
ct
->
containedSubtype
,
module
,
lineno
);
asn1p_value_set_source
(
ct
->
value
,
module
,
lineno
);
asn1p_value_set_source
(
ct
->
range_start
,
module
,
lineno
);
asn1p_value_set_source
(
ct
->
range_stop
,
module
,
lineno
);
for
(
size_t
i
=
0
;
i
<
ct
->
el_count
;
i
++
)
{
asn1p_constraint_set_source
(
ct
->
elements
[
i
],
module
,
lineno
);
}
}
}
int
asn1p_constraint_compare
(
const
asn1p_constraint_t
*
a
,
const
asn1p_constraint_t
*
b
)
{
assert
(
!
"Constraint comparison is not implemented"
);
return
-
1
;
}
asn1p_constraint_t
*
asn1p_constraint_new
(
int
_lineno
,
asn1p_module_t
*
mod
)
{
asn1p_constraint_t
*
ct
;
...
...
@@ -189,3 +211,20 @@ asn1p_constraint_type2str(enum asn1p_constraint_type_e type) {
}
return
"UNKNOWN"
;
}
const
asn1p_constraint_t
*
asn1p_get_component_relation_constraint
(
asn1p_constraint_t
*
ct
)
{
if
(
ct
)
{
if
(
ct
->
type
==
ACT_CA_CRC
)
return
ct
;
if
(
ct
->
type
==
ACT_CA_SET
)
{
for
(
size_t
i
=
0
;
i
<
ct
->
el_count
;
i
++
)
{
const
asn1p_constraint_t
*
tmp
=
asn1p_get_component_relation_constraint
(
ct
->
elements
[
i
]);
if
(
tmp
)
return
tmp
;
}
}
}
return
NULL
;
}
libasn1parser/asn1p_constr.h
View file @
ea6635bd
...
...
@@ -71,6 +71,14 @@ typedef struct asn1p_constraint_s {
/* Human-readable constraint type description */
const
char
*
asn1p_constraint_type2str
(
enum
asn1p_constraint_type_e
);
const
asn1p_constraint_t
*
asn1p_get_component_relation_constraint
(
asn1p_constraint_t
*
);
int
asn1p_constraint_compare
(
const
asn1p_constraint_t
*
,
const
asn1p_constraint_t
*
);
void
asn1p_constraint_set_source
(
asn1p_constraint_t
*
,
struct
asn1p_module_s
*
module
,
int
lineno
);
/*
* Constructors and a recursive destructor.
*/
...
...
libasn1parser/asn1p_expr.c
View file @
ea6635bd
...
...
@@ -9,6 +9,82 @@
static
asn1p_expr_t
*
asn1p_expr_clone_impl
(
asn1p_expr_t
*
expr
,
int
skip_extensions
,
asn1p_expr_t
*
(
*
)(
asn1p_expr_t
*
,
void
*
),
void
*
);
static
asn1p_value_t
*
value_resolver
(
asn1p_value_t
*
,
void
*
arg
);
void
asn1p_expr_set_source
(
asn1p_expr_t
*
expr
,
asn1p_module_t
*
module
,
int
lineno
)
{
if
(
expr
)
{
expr
->
module
=
module
;
expr
->
_lineno
=
lineno
;
asn1p_ref_set_source
(
expr
->
reference
,
module
,
lineno
);
asn1p_value_set_source
(
expr
->
value
,
module
,
lineno
);
asn1p_constraint_set_source
(
expr
->
constraints
,
module
,
lineno
);
asn1p_constraint_set_source
(
expr
->
combined_constraints
,
module
,
lineno
);
asn1p_expr_set_source
(
expr
->
rhs_pspecs
,
module
,
lineno
);
asn1p_expr_t
*
memb
;
TQ_FOR
(
memb
,
&
(
expr
->
members
),
next
)
{
asn1p_expr_set_source
(
memb
,
module
,
lineno
);
}
}
}
int
asn1p_expr_compare
(
const
asn1p_expr_t
*
a
,
const
asn1p_expr_t
*
b
)
{
if
(
a
->
meta_type
!=
b
->
meta_type
||
a
->
expr_type
!=
b
->
expr_type
)
{
return
-
1
;
}
if
((
!
a
->
Identifier
&&
b
->
Identifier
)
||
(
a
->
Identifier
&&
!
b
->
Identifier
))
{
return
-
1
;
}
else
if
(
a
->
Identifier
&&
strcmp
(
a
->
Identifier
,
b
->
Identifier
))
{
return
-
1
;
}
if
((
!
a
->
reference
&&
b
->
reference
)
||
(
a
->
reference
&&
!
b
->
reference
))
{
return
-
1
;
}
else
if
(
a
->
reference
&&
asn1p_ref_compare
(
a
->
reference
,
b
->
reference
)
!=
0
)
{
return
-
1
;
}
if
((
!
a
->
value
&&
b
->
value
)
||
(
a
->
value
&&
!
b
->
value
))
{
return
-
1
;
}
else
if
(
a
->
value
&&
asn1p_value_compare
(
a
->
value
,
b
->
value
))
{
return
-
1
;
}
if
((
a
->
tag
.
tag_class
!=
b
->
tag
.
tag_class
)
||
(
a
->
tag
.
tag_mode
!=
b
->
tag
.
tag_mode
)
||
(
a
->
tag
.
tag_value
!=
b
->
tag
.
tag_value
))
{
return
-
1
;
}
if
((
a
->
marker
.
flags
!=
b
->
marker
.
flags
)
||
(
a
->
marker
.
default_value
&&
!
b
->
marker
.
default_value
)
||
(
!
a
->
marker
.
default_value
&&
b
->
marker
.
default_value
)
||
(
a
->
marker
.
default_value
&&
asn1p_value_compare
(
a
->
marker
.
default_value
,
b
->
marker
.
default_value
)))
{
return
-
1
;
}
if
(
a
->
unique
!=
b
->
unique
)
{
return
-
1
;
}
const
asn1p_expr_t
*
am
=
TQ_FIRST
(
&
a
->
members
);
const
asn1p_expr_t
*
bm
=
TQ_FIRST
(
&
b
->
members
);
for
(;
am
||
bm
;
am
=
TQ_NEXT
(
am
,
next
),
bm
=
TQ_NEXT
(
bm
,
next
))
{
if
((
am
&&
!
bm
)
||
(
!
am
&&
bm
))
{
return
-
1
;
}
else
if
(
asn1p_expr_compare
(
am
,
bm
)
!=
0
)
{
return
-
1
;
}
}
return
0
;
}
/*
* Construct a new empty types collection.
*/
...
...
libasn1parser/asn1p_expr.h
View file @
ea6635bd
...
...
@@ -281,7 +281,10 @@ asn1p_expr_t *asn1p_expr_clone_with_resolver(asn1p_expr_t *,
void
*
resolver_arg
);
void
asn1p_expr_add
(
asn1p_expr_t
*
to
,
asn1p_expr_t
*
what
);
void
asn1p_expr_add_many
(
asn1p_expr_t
*
to
,
asn1p_expr_t
*
from_what
);
int
asn1p_expr_compare
(
const
asn1p_expr_t
*
,
const
asn1p_expr_t
*
);
void
asn1p_expr_free
(
asn1p_expr_t
*
expr
);
void
asn1p_expr_set_source
(
asn1p_expr_t
*
,
asn1p_module_t
*
,
int
lineno
);
#define TAG2STRING_BUFFER_SIZE 64
/* buf should be at least this big */
char
*
asn1p_tag2string
(
struct
asn1p_type_tag_s
*
tag
,
char
*
opt_buf
);
...
...
libasn1parser/asn1p_oid.c
View file @
ea6635bd
...
...
@@ -81,7 +81,7 @@ asn1p_oid_arc_free(asn1p_oid_arc_t *arc) {
}
int
asn1p_oid_compare
(
asn1p_oid_t
*
a
,
asn1p_oid_t
*
b
)
{
asn1p_oid_compare
(
const
asn1p_oid_t
*
a
,
const
asn1p_oid_t
*
b
)
{
int
i
;
for
(
i
=
0
;
;
i
++
)
{
...
...
libasn1parser/asn1p_oid.h
View file @
ea6635bd
...
...
@@ -61,7 +61,7 @@ void asn1p_oid_free(asn1p_oid_t *);
* 0: The specified OIDs are equal.
* -1 or 1 otherwise.
*/
int
asn1p_oid_compare
(
asn1p_oid_t
*
a
,
asn1p_oid_t
*
b
);
int
asn1p_oid_compare
(
const
asn1p_oid_t
*
a
,
const
asn1p_oid_t
*
b
);
#endif
/* ASN1_PARSER_OID_H */
libasn1parser/asn1p_ref.c
View file @
ea6635bd
...
...
@@ -14,10 +14,8 @@ asn1p_ref_new(int _lineno, asn1p_module_t *mod) {
asn1p_ref_t
*
ref
;
ref
=
calloc
(
1
,
sizeof
*
ref
);
if
(
ref
)
{
ref
->
_lineno
=
_lineno
;
ref
->
module
=
mod
;
}
assert
(
ref
);
asn1p_ref_set_source
(
ref
,
mod
,
_lineno
);
return
ref
;
}
...
...
@@ -39,6 +37,14 @@ asn1p_ref_free(asn1p_ref_t *ref) {
}
}
void
asn1p_ref_set_source
(
asn1p_ref_t
*
ref
,
asn1p_module_t
*
module
,
int
lineno
)
{
if
(
ref
)
{
ref
->
module
=
module
;
ref
->
_lineno
=
lineno
;
}
}
static
enum
asn1p_ref_lex_type_e
asn1p_ref_name2lextype
(
const
char
*
name
)
{
enum
asn1p_ref_lex_type_e
lex_type
;
...
...
@@ -136,3 +142,51 @@ asn1p_ref_clone(asn1p_ref_t *ref) {
return
newref
;
}
int
asn1p_ref_compare
(
const
asn1p_ref_t
*
a
,
const
asn1p_ref_t
*
b
)
{
if
(
a
->
comp_count
!=
b
->
comp_count
)
return
-
1
;
if
(
a
->
module
!=
b
->
module
)
return
-
1
;
for
(
size_t
i
=
0
;
i
<
a
->
comp_count
;
i
++
)
{
if
(
a
->
components
[
i
].
lex_type
!=
b
->
components
[
i
].
lex_type
||
strcmp
(
a
->
components
[
i
].
name
,
b
->
components
[
i
].
name
)
!=
0
)
{
return
-
1
;
}
}
return
0
;
}
const
char
*
asn1p_ref_string
(
const
asn1p_ref_t
*
ref
)
{
static
char
static_buf
[
32
];
static
char
*
buf
=
static_buf
;
static
size_t
buf_size
=
sizeof
(
static_buf
);
char
*
p
=
buf
;
for
(
size_t
i
=
0
;
i
<
ref
->
comp_count
;
i
++
)
{
size_t
space
=
buf_size
-
(
p
-
buf
);
int
ret
=
snprintf
(
p
,
space
,
"%s%s"
,
i
?
"."
:
""
,
ref
->
components
[
i
].
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
space
)
{
i
--
;
char
*
tmp
=
malloc
(
buf_size
*
2
+
1
);
assert
(
tmp
);
size_t
p_offset
=
p
-
buf
;
memcpy
(
tmp
,
buf
,
(
p
-
buf
));
if
(
buf
!=
static_buf
)
free
(
buf
);
buf_size
*=
2
;
buf
=
tmp
;
p
=
tmp
+
p_offset
;
}
else
{
p
+=
ret
;
}
}
*
p
=
'\0'
;
return
buf
;
}
libasn1parser/asn1p_ref.h
View file @
ea6635bd
...
...
@@ -49,6 +49,20 @@ void asn1p_ref_free(asn1p_ref_t *);
asn1p_ref_t
*
asn1p_ref_clone
(
asn1p_ref_t
*
ref
);
void
asn1p_ref_set_source
(
asn1p_ref_t
*
,
asn1p_module_t
*
module
,
int
lineno
);
/*
* Lexicographically compare references.
*/
int
asn1p_ref_compare
(
const
asn1p_ref_t
*
,
const
asn1p_ref_t
*
);
/*
* Return a pointer to a statically allocated buffer representing the
* complete reference.
*/
const
char
*
asn1p_ref_string
(
const
asn1p_ref_t
*
);
/*
* Add a new reference component to the existing reference structure.
*
...
...
libasn1parser/asn1p_value.c
View file @
ea6635bd
...
...
@@ -4,7 +4,85 @@
#include <assert.h>
#include "asn1parser.h"
#include "asn1p_expr.h"
void
asn1p_value_set_source
(
asn1p_value_t
*
value
,
asn1p_module_t
*
module
,
int
lineno
)
{
if
(
value
)
{
switch
(
value
->
type
)
{
case
ATV_TYPE
:
asn1p_expr_set_source
(
value
->
value
.
v_type
,
module
,
lineno
);
break
;
case
ATV_REFERENCED
:
asn1p_ref_set_source
(
value
->
value
.
reference
,
module
,
lineno
);
break
;
case
ATV_VALUESET
:
asn1p_constraint_set_source
(
value
->
value
.
constraint
,
module
,
lineno
);
break
;
default:
break
;
}
}
}
int
asn1p_value_compare
(
const
asn1p_value_t
*
a
,
const
asn1p_value_t
*
b
)
{
if
(
a
->
type
!=
b
->
type
)
{
return
-
1
;
}
switch
(
a
->
type
)
{
case
ATV_NULL
:
case
ATV_NOVALUE
:
case
ATV_MAX
:
case
ATV_MIN
:
case
ATV_FALSE
:
case
ATV_TRUE
:
break
;
case
ATV_TYPE
:
return
asn1p_expr_compare
(
a
->
value
.
v_type
,
b
->
value
.
v_type
);
case
ATV_REAL
:
return
(
a
->
value
.
v_double
==
b
->
value
.
v_double
)
?
0
:
-
1
;
case
ATV_INTEGER
:
case
ATV_TUPLE
:
case
ATV_QUADRUPLE
:
return
(
a
->
value
.
v_integer
==
b
->
value
.
v_integer
)
?
0
:
-
1
;
case
ATV_STRING
:
case
ATV_UNPARSED
:
if
(
a
->
value
.
string
.
size
!=
b
->
value
.
string
.
size
||
memcmp
(
a
->
value
.
string
.
buf
,
b
->
value
.
string
.
buf
,
a
->
value
.
string
.
size
)
!=
0
)
{
return
-
1
;
}
return
0
;
case
ATV_BITVECTOR
:
if
(
a
->
value
.
binary_vector
.
size_in_bits
!=
b
->
value
.
binary_vector
.
size_in_bits
||
memcmp
(
a
->
value
.
binary_vector
.
bits
,
b
->
value
.
binary_vector
.
bits
,
(
a
->
value
.
binary_vector
.
size_in_bits
+
7
)
>>
3
)
!=
0
)
{
return
-
1
;
}
case
ATV_VALUESET
:
return
asn1p_constraint_compare
(
a
->
value
.
constraint
,
b
->
value
.
constraint
);
case
ATV_REFERENCED
:
return
asn1p_ref_compare
(
a
->
value
.
reference
,
b
->
value
.
reference
);
case
ATV_CHOICE_IDENTIFIER
:
if
(
strcmp
(
a
->
value
.
choice_identifier
.
identifier
,
b
->
value
.
choice_identifier
.
identifier
)
!=
0
)
{
return
-
1
;
}
return
asn1p_value_compare
(
a
->
value
.
choice_identifier
.
value
,
b
->
value
.
choice_identifier
.
value
);
}
return
0
;
}
asn1p_value_t
*
asn1p_value_fromref
(
asn1p_ref_t
*
ref
,
int
do_copy
)
{
...
...
libasn1parser/asn1p_value.h
View file @
ea6635bd
...
...
@@ -5,6 +5,7 @@
#define ASN1_PARSER_VALUE_H
struct
asn1p_constraint_s
;
/* Forward declaration */
struct
asn1p_module_s
;
struct
asn1p_expr_s
;
/*
...
...
@@ -76,5 +77,7 @@ asn1p_value_t *asn1p_value_clone(asn1p_value_t *);
asn1p_value_t
*
asn1p_value_clone_with_resolver
(
asn1p_value_t
*
,
asn1p_value_t
*
(
*
resolver
)(
asn1p_value_t
*
,
void
*
rarg
),
void
*
rarg
);
int
asn1p_value_compare
(
const
asn1p_value_t
*
,
const
asn1p_value_t
*
);
void
asn1p_value_set_source
(
asn1p_value_t
*
,
struct
asn1p_module_s
*
,
int
line
);
#endif
/* ASN1_PARSER_VALUE_H */
tests/139-component-relation-OK.asn1
0 → 100755
View file @
ea6635bd
-- OK: Everything is fine
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .139
ModuleComponentRelationConstraint
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 139 }
DEFINITIONS ::=
BEGIN
Frame ::= SEQUENCE {
ident FRAME-STRUCTURE.&id({FrameTypes}),
value FRAME-STRUCTURE.&Type({FrameTypes}{@.ident}),
...
}
FRAME-STRUCTURE ::= CLASS {
&id INTEGER UNIQUE,
&Type
} WITH SYNTAX {&Type IDENTIFIED BY &id}
FrameTypes FRAME-STRUCTURE ::= {
{ PrimitiveMessage IDENTIFIED BY basicMessage } |
{ ComplexMessage IDENTIFIED BY 2 },
...
}
PrimitiveMessage ::= SEQUENCE {}
ComplexMessage ::= SEQUENCE {}
basicMessage INTEGER ::= 1
END
tests/139-component-relation-OK.asn1.-EFprint-class-matrix
0 → 100644
View file @
ea6635bd
ModuleComponentRelationConstraint { iso org(3) dod(6) internet(1) private(4)
enterprise(1) spelio(9363) software(1) asn1c(5) test(1) 139 }
DEFINITIONS ::=
BEGIN
Frame ::= SEQUENCE {
ident FRAME-STRUCTURE.&id ({FrameTypes}),
value FRAME-STRUCTURE.&Type ({FrameTypes}{@.ident}),
...
}
FRAME-STRUCTURE ::= CLASS {
&id INTEGER UNIQUE,
&Type ANY
} WITH SYNTAX {&Type IDENTIFIED BY &id}
-- Class matrix has 2 entries:
-- [ &id][ &Type]
-- [1] basicMessage PrimitiveMessage
-- [2] 2 ComplexMessage
FrameTypes FRAME-STRUCTURE ::= {{ PrimitiveMessage IDENTIFIED BY basicMessage } | { ComplexMessage IDENTIFIED BY 2 },...}
PrimitiveMessage ::= SEQUENCE { }
ComplexMessage ::= SEQUENCE { }
basicMessage INTEGER ::= 1
END
tests/140-component-relation-OK.asn1
0 → 100755
View file @
ea6635bd
-- OK: Everything is fine
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .140
ModuleComponentRelationConstraint
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 140 }
DEFINITIONS ::=
BEGIN
Frame ::= SEQUENCE {
ident FRAME-STRUCTURE.&id({FrameTypes}),
value FRAME-STRUCTURE.&Type({FrameTypes}{@.ident}),
...
}
FRAME-STRUCTURE ::= CLASS {
&id INTEGER UNIQUE,
&Type
} WITH SYNTAX {&Type IDENTIFIED BY &id}
FrameTypes FRAME-STRUCTURE ::= { primType | complexType, ... }
primType FRAME-STRUCTURE ::= { PrimitiveMessage IDENTIFIED BY basicMessage }
complexType FRAME-STRUCTURE ::= { ComplexMessage IDENTIFIED BY 2 }
PrimitiveMessage ::= SEQUENCE {}
ComplexMessage ::= SEQUENCE {}
basicMessage INTEGER ::= 1
END
tests/140-component-relation-OK.asn1.-EFprint-class-matrix
0 → 100644
View file @
ea6635bd
ModuleComponentRelationConstraint { iso org(3) dod(6) internet(1) private(4)
enterprise(1) spelio(9363) software(1) asn1c(5) test(1) 140 }
DEFINITIONS ::=
BEGIN
Frame ::= SEQUENCE {
ident FRAME-STRUCTURE.&id ({FrameTypes}),
value FRAME-STRUCTURE.&Type ({FrameTypes}{@.ident}),
...
}
FRAME-STRUCTURE ::= CLASS {
&id INTEGER UNIQUE,
&Type ANY
} WITH SYNTAX {&Type IDENTIFIED BY &id}
-- Class matrix has 2 entries:
-- [ &id][ &Type]
-- [1] basicMessage PrimitiveMessage
-- [2] 2 ComplexMessage
FrameTypes FRAME-STRUCTURE ::= {{ PrimitiveMessage IDENTIFIED BY basicMessage } | { ComplexMessage IDENTIFIED BY 2 },...}
primType FRAME-STRUCTURE ::= { PrimitiveMessage IDENTIFIED BY basicMessage }
complexType FRAME-STRUCTURE ::= { ComplexMessage IDENTIFIED BY 2 }
PrimitiveMessage ::= SEQUENCE { }
ComplexMessage ::= SEQUENCE { }
basicMessage INTEGER ::= 1
END
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment