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
486fd5cb
Commit
486fd5cb
authored
Jul 10, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add encode check (fails yet)
parent
fcfe19b2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
14 deletions
+92
-14
skeletons/oer_encoder.c
skeletons/oer_encoder.c
+14
-13
skeletons/oer_encoder.h
skeletons/oer_encoder.h
+1
-0
skeletons/tests/check-OER-INTEGER.c
skeletons/tests/check-OER-INTEGER.c
+77
-1
No files found.
skeletons/oer_encoder.c
View file @
486fd5cb
...
...
@@ -47,6 +47,7 @@ static int encode_to_buffer_cb(const void *buffer, size_t size, void *key) {
*/
asn_enc_rval_t
oer_encode_to_buffer
(
struct
asn_TYPE_descriptor_s
*
type_descriptor
,
asn_oer_constraints_t
*
constraints
,
void
*
struct_ptr
,
/* Structure to be encoded */
void
*
buffer
,
/* Pre-allocated buffer */
size_t
buffer_size
/* Initial buffer size (maximum) */
...
...
@@ -58,7 +59,7 @@ oer_encode_to_buffer(struct asn_TYPE_descriptor_s *type_descriptor,
arg
.
left
=
buffer_size
;
ec
=
type_descriptor
->
oer_encoder
(
type_descriptor
,
0
,
type_descriptor
,
constraints
,
struct_ptr
,
/* Pointer to the destination structure */
encode_to_buffer_cb
,
&
arg
);
if
(
ec
.
encoded
!=
-
1
)
{
...
...
skeletons/oer_encoder.h
View file @
486fd5cb
...
...
@@ -26,6 +26,7 @@ asn_enc_rval_t oer_encode(struct asn_TYPE_descriptor_s *type_descriptor,
/* A variant of oer_encode() which encodes data into the pre-allocated buffer */
asn_enc_rval_t
oer_encode_to_buffer
(
struct
asn_TYPE_descriptor_s
*
type_descriptor
,
asn_oer_constraints_t
*
constraints
,
void
*
struct_ptr
,
/* Structure to be encoded */
void
*
buffer
,
/* Pre-allocated buffer */
size_t
buffer_size
/* Initial buffer size (maximum) */
...
...
skeletons/tests/check-OER-INTEGER.c
View file @
486fd5cb
...
...
@@ -5,6 +5,7 @@
#include <INTEGER.h>
#define CHECK_DECODE(code, a, b, c, d, e, f) check_decode(__LINE__, code, a, b, c, d, e, f)
#define CHECK_ROUNDTRIP(a, b, c) check_roundtrip(__LINE__, a, b, c);
static
const
intmax_t
NoBound
=
-
4200024
;
...
...
@@ -12,7 +13,7 @@ static void
check_decode
(
int
lineno
,
enum
asn_dec_rval_code_e
code
,
intmax_t
control
,
const
char
*
buf
,
size_t
size
,
const
char
*
dummy
,
intmax_t
lower_bound
,
intmax_t
upper_bound
)
{
static
char
*
code_s
[]
=
{
"RC_OK"
,
"RC_WMORE"
,
"RC_FAIL"
,
"<error>"
};
fprintf
(
stderr
,
"%d: buf[%
d
]={%d, %d, ...}
\n
"
,
lineno
,
size
,
fprintf
(
stderr
,
"%d: buf[%
zu
]={%d, %d, ...}
\n
"
,
lineno
,
size
,
((
const
uint8_t
*
)
buf
)[
0
],
((
const
uint8_t
*
)
buf
)[
1
]);
...
...
@@ -76,6 +77,76 @@ check_decode(int lineno, enum asn_dec_rval_code_e code, intmax_t control, const
fprintf
(
stderr
,
"%d: Decode result %"
PRIdMAX
"
\n
"
,
lineno
,
control
);
}
static
void
check_roundtrip
(
int
lineno
,
intmax_t
value
,
intmax_t
lower_bound
,
intmax_t
upper_bound
)
{
uint8_t
tmpbuf
[
32
];
size_t
tmpbuf_size
;
INTEGER_t
*
stOut
=
(
INTEGER_t
*
)
calloc
(
1
,
sizeof
(
*
stOut
));
INTEGER_t
*
stIn
=
NULL
;
asn_enc_rval_t
er
;
asn_dec_rval_t
ret
;
struct
asn_oer_constraints_s
empty_constraints
=
{{
0
,
0
,
0
},
{
0
,
0
,
0
}};
struct
asn_oer_constraints_s
*
constraints
=
&
empty_constraints
;
struct
asn_oer_constraint_s
*
ct_value
=
&
constraints
->
value
;
/* Setup integer constraints as requested */
if
(
lower_bound
==
NoBound
&&
upper_bound
==
NoBound
)
{
constraints
=
NULL
;
}
else
{
if
(
lower_bound
!=
NoBound
)
{
ct_value
->
flags
|=
AOC_HAS_LOWER_BOUND
;
ct_value
->
lower_bound
=
lower_bound
;
}
if
(
upper_bound
!=
NoBound
)
{
ct_value
->
flags
|=
AOC_HAS_UPPER_BOUND
;
ct_value
->
upper_bound
=
upper_bound
;
}
}
if
(
asn_imax2INTEGER
(
stOut
,
value
)
==
-
1
)
{
assert
(
!
"Unreachable"
);
}
er
=
oer_encode_to_buffer
(
&
asn_DEF_INTEGER
,
constraints
,
stOut
,
tmpbuf
,
sizeof
(
tmpbuf
));
if
(
er
.
encoded
!=
-
1
)
{
fprintf
(
stderr
,
"%d: oer encode failed for %s
\n
"
,
lineno
,
er
.
failed_type
?
er
.
failed_type
->
name
:
"<none>"
);
assert
(
er
.
encoded
!=
-
1
);
}
tmpbuf_size
=
er
.
encoded
;
ret
=
asn_DEF_INTEGER
.
oer_decoder
(
0
,
&
asn_DEF_INTEGER
,
constraints
,
(
void
**
)
&
stIn
,
tmpbuf
,
tmpbuf_size
);
if
(
ret
.
code
!=
RC_OK
)
{
/* Basic OER decode does not work */
fprintf
(
stderr
,
"%d: Failed oer_decode(value=%"
PRIdMAX
", size=%zu)
\n
"
,
lineno
,
value
,
tmpbuf_size
);
assert
(
ret
.
code
==
0
);
}
else
{
intmax_t
outcome
;
if
(
asn_INTEGER2imax
(
stIn
,
&
outcome
)
!=
0
)
{
/* Result of decode is structurally incorrect */
fprintf
(
stderr
,
"%d: Failed to convert INTEGER 2 imax; structurally "
"incorrect INTEGER
\n
"
,
lineno
);
assert
(
!
"Unreachable"
);
}
else
if
(
outcome
!=
value
)
{
/* Decoded value is wrong */
fprintf
(
stderr
,
"%d: Decode result %"
PRIdMAX
" is not expected %"
PRIdMAX
"
\n
"
,
lineno
,
outcome
,
value
);
assert
(
outcome
==
value
);
}
}
fprintf
(
stderr
,
"%d: Decode result %"
PRIdMAX
"
\n
"
,
lineno
,
value
);
}
int
main
()
{
CHECK_DECODE
(
RC_WMORE
,
0
,
""
,
0
,
"bounds="
,
NoBound
,
NoBound
);
...
...
@@ -102,4 +173,9 @@ main() {
CHECK_DECODE
(
RC_OK
,
-
1
,
"\x1
\xff
"
,
2
,
"bounds="
,
NoBound
,
255
);
CHECK_DECODE
(
RC_WMORE
,
-
1
,
"
\x02\x00\xff
"
,
2
,
"bounds="
,
NoBound
,
200
);
CHECK_DECODE
(
RC_OK
,
255
,
"
\x02\x00\xff
"
,
3
,
"bounds="
,
NoBound
,
200
);
CHECK_ROUNDTRIP
(
0
,
NoBound
,
NoBound
);
CHECK_ROUNDTRIP
(
1
,
NoBound
,
NoBound
);
CHECK_ROUNDTRIP
(
1
,
-
128
,
127
);
}
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