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
c54d9467
Commit
c54d9467
authored
Jan 20, 2024
by
v0-e
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for default class syntax
parent
32706502
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
14 deletions
+131
-14
libasn1fix/asn1fix_cws.c
libasn1fix/asn1fix_cws.c
+81
-14
libasn1parser/asn1p_class.c
libasn1parser/asn1p_class.c
+46
-0
libasn1parser/asn1p_class.h
libasn1parser/asn1p_class.h
+4
-0
No files found.
libasn1fix/asn1fix_cws.c
View file @
c54d9467
...
...
@@ -31,12 +31,6 @@ asn1f_check_class_object(arg_t *arg) {
return
0
;
}
if
(
!
eclass
->
with_syntax
)
{
DEBUG
(
"Can't process classes without %s just yet"
,
"WITH SYNTAX"
);
return
0
;
}
row
=
asn1p_ioc_row_new
(
eclass
);
assert
(
row
);
...
...
@@ -266,12 +260,6 @@ asn1f_parse_class_object(arg_t *arg) {
DEBUG
(
"Value %s of CLASS %s found at line %d"
,
expr
->
Identifier
,
eclass
->
Identifier
,
expr
->
_lineno
);
if
(
!
eclass
->
with_syntax
)
{
DEBUG
(
"Can't process classes without %s just yet"
,
"WITH SYNTAX"
);
return
0
;
}
struct
parse_object_key
key
=
{
.
arg
=
arg
,
.
expr
=
expr
,
...
...
@@ -308,10 +296,68 @@ asn1f_parse_class_object(arg_t *arg) {
return
0
;
}
#define SKIPSPACES for(; buf < bend && isspace(*buf); buf++)
#define SKIPSPACES \
for(; buf < bend && isspace(*buf); buf++)
#define SKIPSPACES_AND_COMMA \
for(; buf < bend && (isspace(*buf) || *buf==','); buf++)
static
int
_asn1f_parse_class_object_data
(
arg_t
*
arg
,
asn1p_expr_t
*
eclass
,
_asn1f_parse_class_object_data_default_syntx
(
arg_t
*
arg
,
asn1p_expr_t
*
eclass
,
struct
asn1p_ioc_row_s
*
row
,
asn1p_wsyntx_t
*
syntax
,
const
uint8_t
*
buf
,
const
uint8_t
*
bend
,
int
optional_mode
,
const
uint8_t
**
newpos
,
int
counter
)
{
int
ret
;
/* Default syntax: { FieldSetting , * }
* where, FieldSetting ::= PrimitiveFieldName Setting
* and, FieldSetting is a reference and Setting is not
* Contrary to with the defined WITH SYNTAX,
* FieldSetting's can appear in any order */
asn1p_expr_t
*
cm
;
SKIPSPACES
;
for
(;
buf
<
bend
;
++
buf
)
{
TQ_FOR
(
cm
,
&
(
eclass
->
members
),
next
)
{
/* PrimitiveFieldName */
int
id_len
=
strlen
(
cm
->
Identifier
);
if
(
id_len
>
(
bend
-
buf
))
{
continue
;
}
if
(
memcmp
(
buf
,
cm
->
Identifier
,
id_len
)
==
0
)
{
buf
+=
strlen
(
cm
->
Identifier
);
SKIPSPACES
;
/* Setting */
const
uint8_t
*
p
=
0
;
for
(
p
=
buf
;
p
<
bend
&&
(
*
p
)
!=
','
;
p
++
)
{}
struct
asn1p_ioc_cell_s
*
cell
;
cell
=
asn1p_ioc_row_cell_fetch
(
row
,
cm
->
Identifier
);
if
(
cell
==
NULL
)
{
if
(
newpos
)
*
newpos
=
buf
;
return
-
1
;
}
DEBUG
(
"Reference %s satisfied by %s (%d)"
,
cm
->
Identifier
,
buf
,
p
-
buf
);
ret
=
_asn1f_assign_cell_value
(
arg
,
cell
,
buf
,
p
,
counter
);
if
(
ret
)
return
ret
;
buf
=
p
;
SKIPSPACES_AND_COMMA
;
if
(
newpos
)
*
newpos
=
buf
;
break
;
}
}
}
if
(
newpos
)
*
newpos
=
buf
;
return
0
;
}
static
int
_asn1f_parse_class_object_data_defined_syntx
(
arg_t
*
arg
,
asn1p_expr_t
*
eclass
,
struct
asn1p_ioc_row_s
*
row
,
asn1p_wsyntx_t
*
syntax
,
const
uint8_t
*
buf
,
const
uint8_t
*
bend
,
int
optional_mode
,
const
uint8_t
**
newpos
,
int
counter
)
{
...
...
@@ -391,6 +437,27 @@ _asn1f_parse_class_object_data(arg_t *arg, asn1p_expr_t *eclass,
return
0
;
}
static
int
_asn1f_parse_class_object_data
(
arg_t
*
arg
,
asn1p_expr_t
*
eclass
,
struct
asn1p_ioc_row_s
*
row
,
asn1p_wsyntx_t
*
syntax
,
const
uint8_t
*
buf
,
const
uint8_t
*
bend
,
int
optional_mode
,
const
uint8_t
**
newpos
,
int
counter
)
{
if
(
!
eclass
->
with_syntax
)
{
/* Assume default syntax */
return
_asn1f_parse_class_object_data_default_syntx
(
arg
,
eclass
,
row
,
syntax
,
buf
,
bend
,
optional_mode
,
newpos
,
counter
);
}
else
{
/* WITH SYNTAX {} */
return
_asn1f_parse_class_object_data_defined_syntx
(
arg
,
eclass
,
row
,
syntax
,
buf
,
bend
,
optional_mode
,
newpos
,
counter
);
}
}
static
int
_asn1f_assign_cell_value
(
arg_t
*
arg
,
struct
asn1p_ioc_cell_s
*
cell
,
...
...
libasn1parser/asn1p_class.c
View file @
c54d9467
...
...
@@ -282,6 +282,52 @@ asn1p_wsyntx_clone(asn1p_wsyntx_t *wx) {
return
nw
;
}
asn1p_wsyntx_t
*
asn1p_wsyntx_default
(
const
struct
asn1p_expr_s
*
eclass
)
{
/*
* Default syntax: { &literal field , * }
*/
asn1p_wsyntx_t
*
syntax
;
asn1p_expr_t
*
member
;
asn1p_wsyntx_chunk_t
*
chunk
;
syntax
=
asn1p_wsyntx_new
();
if
(
!
syntax
)
{
return
NULL
;
}
#define ADD_DC(ctype, ctoken) \
do { \
chunk = asn1p_wsyntx_chunk_new(); \
if(!chunk) { \
asn1p_wsyntx_free(syntax); \
return NULL; \
} \
chunk->type = ctype; \
chunk->content.token = strdup(ctoken); \
TQ_ADD(&(syntax->chunks), chunk, next); \
} while(0)
TQ_FOR
(
member
,
(
&
eclass
->
members
),
next
)
{
/* &literal */
ADD_DC
(
WC_LITERAL
,
member
->
Identifier
);
/* whitespace */
ADD_DC
(
WC_WHITESPACE
,
" "
);
/* field */
ADD_DC
(
WC_FIELD
,
member
->
Identifier
);
/* comma separator */
if
(
TQ_NEXT
(
member
,
next
))
{
ADD_DC
(
WC_LITERAL
,
","
);
}
}
return
syntax
;
}
asn1p_wsyntx_chunk_t
*
asn1p_wsyntx_chunk_fromstring
(
char
*
token
,
int
do_copy
)
{
asn1p_wsyntx_chunk_t
*
wc
;
...
...
libasn1parser/asn1p_class.h
View file @
c54d9467
...
...
@@ -84,6 +84,10 @@ asn1p_wsyntx_chunk_t *asn1p_wsyntx_chunk_clone(asn1p_wsyntx_chunk_t *);
asn1p_wsyntx_t
*
asn1p_wsyntx_new
(
void
);
void
asn1p_wsyntx_free
(
asn1p_wsyntx_t
*
);
asn1p_wsyntx_t
*
asn1p_wsyntx_clone
(
asn1p_wsyntx_t
*
);
/*
* Creates a default syntax of some class
*/
asn1p_wsyntx_t
*
asn1p_wsyntx_default
(
const
struct
asn1p_expr_s
*
eclass
);
/*
* RETURN VALUES:
...
...
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