Commit 59b176ee authored by Lev Walkin's avatar Lev Walkin

upgrade: PER related changes

parent 70853058
0.9.20: 2005-Nov-07 0.9.20: 2005-Nov-13
* SET OF CHOICE, SEQUENCE OF CHOICE and a certain named S/O types * SET OF CHOICE, SEQUENCE OF CHOICE and a certain named S/O types
are represented differently in XER. THIS IS AN ICOMPATIBLE CHANGE. are represented differently in XER. THIS IS AN ICOMPATIBLE CHANGE.
(Test case 70) (Severity: low; Security impact: low) (Test case 70) (Severity: low; Security impact: low)
* PER implementation has started
* asn1c: Removed -ftypes88 command line option.
0.9.19: 2005-Oct-06 0.9.19: 2005-Oct-06
......
1. MAJOR: 1. MAJOR:
1.1 Support for PER encoding. Requires advanced subtype constraints support, 1.1 Support for PER encoding. PER decoding is already supported.
which is already completed.
1.2 Support for Information Object Classes. 1.2 Support for Information Object Classes.
Status: Support for parsing IOCs is mostly present. Status: Support for parsing IOCs is mostly present.
...@@ -12,7 +11,3 @@ which is already completed. ...@@ -12,7 +11,3 @@ which is already completed.
2.1 Support for EXTERNAL, EMBEDDED-PDV and CHARACTER STRING types. 2.1 Support for EXTERNAL, EMBEDDED-PDV and CHARACTER STRING types.
Requires something from 1.2 (Information Object Classes). Requires something from 1.2 (Information Object Classes).
3. MINOR:
3.1 Support for DEFAULT encoding and decoding, at least in INTEGER/ENUMERATED types.
...@@ -4,7 +4,7 @@ asn1c \- ASN.1 Compiler ...@@ -4,7 +4,7 @@ asn1c \- ASN.1 Compiler
.SH SYNOPSIS .SH SYNOPSIS
asn1c [\fB\-E\fR [\fB-F\fR] | \fB\-P\fR | \fB\-R\fR] asn1c [\fB\-E\fR [\fB-F\fR] | \fB\-P\fR | \fB\-R\fR]
[\fB\-S\fR\fIdir\fR] [\fB-X\fR] [\fB\-S\fR\fIdir\fR] [\fB-X\fR]
[\fB\-W\fR\fIdebug-\fR...] [\fB\-f\fR\fIoption\fR...] [\fB\-p\fR\fIrint-\fR...] [\fB\-W\fR\fIdebug-\fR...] [\fB\-f\fR\fIoption\fR] [\fB\-gen-\fR\fIoption\fR] [\fB\-print-\fR\fIoption\fR]
\fIinfile\fR... \fIinfile\fR...
.SH DESCRIPTION .SH DESCRIPTION
asn1c compiles the ASN.1 specifications into the set of asn1c compiles the ASN.1 specifications into the set of
...@@ -25,7 +25,11 @@ and other encoding standards. ...@@ -25,7 +25,11 @@ and other encoding standards.
.br .br
\fB\-fall-defs-global \-fbless-SIZE \-fcompound-names \-findirect-choice \fB\-fall-defs-global \-fbless-SIZE \-fcompound-names \-findirect-choice
.BI "\-fknown-extern-type="<name> .BI "\-fknown-extern-type="<name>
\fB\-fnative-types \-fno-constraints \-fno-include-deps \-funnamed-unions \-fskeletons-copy \-ftypes88\fR \fB\-fnative-types \-fno-constraints \-fno-include-deps \-funnamed-unions \-fskeletons-copy
.TP
\fICodecs Generation Options\fR
.br
.B \-gen-PER
.TP .TP
\fIOutput Options\fR \fIOutput Options\fR
.br .br
...@@ -117,11 +121,10 @@ Enable unnamed unions in the definitions of target language's structures. ...@@ -117,11 +121,10 @@ Enable unnamed unions in the definitions of target language's structures.
.TP .TP
.B \-fskeletons-copy .B \-fskeletons-copy
Copy support files (skeletons) rather than symlink them. Copy support files (skeletons) rather than symlink them.
.SH CODECS GENERATION OPTIONS
.TP .TP
.B \-ftypes88 .B \-gen-PER
Pretend to support only ASN.1:1988 embedded types. Certain reserved words, Generate Packed Encoding Rules (PER) support code.
such as UniversalString and BMPString, become ordinary type references
and may be redefined by the specification.
.SH OUTPUT OPTIONS .SH OUTPUT OPTIONS
.TP .TP
.B \-print-constraints .B \-print-constraints
......
...@@ -62,7 +62,7 @@ main(int ac, char **av) { ...@@ -62,7 +62,7 @@ main(int ac, char **av) {
/* /*
* Process command-line options. * Process command-line options.
*/ */
while((ch = getopt(ac, av, "EFf:hLPp:RS:vW:X")) != -1) while((ch = getopt(ac, av, "EFf:g:hLPp:RS:vW:X")) != -1)
switch(ch) { switch(ch) {
case 'E': case 'E':
print_arg__print_out = 1; print_arg__print_out = 1;
...@@ -95,13 +95,19 @@ main(int ac, char **av) { ...@@ -95,13 +95,19 @@ main(int ac, char **av) {
asn1_compiler_flags |= A1C_UNNAMED_UNIONS; asn1_compiler_flags |= A1C_UNNAMED_UNIONS;
} else if(strcmp(optarg, "skeletons-copy") == 0) { } else if(strcmp(optarg, "skeletons-copy") == 0) {
asn1_compiler_flags |= A1C_SKELETONS_COPY; asn1_compiler_flags |= A1C_SKELETONS_COPY;
} else if(strcmp(optarg, "types88") == 0) {
asn1_parser_flags |= A1P_TYPES_RESTRICT_TO_1988;
} else { } else {
fprintf(stderr, "-f%s: Invalid argument\n", optarg); fprintf(stderr, "-f%s: Invalid argument\n", optarg);
exit(EX_USAGE); exit(EX_USAGE);
} }
break; break;
case 'g':
if(strcmp(optarg, "en-PER") == 0) {
asn1_compiler_flags |= A1C_GEN_PER;
} else {
fprintf(stderr, "-g%s: Invalid argument\n", optarg);
exit(EX_USAGE);
}
break;
case 'h': case 'h':
usage(av[0]); usage(av[0]);
case 'P': case 'P':
...@@ -109,7 +115,15 @@ main(int ac, char **av) { ...@@ -109,7 +115,15 @@ main(int ac, char **av) {
asn1_compiler_flags &= ~A1C_NO_C99; asn1_compiler_flags &= ~A1C_NO_C99;
break; break;
case 'p': case 'p':
if(strcmp(optarg, "rint-constraints") == 0) { if(strncmp(optarg, "du=", 3) == 0) {
char *pduname = optarg + 3;
if(strcmp(pduname, "auto")) {
fprintf(stderr, "-pdu=%s: expected -pdu=auto\n",
pduname);
exit(EX_USAGE);
}
asn1_compiler_flags |= A1C_PDU_AUTO;
} else if(strcmp(optarg, "rint-constraints") == 0) {
asn1_printer_flags |= APF_DEBUG_CONSTRAINTS; asn1_printer_flags |= APF_DEBUG_CONSTRAINTS;
} else if(strcmp(optarg, "rint-lines") == 0) { } else if(strcmp(optarg, "rint-lines") == 0) {
asn1_printer_flags |= APF_LINE_COMMENTS; asn1_printer_flags |= APF_LINE_COMMENTS;
...@@ -250,7 +264,8 @@ main(int ac, char **av) { ...@@ -250,7 +264,8 @@ main(int ac, char **av) {
/* /*
* Make sure the skeleton directory is out there. * Make sure the skeleton directory is out there.
*/ */
if(skeletons_dir == NULL) { if((asn1_compiler_flags & A1C_OMIT_SUPPORT_CODE) == 0
&& skeletons_dir == NULL) {
struct stat sb; struct stat sb;
skeletons_dir = DATADIR; skeletons_dir = DATADIR;
if((av[-optind][0] == '.' || av[-optind][1] == '/') if((av[-optind][0] == '.' || av[-optind][1] == '/')
...@@ -326,7 +341,10 @@ usage(const char *av0) { ...@@ -326,7 +341,10 @@ usage(const char *av0) {
" -fno-include-deps Do not generate courtesy #includes for dependencies\n" " -fno-include-deps Do not generate courtesy #includes for dependencies\n"
" -funnamed-unions Enable unnamed unions in structures\n" " -funnamed-unions Enable unnamed unions in structures\n"
" -fskeletons-copy Force copying the support files\n" " -fskeletons-copy Force copying the support files\n"
" -ftypes88 Pretend to support only ASN.1:1988 embedded types\n" "\n"
" -gen-PER Generate PER support code\n"
" -pdu=auto Generate PDU table (discover PDUs automatically)\n"
"\n" "\n"
" -print-constraints Explain subtype constraints (debug)\n" " -print-constraints Explain subtype constraints (debug)\n"
......
...@@ -102,8 +102,8 @@ check(int is_ok, uint8_t *buf, int size, size_t consumed) { ...@@ -102,8 +102,8 @@ check(int is_ok, uint8_t *buf, int size, size_t consumed) {
assert(rval.code == RC_OK); assert(rval.code == RC_OK);
assert(rval.consumed == consumed); assert(rval.consumed == consumed);
assert(strcmp(t.e->buf, "xyz") == 0); assert(strcmp((char *)t.e->buf, "xyz") == 0);
assert(strcmp(t.f->buf, "love_it") == 0); assert(strcmp((char *)t.f->buf, "love_it") == 0);
assert(t.g->size == 2); assert(t.g->size == 2);
assert(t.g->bits_unused == 2); assert(t.g->bits_unused == 2);
......
...@@ -36,8 +36,12 @@ _buf_writer(const void *buffer, size_t size, void *app_key) { ...@@ -36,8 +36,12 @@ _buf_writer(const void *buffer, size_t size, void *app_key) {
b = buf + buf_offset; b = buf + buf_offset;
bend = b + size; bend = b + size;
fprintf(stderr, "=> ["); fprintf(stderr, "=> [");
for(; b < bend; b++) for(; b < bend; b++) {
if(*b >= 32 && *b < 127 && *b != '%')
fprintf(stderr, "%c", *b); fprintf(stderr, "%c", *b);
else
fprintf(stderr, "%%02x", *b);
}
fprintf(stderr, "]:%ld\n", (long)size); fprintf(stderr, "]:%ld\n", (long)size);
buf_offset += size; buf_offset += size;
return 0; return 0;
......
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "asn1c_out.h" #include "asn1c_out.h"
#include <asn1fix_crange.h> /* constraint groker from libasn1fix */ #include <asn1fix_crange.h> /* constraint groker from libasn1fix */
#include <asn1fix_export.h> /* other exportable stuff from libasn1fix */ #include <asn1fix_export.h> /* other exportables from libasn1fix */
static int asn1c_emit_constraint_tables(arg_t *arg, int got_size); static int asn1c_emit_constraint_tables(arg_t *arg, int got_size);
static int emit_alphabet_check_loop(arg_t *arg, asn1cnst_range_t *range); static int emit_alphabet_check_loop(arg_t *arg, asn1cnst_range_t *range);
......
...@@ -66,7 +66,12 @@ asn1c_read_file_dependencies(arg_t *arg, const char *datadir) { ...@@ -66,7 +66,12 @@ asn1c_read_file_dependencies(arg_t *arg, const char *datadir) {
asn1c_fdeps_t *cur; asn1c_fdeps_t *cur;
char buf[4096]; char buf[4096];
FILE *f; FILE *f;
int hit_COMMON_FILES = 0; enum {
SS_DYNAMIC, /* Dynamic list of dependencies */
SS_CODEC_PER, /* Use contents only if -gen-PER */
SS_COMMON_FILES, /* Section for dependencies */
SS_IGNORE /* Ignore contents of this section */
} special_section = SS_DYNAMIC;
(void)arg; (void)arg;
...@@ -91,17 +96,27 @@ asn1c_read_file_dependencies(arg_t *arg, const char *datadir) { ...@@ -91,17 +96,27 @@ asn1c_read_file_dependencies(arg_t *arg, const char *datadir) {
for(p = strtok(buf, " \t\r\n"); p; for(p = strtok(buf, " \t\r\n"); p;
p = strtok(NULL, " \t\r\n")) { p = strtok(NULL, " \t\r\n")) {
asn1c_fdeps_t *d; asn1c_fdeps_t *d;
/* /*
* If hit "COMMON-FILES:", treat everything else * Special "prefix" section.
* as a huge dependency.
*/ */
if(strchr(p, ':')) {
special_section = SS_IGNORE;
if(strcmp(p, "COMMON-FILES:") == 0) { if(strcmp(p, "COMMON-FILES:") == 0) {
hit_COMMON_FILES = 1; special_section = SS_COMMON_FILES;
} else if((arg->flags & A1C_GEN_PER)
&& strcmp(p, "CODEC-PER:") == 0) {
special_section = SS_CODEC_PER;
}
break; break;
} }
if(special_section == SS_IGNORE)
continue;
d = asn1c_new_dep(p); d = asn1c_new_dep(p);
assert(d); assert(d);
d->used_somewhere = hit_COMMON_FILES; d->used_somewhere = special_section;
if(asn1c_dep_add(cur, d) == 1) if(asn1c_dep_add(cur, d) == 1)
cur = d; cur = d;
......
...@@ -11,6 +11,7 @@ static int asn1c_print_streams(arg_t *arg); ...@@ -11,6 +11,7 @@ static int asn1c_print_streams(arg_t *arg);
static int asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *); static int asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *);
static int asn1c_copy_over(arg_t *arg, char *path); static int asn1c_copy_over(arg_t *arg, char *path);
static int identical_files(const char *fname1, const char *fname2); static int identical_files(const char *fname1, const char *fname2);
static int generate_pdu_collection_file(arg_t *arg);
int int
asn1c_save_compiled_output(arg_t *arg, const char *datadir, asn1c_save_compiled_output(arg_t *arg, const char *datadir,
...@@ -18,7 +19,7 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, ...@@ -18,7 +19,7 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
asn1c_fdeps_t *deps = 0; asn1c_fdeps_t *deps = 0;
asn1c_fdeps_t *dlist; asn1c_fdeps_t *dlist;
asn1p_module_t *mod; asn1p_module_t *mod;
FILE *mkf; FILE *mkf; /* Makefile.am.sample */
int i; int i;
deps = asn1c_read_file_dependencies(arg, datadir); deps = asn1c_read_file_dependencies(arg, datadir);
...@@ -108,6 +109,12 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, ...@@ -108,6 +109,12 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
} }
} }
if(arg->flags & A1C_PDU_AUTO) {
fprintf(mkf, "ASN_MODULE_SOURCES+=pdu_collection.c\n");
if(generate_pdu_collection_file(arg))
return -1;
}
fprintf(mkf, "\n\n" fprintf(mkf, "\n\n"
"lib_LTLIBRARIES=libsomething.la\n" "lib_LTLIBRARIES=libsomething.la\n"
"libsomething_la_SOURCES=" "libsomething_la_SOURCES="
...@@ -438,3 +445,62 @@ asn1c_copy_over(arg_t *arg, char *path) { ...@@ -438,3 +445,62 @@ asn1c_copy_over(arg_t *arg, char *path) {
return 1; return 1;
} }
static int
generate_pdu_collection_file(arg_t *arg) {
asn1p_module_t *mod;
FILE *fp;
fp = asn1c_open_file("pdu_collection", ".c", 0);
if(fp == NULL) {
perror("pdu_collection.c");
return -1;
}
fprintf(fp,
"/*\n"
" * Generated by asn1c-" VERSION " (http://lionet.info/asn1c)\n"
" */\n\n");
fprintf(fp, "struct asn_TYPE_descriptor_s;\t"
"/* Forward declaration */\n\n");
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
TQ_FOR(arg->expr, &(mod->members), next) {
if(arg->expr->_type_referenced
|| !asn1_lang_map[arg->expr->meta_type]
[arg->expr->expr_type].type_cb)
continue;
fprintf(fp, "extern struct asn_TYPE_descriptor_s "
"asn_DEF_%s;\n",
asn1c_make_identifier(0, arg->expr->Identifier,
NULL));
}
}
fprintf(fp, "\n\n");
fprintf(fp, "struct asn_TYPE_descriptor_s *asn_pdu_collection[] = {\n");
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
int mod_printed = 0;
TQ_FOR(arg->expr, &(mod->members), next) {
if(arg->expr->_type_referenced
|| !asn1_lang_map[arg->expr->meta_type]
[arg->expr->expr_type].type_cb)
continue;
if(!mod_printed++)
fprintf(fp, "\t/* From module %s in %s */\n",
arg->expr->module->ModuleName,
arg->expr->module->source_file_name);
fprintf(fp, "\t&asn_DEF_%s,\t\n",
asn1c_make_identifier(0, arg->expr->Identifier,
NULL));
}
}
fprintf(fp, "\t0\n};\n\n");
fclose(fp);
fprintf(stderr, "Generated pdu_collection.c\n");
return 0;
}
...@@ -56,6 +56,16 @@ enum asn1c_flags { ...@@ -56,6 +56,16 @@ enum asn1c_flags {
* Copy support files rather than symlink them. * Copy support files rather than symlink them.
*/ */
A1C_SKELETONS_COPY = 0x0800, A1C_SKELETONS_COPY = 0x0800,
/*
* -gen-PER
* Generate PER support code
*/
A1C_GEN_PER = 0x1000,
/*
* -pdu=auto
* Generate PDU table
*/
A1C_PDU_AUTO = 0x2000
}; };
/* /*
......
#include "asn1fix_internal.h" #include "asn1fix_internal.h"
#define AFT_MAGIC_ANY 1 /* _fetch_tag() flag */
static int _asn1f_check_if_tag_must_be_explicit(arg_t *arg, asn1p_expr_t *v); static int _asn1f_check_if_tag_must_be_explicit(arg_t *arg, asn1p_expr_t *v);
static int _asn1f_compare_tags(arg_t *arg, asn1p_expr_t *a, asn1p_expr_t *b); static int _asn1f_compare_tags(arg_t *arg, asn1p_expr_t *a, asn1p_expr_t *b);
static int _asn1f_fix_type_tag(arg_t *arg, asn1p_expr_t *expr); static int _asn1f_fix_type_tag(arg_t *arg, asn1p_expr_t *expr);
...@@ -337,6 +335,7 @@ asn1f_check_constr_tags_distinct(arg_t *arg) { ...@@ -337,6 +335,7 @@ asn1f_check_constr_tags_distinct(arg_t *arg) {
case ASN_CONSTR_SEQUENCE: case ASN_CONSTR_SEQUENCE:
case ASN_CONSTR_SET: case ASN_CONSTR_SET:
case ASN_CONSTR_CHOICE: case ASN_CONSTR_CHOICE:
DEBUG("Checking tags of members of constructed types");
break; break;
default: default:
return 0; return 0;
...@@ -353,6 +352,8 @@ asn1f_check_constr_tags_distinct(arg_t *arg) { ...@@ -353,6 +352,8 @@ asn1f_check_constr_tags_distinct(arg_t *arg) {
if(expr->expr_type != ASN_CONSTR_SEQUENCE || v->marker.flags) { if(expr->expr_type != ASN_CONSTR_SEQUENCE || v->marker.flags) {
asn1p_expr_t *nv; asn1p_expr_t *nv;
for(nv = v; (nv = TQ_NEXT(nv, next));) { for(nv = v; (nv = TQ_NEXT(nv, next));) {
DEBUG("S/C comparing tags %s s. %s",
v->Identifier, nv->Identifier);
if(_asn1f_compare_tags(arg, v, nv)) if(_asn1f_compare_tags(arg, v, nv))
r_value = -1; r_value = -1;
if(expr->expr_type == ASN_CONSTR_SEQUENCE if(expr->expr_type == ASN_CONSTR_SEQUENCE
...@@ -404,12 +405,15 @@ _asn1f_compare_tags(arg_t *arg, asn1p_expr_t *a, asn1p_expr_t *b) { ...@@ -404,12 +405,15 @@ _asn1f_compare_tags(arg_t *arg, asn1p_expr_t *a, asn1p_expr_t *b) {
int ra, rb; int ra, rb;
int ret; int ret;
ra = asn1f_fetch_outmost_tag(arg->asn, arg->mod, a, &ta, AFT_MAGIC_ANY); ra = asn1f_fetch_outmost_tag(arg->asn, arg->mod, a,
rb = asn1f_fetch_outmost_tag(arg->asn, arg->mod, b, &tb, AFT_MAGIC_ANY); &ta, AFT_IMAGINARY_ANY);
rb = asn1f_fetch_outmost_tag(arg->asn, arg->mod, b,
&tb, AFT_IMAGINARY_ANY);
/* /*
* If both tags are explicitly or implicitly given, use them. * If both tags are explicitly or implicitly given, use them.
*/ */
DEBUG("Fetching outmost tags: %d, %d", ra, rb);
if(ra == 0 && rb == 0) { if(ra == 0 && rb == 0) {
/* /*
* Simple case: fetched both tags. * Simple case: fetched both tags.
......
...@@ -370,6 +370,7 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, enum ftt_what what) { ...@@ -370,6 +370,7 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, enum ftt_what what) {
return NULL; return NULL;
} }
tc->_type_referenced = 1;
tc->_mark |= TM_RECURSION; tc->_mark |= TM_RECURSION;
WITH_MODULE(tc->module, WITH_MODULE(tc->module,
expr = asn1f_find_terminal_thing(arg, tc, what)); expr = asn1f_find_terminal_thing(arg, tc, what));
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
if((flags & AFT_FETCH_OUTMOST)) return count; \ if((flags & AFT_FETCH_OUTMOST)) return count; \
} while(0) } while(0)
/* X.691, #22.2 */
static int asn1f_fetch_minimal_choice_root_tag(arg_t *arg, struct asn1p_type_tag_s *tag, enum asn1f_aft_flags_e flags);
static int static int
asn1f_fetch_tags_impl(arg_t *arg, struct asn1p_type_tag_s **tags, int count, int skip, enum asn1f_aft_flags_e flags) { asn1f_fetch_tags_impl(arg_t *arg, struct asn1p_type_tag_s **tags, int count, int skip, enum asn1f_aft_flags_e flags) {
asn1p_expr_t *expr = arg->expr; asn1p_expr_t *expr = arg->expr;
...@@ -44,9 +47,13 @@ asn1f_fetch_tags_impl(arg_t *arg, struct asn1p_type_tag_s **tags, int count, int ...@@ -44,9 +47,13 @@ asn1f_fetch_tags_impl(arg_t *arg, struct asn1p_type_tag_s **tags, int count, int
if(expr->expr_type == ASN_TYPE_ANY if(expr->expr_type == ASN_TYPE_ANY
&& (flags & AFT_IMAGINARY_ANY)) && (flags & AFT_IMAGINARY_ANY))
tt.tag_value = -1; tt.tag_value = -1;
else if(expr->expr_type == ASN_CONSTR_CHOICE) else if(expr->expr_type != ASN_CONSTR_CHOICE)
return count ? count : -1; return -1;
else else if(count) return count;
else if((flags & AFT_CANON_CHOICE) == 0)
return -1;
else if(asn1f_fetch_minimal_choice_root_tag(arg,
&tt, flags))
return -1; return -1;
} }
ADD_TAG(skip, tt); ADD_TAG(skip, tt);
...@@ -55,6 +62,7 @@ asn1f_fetch_tags_impl(arg_t *arg, struct asn1p_type_tag_s **tags, int count, int ...@@ -55,6 +62,7 @@ asn1f_fetch_tags_impl(arg_t *arg, struct asn1p_type_tag_s **tags, int count, int
if(expr->meta_type == AMT_TYPEREF) { if(expr->meta_type == AMT_TYPEREF) {
asn1p_expr_t *nexpr; asn1p_expr_t *nexpr;
DEBUG("Following the reference %s", expr->Identifier);
nexpr = asn1f_lookup_symbol(arg, expr->module, expr->reference); nexpr = asn1f_lookup_symbol(arg, expr->module, expr->reference);
if(nexpr == NULL) { if(nexpr == NULL) {
if(errno != EEXIST) /* -fknown-extern-type */ if(errno != EEXIST) /* -fknown-extern-type */
...@@ -87,18 +95,52 @@ asn1f_fetch_tags_impl(arg_t *arg, struct asn1p_type_tag_s **tags, int count, int ...@@ -87,18 +95,52 @@ asn1f_fetch_tags_impl(arg_t *arg, struct asn1p_type_tag_s **tags, int count, int
return count; return count;
} }
DEBUG("No tags discovered for type %d", expr->expr_type);
return -1; return -1;
} }
static int
asn1f_fetch_minimal_choice_root_tag(arg_t *arg, struct asn1p_type_tag_s *tag, enum asn1f_aft_flags_e flags) {
struct asn1p_type_tag_s min_tag;
asn1p_expr_t *v;
memset(&min_tag, 0, sizeof(min_tag));
min_tag.tag_class = TC_PRIVATE + 1;
TQ_FOR(v, &(arg->expr->members), next) {
arg_t tmparg = *arg;
struct asn1p_type_tag_s *tags = 0;
int count;
if(v->expr_type == A1TC_EXTENSIBLE)
break; /* Search only within extension root */
tmparg.expr = v;
count = asn1f_fetch_tags_impl(&tmparg, &tags, 0, 0, flags);
if(count <= 0) continue;
if(tags[0].tag_class < min_tag.tag_class)
min_tag = tags[0];
else if(tags[0].tag_class == min_tag.tag_class
&& tags[0].tag_value < min_tag.tag_value)
min_tag = tags[0];
free(tags);
}
if(min_tag.tag_class == TC_PRIVATE + 1)
return -1;
else
*tag = min_tag;
return 0;
}
int int
asn1f_fetch_outmost_tag(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, struct asn1p_type_tag_s *tag, int _aft_imaginary_any) { asn1f_fetch_outmost_tag(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, struct asn1p_type_tag_s *tag, enum asn1f_aft_flags_e flags) {
struct asn1p_type_tag_s *tags; struct asn1p_type_tag_s *tags;
enum asn1f_aft_flags_e flags;
int count; int count;
flags = AFT_FETCH_OUTMOST; flags |= AFT_FETCH_OUTMOST;
flags |= AFT_IMAGINARY_ANY * _aft_imaginary_any;
count = asn1f_fetch_tags(asn, mod, expr, &tags, flags); count = asn1f_fetch_tags(asn, mod, expr, &tags, flags);
if(count <= 0) return count; if(count <= 0) return count;
......
...@@ -5,6 +5,7 @@ enum asn1f_aft_flags_e { ...@@ -5,6 +5,7 @@ enum asn1f_aft_flags_e {
AFT_IMAGINARY_ANY = 0x01, /* Treat ANY tag as [IMAGINARY ANY] */ AFT_IMAGINARY_ANY = 0x01, /* Treat ANY tag as [IMAGINARY ANY] */
AFT_FETCH_OUTMOST = 0x02, /* Fetch only outmost tag */ AFT_FETCH_OUTMOST = 0x02, /* Fetch only outmost tag */
AFT_FULL_COLLECT = 0x04, /* Collect all tags */ AFT_FULL_COLLECT = 0x04, /* Collect all tags */
AFT_CANON_CHOICE = 0x08, /* Fetch the minimal CHOICE root tag */
}; };
/* /*
...@@ -24,6 +25,6 @@ int asn1f_fetch_tags(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, ...@@ -24,6 +25,6 @@ int asn1f_fetch_tags(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr,
* Type3 ::= SEQUENCE { ... } * Type3 ::= SEQUENCE { ... }
* Will yield [2] for Type1. * Will yield [2] for Type1.
*/ */
int asn1f_fetch_outmost_tag(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, struct asn1p_type_tag_s *tag, int _aft_imaginary_any); int asn1f_fetch_outmost_tag(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, struct asn1p_type_tag_s *tag, enum asn1f_aft_flags_e);
#endif /* _ASN1FIX_TAGS_H_ */ #endif /* _ASN1FIX_TAGS_H_ */
...@@ -21,8 +21,10 @@ asn_TYPE_descriptor_t asn_DEF_ANY = { ...@@ -21,8 +21,10 @@ asn_TYPE_descriptor_t asn_DEF_ANY = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex, OCTET_STRING_decode_xer_hex,
ANY_encode_xer, ANY_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
&asn_DEF_ANY_specs, &asn_DEF_ANY_specs,
}; };
......
...@@ -27,6 +27,7 @@ asn_TYPE_descriptor_t asn_DEF_BIT_STRING = { ...@@ -27,6 +27,7 @@ asn_TYPE_descriptor_t asn_DEF_BIT_STRING = {
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_decode_xer_binary, OCTET_STRING_decode_xer_binary,
BIT_STRING_encode_xer, BIT_STRING_encode_xer,
OCTET_STRING_decode_uper, /* Unaligned PER decoder */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_BIT_STRING_tags, asn_DEF_BIT_STRING_tags,
sizeof(asn_DEF_BIT_STRING_tags) sizeof(asn_DEF_BIT_STRING_tags)
...@@ -34,6 +35,7 @@ asn_TYPE_descriptor_t asn_DEF_BIT_STRING = { ...@@ -34,6 +35,7 @@ asn_TYPE_descriptor_t asn_DEF_BIT_STRING = {
asn_DEF_BIT_STRING_tags, /* Same as above */ asn_DEF_BIT_STRING_tags, /* Same as above */
sizeof(asn_DEF_BIT_STRING_tags) sizeof(asn_DEF_BIT_STRING_tags)
/ sizeof(asn_DEF_BIT_STRING_tags[0]), / sizeof(asn_DEF_BIT_STRING_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
&asn_DEF_BIT_STRING_specs &asn_DEF_BIT_STRING_specs
}; };
...@@ -124,9 +126,7 @@ BIT_STRING_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -124,9 +126,7 @@ BIT_STRING_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1); if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0;
return er;
cb_failed: cb_failed:
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
......
...@@ -23,6 +23,7 @@ asn_TYPE_descriptor_t asn_DEF_BMPString = { ...@@ -23,6 +23,7 @@ asn_TYPE_descriptor_t asn_DEF_BMPString = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
BMPString_decode_xer, /* Convert from UTF-8 */ BMPString_decode_xer, /* Convert from UTF-8 */
BMPString_encode_xer, /* Convert to UTF-8 */ BMPString_encode_xer, /* Convert to UTF-8 */
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_BMPString_tags, asn_DEF_BMPString_tags,
sizeof(asn_DEF_BMPString_tags) sizeof(asn_DEF_BMPString_tags)
...@@ -30,6 +31,7 @@ asn_TYPE_descriptor_t asn_DEF_BMPString = { ...@@ -30,6 +31,7 @@ asn_TYPE_descriptor_t asn_DEF_BMPString = {
asn_DEF_BMPString_tags, asn_DEF_BMPString_tags,
sizeof(asn_DEF_BMPString_tags) sizeof(asn_DEF_BMPString_tags)
/ sizeof(asn_DEF_BMPString_tags[0]), / sizeof(asn_DEF_BMPString_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -156,7 +158,7 @@ BMPString_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -156,7 +158,7 @@ BMPString_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = BMPString__dump(st, cb, app_key); er.encoded = BMPString__dump(st, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED; if(er.encoded < 0) _ASN_ENCODE_FAILED;
return er; _ASN_ENCODED_OK(er);
} }
int int
......
/*- /*-
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h> #include <asn_internal.h>
...@@ -22,11 +22,13 @@ asn_TYPE_descriptor_t asn_DEF_BOOLEAN = { ...@@ -22,11 +22,13 @@ asn_TYPE_descriptor_t asn_DEF_BOOLEAN = {
BOOLEAN_encode_der, BOOLEAN_encode_der,
BOOLEAN_decode_xer, BOOLEAN_decode_xer,
BOOLEAN_encode_xer, BOOLEAN_encode_xer,
BOOLEAN_decode_uper, /* Unaligned PER decoder */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_BOOLEAN_tags, asn_DEF_BOOLEAN_tags,
sizeof(asn_DEF_BOOLEAN_tags) / sizeof(asn_DEF_BOOLEAN_tags[0]), sizeof(asn_DEF_BOOLEAN_tags) / sizeof(asn_DEF_BOOLEAN_tags[0]),
asn_DEF_BOOLEAN_tags, /* Same as above */ asn_DEF_BOOLEAN_tags, /* Same as above */
sizeof(asn_DEF_BOOLEAN_tags) / sizeof(asn_DEF_BOOLEAN_tags[0]), sizeof(asn_DEF_BOOLEAN_tags) / sizeof(asn_DEF_BOOLEAN_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -126,7 +128,7 @@ BOOLEAN_encode_der(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -126,7 +128,7 @@ BOOLEAN_encode_der(asn_TYPE_descriptor_t *td, void *sptr,
erval.encoded += 1; erval.encoded += 1;
return erval; _ASN_ENCODED_OK(erval);
} }
...@@ -196,7 +198,7 @@ BOOLEAN_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -196,7 +198,7 @@ BOOLEAN_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = 8; er.encoded = 8;
} }
return er; _ASN_ENCODED_OK(er);
cb_failed: cb_failed:
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
...@@ -234,3 +236,33 @@ BOOLEAN_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { ...@@ -234,3 +236,33 @@ BOOLEAN_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) {
} }
} }
asn_dec_rval_t
BOOLEAN_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_dec_rval_t rv;
BOOLEAN_t *st = (BOOLEAN_t *)*sptr;
(void)opt_codec_ctx;
(void)constraints;
if(!st) {
st = (BOOLEAN_t *)(*sptr = MALLOC(sizeof(*st)));
if(!st) _ASN_DECODE_FAILED;
}
/*
* Extract a single bit
*/
switch(per_get_few_bits(pd, 1)) {
case 1: *st = 1; break;
case 0: *st = 0; break;
case -1: default: _ASN_DECODE_FAILED;
}
ASN_DEBUG("%s decoded as %s", td->name, *st ? "TRUE" : "FALSE");
rv.code = RC_OK;
rv.consumed = 1;
return rv;
}
...@@ -26,6 +26,7 @@ ber_type_decoder_f BOOLEAN_decode_ber; ...@@ -26,6 +26,7 @@ ber_type_decoder_f BOOLEAN_decode_ber;
der_type_encoder_f BOOLEAN_encode_der; der_type_encoder_f BOOLEAN_encode_der;
xer_type_decoder_f BOOLEAN_decode_xer; xer_type_decoder_f BOOLEAN_decode_xer;
xer_type_encoder_f BOOLEAN_encode_xer; xer_type_encoder_f BOOLEAN_encode_xer;
per_type_decoder_f BOOLEAN_decode_uper;
#ifdef __cplusplus #ifdef __cplusplus
} }
......
/*- /*-
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h> #include <asn_internal.h>
#include <ENUMERATED.h> #include <ENUMERATED.h>
#include <NativeEnumerated.h>
#include <asn_codecs_prim.h> /* Encoder and decoder of a primitive type */ #include <asn_codecs_prim.h> /* Encoder and decoder of a primitive type */
/* /*
...@@ -22,12 +23,33 @@ asn_TYPE_descriptor_t asn_DEF_ENUMERATED = { ...@@ -22,12 +23,33 @@ asn_TYPE_descriptor_t asn_DEF_ENUMERATED = {
INTEGER_encode_der, /* Implemented in terms of INTEGER */ INTEGER_encode_der, /* Implemented in terms of INTEGER */
INTEGER_decode_xer, /* This is temporary! */ INTEGER_decode_xer, /* This is temporary! */
INTEGER_encode_xer, INTEGER_encode_xer,
ENUMERATED_decode_uper, /* Unaligned PER decoder */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_ENUMERATED_tags, asn_DEF_ENUMERATED_tags,
sizeof(asn_DEF_ENUMERATED_tags) / sizeof(asn_DEF_ENUMERATED_tags[0]), sizeof(asn_DEF_ENUMERATED_tags) / sizeof(asn_DEF_ENUMERATED_tags[0]),
asn_DEF_ENUMERATED_tags, /* Same as above */ asn_DEF_ENUMERATED_tags, /* Same as above */
sizeof(asn_DEF_ENUMERATED_tags) / sizeof(asn_DEF_ENUMERATED_tags[0]), sizeof(asn_DEF_ENUMERATED_tags) / sizeof(asn_DEF_ENUMERATED_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
asn_dec_rval_t
ENUMERATED_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_dec_rval_t rval;
ENUMERATED_t *st = (ENUMERATED_t *)*sptr;
long value, *vptr = &value;
if(!st) {
st = (ENUMERATED_t *)(*sptr = CALLOC(1, sizeof(*st)));
if(!st) _ASN_DECODE_FAILED;
}
rval = NativeEnumerated_decode_uper(opt_codec_ctx, td, constraints,
(void **)&vptr, pd);
if(rval.code == RC_OK)
if(asn_long2INTEGER(st, value))
rval.code = RC_FAIL;
return rval;
}
/*- /*-
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#ifndef _ENUMERATED_H_ #ifndef _ENUMERATED_H_
...@@ -15,6 +15,8 @@ typedef INTEGER_t ENUMERATED_t; /* Implemented via INTEGER */ ...@@ -15,6 +15,8 @@ typedef INTEGER_t ENUMERATED_t; /* Implemented via INTEGER */
extern asn_TYPE_descriptor_t asn_DEF_ENUMERATED; extern asn_TYPE_descriptor_t asn_DEF_ENUMERATED;
per_type_decoder_f ENUMERATED_decode_uper;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralString = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralString = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex, OCTET_STRING_decode_xer_hex,
OCTET_STRING_encode_xer, OCTET_STRING_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_GeneralString_tags, asn_DEF_GeneralString_tags,
sizeof(asn_DEF_GeneralString_tags) sizeof(asn_DEF_GeneralString_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralString = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralString = {
asn_DEF_GeneralString_tags, asn_DEF_GeneralString_tags,
sizeof(asn_DEF_GeneralString_tags) sizeof(asn_DEF_GeneralString_tags)
/ sizeof(asn_DEF_GeneralString_tags[0]), / sizeof(asn_DEF_GeneralString_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -128,6 +128,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralizedTime = { ...@@ -128,6 +128,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralizedTime = {
GeneralizedTime_encode_der, GeneralizedTime_encode_der,
OCTET_STRING_decode_xer_utf8, OCTET_STRING_decode_xer_utf8,
GeneralizedTime_encode_xer, GeneralizedTime_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_GeneralizedTime_tags, asn_DEF_GeneralizedTime_tags,
sizeof(asn_DEF_GeneralizedTime_tags) sizeof(asn_DEF_GeneralizedTime_tags)
...@@ -135,6 +136,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralizedTime = { ...@@ -135,6 +136,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralizedTime = {
asn_DEF_GeneralizedTime_tags, asn_DEF_GeneralizedTime_tags,
sizeof(asn_DEF_GeneralizedTime_tags) sizeof(asn_DEF_GeneralizedTime_tags)
/ sizeof(asn_DEF_GeneralizedTime_tags[0]), / sizeof(asn_DEF_GeneralizedTime_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_GraphicString = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_GraphicString = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex, OCTET_STRING_decode_xer_hex,
OCTET_STRING_encode_xer, /* Can't expect it to be ASCII/UTF8 */ OCTET_STRING_encode_xer, /* Can't expect it to be ASCII/UTF8 */
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_GraphicString_tags, asn_DEF_GraphicString_tags,
sizeof(asn_DEF_GraphicString_tags) sizeof(asn_DEF_GraphicString_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_GraphicString = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_GraphicString = {
asn_DEF_GraphicString_tags, asn_DEF_GraphicString_tags,
sizeof(asn_DEF_GraphicString_tags) sizeof(asn_DEF_GraphicString_tags)
/ sizeof(asn_DEF_GraphicString_tags[0]), / sizeof(asn_DEF_GraphicString_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_IA5String = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_IA5String = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_utf8, OCTET_STRING_decode_xer_utf8,
OCTET_STRING_encode_xer_utf8, OCTET_STRING_encode_xer_utf8,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_IA5String_tags, asn_DEF_IA5String_tags,
sizeof(asn_DEF_IA5String_tags) sizeof(asn_DEF_IA5String_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_IA5String = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_IA5String = {
asn_DEF_IA5String_tags, asn_DEF_IA5String_tags,
sizeof(asn_DEF_IA5String_tags) sizeof(asn_DEF_IA5String_tags)
/ sizeof(asn_DEF_IA5String_tags[0]), / sizeof(asn_DEF_IA5String_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -24,11 +24,13 @@ asn_TYPE_descriptor_t asn_DEF_INTEGER = { ...@@ -24,11 +24,13 @@ asn_TYPE_descriptor_t asn_DEF_INTEGER = {
INTEGER_encode_der, INTEGER_encode_der,
INTEGER_decode_xer, INTEGER_decode_xer,
INTEGER_encode_xer, INTEGER_encode_xer,
INTEGER_decode_uper, /* Unaligned PER decoder */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_INTEGER_tags, asn_DEF_INTEGER_tags,
sizeof(asn_DEF_INTEGER_tags) / sizeof(asn_DEF_INTEGER_tags[0]), sizeof(asn_DEF_INTEGER_tags) / sizeof(asn_DEF_INTEGER_tags[0]),
asn_DEF_INTEGER_tags, /* Same as above */ asn_DEF_INTEGER_tags, /* Same as above */
sizeof(asn_DEF_INTEGER_tags) / sizeof(asn_DEF_INTEGER_tags[0]), sizeof(asn_DEF_INTEGER_tags) / sizeof(asn_DEF_INTEGER_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -430,9 +432,102 @@ INTEGER_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -430,9 +432,102 @@ INTEGER_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = INTEGER__dump(td, st, cb, app_key, 1); er.encoded = INTEGER__dump(td, st, cb, app_key, 1);
if(er.encoded < 0) _ASN_ENCODE_FAILED; if(er.encoded < 0) _ASN_ENCODE_FAILED;
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0; }
return er;
asn_dec_rval_t
INTEGER_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_dec_rval_t rval = { RC_OK, 0 };
INTEGER_t *st = (INTEGER_t *)*sptr;
asn_per_constraint_t *ct;
int repeat;
(void)opt_codec_ctx;
if(!st) {
st = (INTEGER_t *)(*sptr = CALLOC(1, sizeof(*st)));
if(!st) _ASN_DECODE_FAILED;
}
if(!constraints) constraints = td->per_constraints;
ct = constraints ? &constraints->value : 0;
if(ct && ct->flags & APC_EXTENSIBLE) {
int inext = per_get_few_bits(pd, 1);
if(inext < 0) _ASN_DECODE_FAILED;
if(inext) ct = 0;
}
FREEMEM(st->buf);
if(ct) {
if(ct->flags & APC_SEMI_CONSTRAINED) {
st->buf = (uint8_t *)CALLOC(1, 2);
if(!st->buf) _ASN_DECODE_FAILED;
st->size = 1;
} else if(ct->flags & APC_CONSTRAINED && ct->range_bits >= 0) {
size_t size = (ct->range_bits + 7) >> 3;
st->buf = (uint8_t *)MALLOC(1 + size + 1);
if(!st->buf) _ASN_DECODE_FAILED;
st->size = size;
} else {
st->size = 0;
}
} else {
st->size = 0;
}
/* X.691, #12.2.2 */
if(ct && ct->flags != APC_UNCONSTRAINED) {
/* #10.5.6 */
ASN_DEBUG("Integer with range %d bits", ct->range_bits);
if(ct->range_bits >= 0) {
long value = per_get_few_bits(pd, ct->range_bits);
if(value < 0) _ASN_DECODE_FAILED;
ASN_DEBUG("Got value %ld + low %ld",
value, ct->lower_bound);
value += ct->lower_bound;
if(asn_long2INTEGER(st, value))
_ASN_DECODE_FAILED;
return rval;
}
} else {
ASN_DEBUG("Decoding unconstrained integer %s", td->name);
}
/* X.691, #12.2.3, #12.2.4 */
do {
ssize_t len;
void *p;
int ret;
/* Get the PER length */
len = uper_get_length(pd, -1, &repeat);
if(len < 0) _ASN_DECODE_FAILED;
p = REALLOC(st->buf, st->size + len + 1);
if(!p) _ASN_DECODE_FAILED;
st->buf = (uint8_t *)p;
ret = per_get_many_bits(pd, &st->buf[st->size], 0, 8 * len);
if(ret < 0) _ASN_DECODE_FAILED;
st->size += len;
} while(repeat);
st->buf[st->size] = 0; /* JIC */
/* #12.2.3 */
if(ct && ct->lower_bound) {
/*
* TODO: replace by in-place arithmetics.
*/
long value;
if(asn_INTEGER2long(st, &value))
_ASN_DECODE_FAILED;
if(asn_long2INTEGER(st, value + ct->lower_bound))
_ASN_DECODE_FAILED;
}
return rval;
} }
int int
......
...@@ -28,7 +28,7 @@ typedef struct asn_INTEGER_specifics_s { ...@@ -28,7 +28,7 @@ typedef struct asn_INTEGER_specifics_s {
asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */ asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
unsigned int *enum2value; /* "tag" => N; sorted by tag */ unsigned int *enum2value; /* "tag" => N; sorted by tag */
int map_count; /* Elements in either map */ int map_count; /* Elements in either map */
int extensible; /* This map is extensible */ int extension; /* This map is extensible */
int strict_enumeration; /* Enumeration set is fixed */ int strict_enumeration; /* Enumeration set is fixed */
} asn_INTEGER_specifics_t; } asn_INTEGER_specifics_t;
...@@ -37,6 +37,7 @@ ber_type_decoder_f INTEGER_decode_ber; ...@@ -37,6 +37,7 @@ ber_type_decoder_f INTEGER_decode_ber;
der_type_encoder_f INTEGER_encode_der; der_type_encoder_f INTEGER_encode_der;
xer_type_decoder_f INTEGER_decode_xer; xer_type_decoder_f INTEGER_decode_xer;
xer_type_encoder_f INTEGER_encode_xer; xer_type_encoder_f INTEGER_encode_xer;
per_type_decoder_f INTEGER_decode_uper;
/*********************************** /***********************************
* Some handy conversion routines. * * Some handy conversion routines. *
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_ISO646String = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_ISO646String = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_utf8, OCTET_STRING_decode_xer_utf8,
OCTET_STRING_encode_xer_utf8, OCTET_STRING_encode_xer_utf8,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_ISO646String_tags, asn_DEF_ISO646String_tags,
sizeof(asn_DEF_ISO646String_tags) sizeof(asn_DEF_ISO646String_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_ISO646String = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_ISO646String = {
asn_DEF_ISO646String_tags, asn_DEF_ISO646String_tags,
sizeof(asn_DEF_ISO646String_tags) sizeof(asn_DEF_ISO646String_tags)
/ sizeof(asn_DEF_ISO646String_tags[0]), / sizeof(asn_DEF_ISO646String_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
/*- /*-
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h> #include <asn_internal.h>
...@@ -23,11 +23,13 @@ asn_TYPE_descriptor_t asn_DEF_NULL = { ...@@ -23,11 +23,13 @@ asn_TYPE_descriptor_t asn_DEF_NULL = {
NULL_encode_der, /* Special handling of DER encoding */ NULL_encode_der, /* Special handling of DER encoding */
NULL_decode_xer, NULL_decode_xer,
NULL_encode_xer, NULL_encode_xer,
NULL_decode_uper, /* Unaligned PER decoder */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_NULL_tags, asn_DEF_NULL_tags,
sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]), sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
asn_DEF_NULL_tags, /* Same as above */ asn_DEF_NULL_tags, /* Same as above */
sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]), sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -44,7 +46,7 @@ NULL_encode_der(asn_TYPE_descriptor_t *td, void *ptr, ...@@ -44,7 +46,7 @@ NULL_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
erval.structure_ptr = ptr; erval.structure_ptr = ptr;
} }
return erval; _ASN_ENCODED_OK(erval);
} }
asn_enc_rval_t asn_enc_rval_t
...@@ -62,8 +64,7 @@ NULL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -62,8 +64,7 @@ NULL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
/* XMLNullValue is empty */ /* XMLNullValue is empty */
er.encoded = 0; er.encoded = 0;
_ASN_ENCODED_OK(er);
return er;
} }
...@@ -101,3 +102,31 @@ NULL_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -101,3 +102,31 @@ NULL_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
return (cb("<absent>", 8, app_key) < 0) ? -1 : 0; return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
} }
} }
asn_dec_rval_t
NULL_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_dec_rval_t rv;
(void)opt_codec_ctx;
(void)td;
(void)constraints;
(void)pd;
if(!*sptr) {
*sptr = MALLOC(sizeof(NULL_t));
if(*sptr) {
*(NULL_t *)*sptr = 0;
} else {
_ASN_DECODE_FAILED;
}
}
/*
* NULL type does not have content octets.
*/
rv.code = RC_OK;
rv.consumed = 0;
return rv;
}
...@@ -23,6 +23,7 @@ asn_struct_print_f NULL_print; ...@@ -23,6 +23,7 @@ asn_struct_print_f NULL_print;
der_type_encoder_f NULL_encode_der; der_type_encoder_f NULL_encode_der;
xer_type_decoder_f NULL_decode_xer; xer_type_decoder_f NULL_decode_xer;
xer_type_encoder_f NULL_encode_xer; xer_type_encoder_f NULL_encode_xer;
per_type_decoder_f NULL_decode_uper;
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -28,11 +28,13 @@ asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = { ...@@ -28,11 +28,13 @@ asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = {
NativeInteger_encode_der, NativeInteger_encode_der,
NativeInteger_decode_xer, NativeInteger_decode_xer,
NativeEnumerated_encode_xer, NativeEnumerated_encode_xer,
NativeEnumerated_decode_uper,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_NativeEnumerated_tags, asn_DEF_NativeEnumerated_tags,
sizeof(asn_DEF_NativeEnumerated_tags) / sizeof(asn_DEF_NativeEnumerated_tags[0]), sizeof(asn_DEF_NativeEnumerated_tags) / sizeof(asn_DEF_NativeEnumerated_tags[0]),
asn_DEF_NativeEnumerated_tags, /* Same as above */ asn_DEF_NativeEnumerated_tags, /* Same as above */
sizeof(asn_DEF_NativeEnumerated_tags) / sizeof(asn_DEF_NativeEnumerated_tags[0]), sizeof(asn_DEF_NativeEnumerated_tags) / sizeof(asn_DEF_NativeEnumerated_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -59,13 +61,65 @@ NativeEnumerated_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -59,13 +61,65 @@ NativeEnumerated_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = snprintf(src, srcsize, "<%s/>", el->enum_name); er.encoded = snprintf(src, srcsize, "<%s/>", el->enum_name);
assert(er.encoded > 0 && (size_t)er.encoded < srcsize); assert(er.encoded > 0 && (size_t)er.encoded < srcsize);
if(cb(src, er.encoded, app_key) < 0) _ASN_ENCODE_FAILED; if(cb(src, er.encoded, app_key) < 0) _ASN_ENCODE_FAILED;
return er; _ASN_ENCODED_OK(er);
} else { } else {
ASN_DEBUG("ASN.1 forbids dealing with " ASN_DEBUG("ASN.1 forbids dealing with "
"unknown value of ENUMERATED type"); "unknown value of ENUMERATED type");
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
}
asn_dec_rval_t
NativeEnumerated_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
asn_dec_rval_t rval = { RC_OK, 0 };
long *native = (long *)*sptr;
asn_per_constraint_t *ct;
long value;
(void)opt_codec_ctx;
if(constraints) ct = &constraints->value;
else if(td->per_constraints) ct = &td->per_constraints->value;
else _ASN_DECODE_FAILED; /* Mandatory! */
if(!specs) _ASN_DECODE_FAILED;
if(!native) {
native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
if(!native) _ASN_DECODE_FAILED;
}
ASN_DEBUG("Decoding %s as NativeEnumerated", td->name);
if(ct->flags & APC_EXTENSIBLE) {
int inext = per_get_few_bits(pd, 1);
if(inext < 0) _ASN_DECODE_FAILED;
if(inext) ct = 0;
}
if(ct && ct->range_bits >= 0) {
value = per_get_few_bits(pd, ct->range_bits);
if(value < 0) _ASN_DECODE_FAILED;
if(value >= (specs->extension
? specs->extension - 1 : specs->map_count))
_ASN_DECODE_FAILED;
} else {
if(!specs->extension)
_ASN_DECODE_FAILED;
/*
* X.691, #10.6: normally small non-negative whole number;
*/
value = uper_get_nsnnwn(pd);
if(value < 0) _ASN_DECODE_FAILED;
value += specs->extension - 1;
if(value >= specs->map_count)
_ASN_DECODE_FAILED;
}
*native = specs->value2enum[value].nat_value;
ASN_DEBUG("Decoded %s = %ld", td->name, *native);
return er; return rval;
} }
...@@ -21,6 +21,7 @@ extern "C" { ...@@ -21,6 +21,7 @@ extern "C" {
extern asn_TYPE_descriptor_t asn_DEF_NativeEnumerated; extern asn_TYPE_descriptor_t asn_DEF_NativeEnumerated;
xer_type_encoder_f NativeEnumerated_encode_xer; xer_type_encoder_f NativeEnumerated_encode_xer;
per_type_decoder_f NativeEnumerated_decode_uper;
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -28,11 +28,13 @@ asn_TYPE_descriptor_t asn_DEF_NativeInteger = { ...@@ -28,11 +28,13 @@ asn_TYPE_descriptor_t asn_DEF_NativeInteger = {
NativeInteger_encode_der, NativeInteger_encode_der,
NativeInteger_decode_xer, NativeInteger_decode_xer,
NativeInteger_encode_xer, NativeInteger_encode_xer,
NativeInteger_decode_uper, /* Unaligned PER decoder */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_NativeInteger_tags, asn_DEF_NativeInteger_tags,
sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]), sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]),
asn_DEF_NativeInteger_tags, /* Same as above */ asn_DEF_NativeInteger_tags, /* Same as above */
sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]), sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -108,18 +110,6 @@ NativeInteger_decode_ber(asn_codec_ctx_t *opt_codec_ctx, ...@@ -108,18 +110,6 @@ NativeInteger_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
} }
*native = l; *native = l;
/*
* Note that native integer size might be other than long.
* This expression hopefully will be optimized away
* by compiler.
*/
if(sizeof(*native) != sizeof(long) && ((long)*native != l)) {
*native = 0; /* Safe value */
rval.code = RC_FAIL;
rval.consumed = 0;
return rval;
}
} }
rval.code = RC_OK; rval.code = RC_OK;
...@@ -176,38 +166,25 @@ NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx, ...@@ -176,38 +166,25 @@ NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname, asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
const void *buf_ptr, size_t size) { const void *buf_ptr, size_t size) {
asn_dec_rval_t rval; asn_dec_rval_t rval;
INTEGER_t *st = 0; INTEGER_t st;
void *st_ptr = (void *)&st; void *st_ptr = (void *)&st;
long *native = (long *)*sptr; long *native = (long *)*sptr;
if(!native) { if(!native) {
*sptr = CALLOC(1, sizeof(int)); native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
native = (long *)*sptr; if(!native) _ASN_DECODE_FAILED;
if(!native) {
rval.code = RC_FAIL;
rval.consumed = 0;
return rval;
}
} }
rval = INTEGER_decode_xer(opt_codec_ctx, td, (void **)st_ptr, memset(&st, 0, sizeof(st));
rval = INTEGER_decode_xer(opt_codec_ctx, td, &st_ptr,
opt_mname, buf_ptr, size); opt_mname, buf_ptr, size);
if(rval.code == RC_OK) { if(rval.code == RC_OK) {
long l; long l;
if(asn_INTEGER2long(st, &l)) { if(asn_INTEGER2long(&st, &l)) {
rval.code = RC_FAIL; rval.code = RC_FAIL;
rval.consumed = 0; rval.consumed = 0;
} else { } else {
*native = l; *native = l;
/* Native type might be shorter than long */
if(sizeof(*native) != sizeof(long)
&& ((long)*native != l)) {
*native = 0; /* Safe value */
rval.code = RC_FAIL;
rval.consumed = 0;
return rval;
}
} }
} else { } else {
/* /*
...@@ -217,7 +194,7 @@ NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx, ...@@ -217,7 +194,7 @@ NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
*/ */
rval.consumed = 0; rval.consumed = 0;
} }
asn_DEF_INTEGER.free_struct(&asn_DEF_INTEGER, st, 0); asn_DEF_INTEGER.free_struct(&asn_DEF_INTEGER, &st, 1);
return rval; return rval;
} }
...@@ -240,7 +217,39 @@ NativeInteger_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -240,7 +217,39 @@ NativeInteger_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
|| cb(scratch, er.encoded, app_key) < 0) || cb(scratch, er.encoded, app_key) < 0)
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
return er; _ASN_ENCODED_OK(er);
}
asn_dec_rval_t
NativeInteger_decode_uper(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_dec_rval_t rval;
long *native = (long *)*sptr;
INTEGER_t tmpint;
void *tmpintptr = &tmpint;
(void)opt_codec_ctx;
ASN_DEBUG("Decoding NativeInteger %s (UPER)", td->name);
if(!native) {
native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
if(!native) _ASN_DECODE_FAILED;
}
memset(&tmpint, 0, sizeof tmpint);
rval = INTEGER_decode_uper(opt_codec_ctx, td, constraints,
&tmpintptr, pd);
if(rval.code == RC_OK)
if(asn_INTEGER2long(&tmpint, native))
rval.code = RC_FAIL;
else
ASN_DEBUG("NativeInteger %s got value %ld",
td->name, *native);
asn_DEF_INTEGER.free_struct(&asn_DEF_INTEGER, &tmpint, 1);
return rval;
} }
/* /*
......
...@@ -27,6 +27,7 @@ ber_type_decoder_f NativeInteger_decode_ber; ...@@ -27,6 +27,7 @@ ber_type_decoder_f NativeInteger_decode_ber;
der_type_encoder_f NativeInteger_encode_der; der_type_encoder_f NativeInteger_encode_der;
xer_type_decoder_f NativeInteger_decode_xer; xer_type_decoder_f NativeInteger_decode_xer;
xer_type_encoder_f NativeInteger_encode_xer; xer_type_encoder_f NativeInteger_encode_xer;
per_type_decoder_f NativeInteger_decode_uper;
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -29,11 +29,13 @@ asn_TYPE_descriptor_t asn_DEF_NativeReal = { ...@@ -29,11 +29,13 @@ asn_TYPE_descriptor_t asn_DEF_NativeReal = {
NativeReal_encode_der, NativeReal_encode_der,
NativeReal_decode_xer, NativeReal_decode_xer,
NativeReal_encode_xer, NativeReal_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_NativeReal_tags, asn_DEF_NativeReal_tags,
sizeof(asn_DEF_NativeReal_tags) / sizeof(asn_DEF_NativeReal_tags[0]), sizeof(asn_DEF_NativeReal_tags) / sizeof(asn_DEF_NativeReal_tags[0]),
asn_DEF_NativeReal_tags, /* Same as above */ asn_DEF_NativeReal_tags, /* Same as above */
sizeof(asn_DEF_NativeReal_tags) / sizeof(asn_DEF_NativeReal_tags[0]), sizeof(asn_DEF_NativeReal_tags) / sizeof(asn_DEF_NativeReal_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -206,7 +208,7 @@ NativeReal_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -206,7 +208,7 @@ NativeReal_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = REAL__dump(*Dbl, flags & XER_F_CANONICAL, cb, app_key); er.encoded = REAL__dump(*Dbl, flags & XER_F_CANONICAL, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED; if(er.encoded < 0) _ASN_ENCODE_FAILED;
return er; _ASN_ENCODED_OK(er);
} }
/* /*
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_NumericString = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_NumericString = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_utf8, OCTET_STRING_decode_xer_utf8,
OCTET_STRING_encode_xer_utf8, OCTET_STRING_encode_xer_utf8,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_NumericString_tags, asn_DEF_NumericString_tags,
sizeof(asn_DEF_NumericString_tags) sizeof(asn_DEF_NumericString_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_NumericString = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_NumericString = {
asn_DEF_NumericString_tags, asn_DEF_NumericString_tags,
sizeof(asn_DEF_NumericString_tags) sizeof(asn_DEF_NumericString_tags)
/ sizeof(asn_DEF_NumericString_tags[0]), / sizeof(asn_DEF_NumericString_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -23,6 +23,7 @@ asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER = { ...@@ -23,6 +23,7 @@ asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER = {
der_encode_primitive, der_encode_primitive,
OBJECT_IDENTIFIER_decode_xer, OBJECT_IDENTIFIER_decode_xer,
OBJECT_IDENTIFIER_encode_xer, OBJECT_IDENTIFIER_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_OBJECT_IDENTIFIER_tags, asn_DEF_OBJECT_IDENTIFIER_tags,
sizeof(asn_DEF_OBJECT_IDENTIFIER_tags) sizeof(asn_DEF_OBJECT_IDENTIFIER_tags)
...@@ -30,6 +31,7 @@ asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER = { ...@@ -30,6 +31,7 @@ asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER = {
asn_DEF_OBJECT_IDENTIFIER_tags, /* Same as above */ asn_DEF_OBJECT_IDENTIFIER_tags, /* Same as above */
sizeof(asn_DEF_OBJECT_IDENTIFIER_tags) sizeof(asn_DEF_OBJECT_IDENTIFIER_tags)
/ sizeof(asn_DEF_OBJECT_IDENTIFIER_tags[0]), / sizeof(asn_DEF_OBJECT_IDENTIFIER_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -332,9 +334,7 @@ OBJECT_IDENTIFIER_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -332,9 +334,7 @@ OBJECT_IDENTIFIER_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = OBJECT_IDENTIFIER__dump_body(st, cb, app_key); er.encoded = OBJECT_IDENTIFIER__dump_body(st, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED; if(er.encoded < 0) _ASN_ENCODE_FAILED;
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0;
return er;
} }
int int
......
...@@ -19,6 +19,9 @@ static asn_OCTET_STRING_specifics_t asn_DEF_OCTET_STRING_specs = { ...@@ -19,6 +19,9 @@ static asn_OCTET_STRING_specifics_t asn_DEF_OCTET_STRING_specs = {
offsetof(OCTET_STRING_t, _asn_ctx), offsetof(OCTET_STRING_t, _asn_ctx),
0 0
}; };
static asn_per_constraint_t asn_DEF_OCTET_STRING_constraint = {
APC_SEMI_CONSTRAINED, -1, 0, 0, 0
};
asn_TYPE_descriptor_t asn_DEF_OCTET_STRING = { asn_TYPE_descriptor_t asn_DEF_OCTET_STRING = {
"OCTET STRING", /* Canonical name */ "OCTET STRING", /* Canonical name */
"OCTET_STRING", /* XML tag name */ "OCTET_STRING", /* XML tag name */
...@@ -29,6 +32,7 @@ asn_TYPE_descriptor_t asn_DEF_OCTET_STRING = { ...@@ -29,6 +32,7 @@ asn_TYPE_descriptor_t asn_DEF_OCTET_STRING = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex, OCTET_STRING_decode_xer_hex,
OCTET_STRING_encode_xer, OCTET_STRING_encode_xer,
OCTET_STRING_decode_uper, /* Unaligned PER decoder */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_OCTET_STRING_tags, asn_DEF_OCTET_STRING_tags,
sizeof(asn_DEF_OCTET_STRING_tags) sizeof(asn_DEF_OCTET_STRING_tags)
...@@ -36,6 +40,7 @@ asn_TYPE_descriptor_t asn_DEF_OCTET_STRING = { ...@@ -36,6 +40,7 @@ asn_TYPE_descriptor_t asn_DEF_OCTET_STRING = {
asn_DEF_OCTET_STRING_tags, /* Same as above */ asn_DEF_OCTET_STRING_tags, /* Same as above */
sizeof(asn_DEF_OCTET_STRING_tags) sizeof(asn_DEF_OCTET_STRING_tags)
/ sizeof(asn_DEF_OCTET_STRING_tags[0]), / sizeof(asn_DEF_OCTET_STRING_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
&asn_DEF_OCTET_STRING_specs &asn_DEF_OCTET_STRING_specs
}; };
...@@ -61,9 +66,10 @@ asn_TYPE_descriptor_t asn_DEF_OCTET_STRING = { ...@@ -61,9 +66,10 @@ asn_TYPE_descriptor_t asn_DEF_OCTET_STRING = {
#undef RETURN #undef RETURN
#define RETURN(_code) do { \ #define RETURN(_code) do { \
rval.code = _code; \ asn_dec_rval_t tmprval; \
rval.consumed = consumed_myself; \ tmprval.code = _code; \
return rval; \ tmprval.consumed = consumed_myself; \
return tmprval; \
} while(0) } while(0)
#undef APPEND #undef APPEND
...@@ -167,11 +173,11 @@ _new_stack() { ...@@ -167,11 +173,11 @@ _new_stack() {
asn_dec_rval_t asn_dec_rval_t
OCTET_STRING_decode_ber(asn_codec_ctx_t *opt_codec_ctx, OCTET_STRING_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td, asn_TYPE_descriptor_t *td,
void **os_structure, const void *buf_ptr, size_t size, int tag_mode) { void **sptr, const void *buf_ptr, size_t size, int tag_mode) {
asn_OCTET_STRING_specifics_t *specs = td->specifics asn_OCTET_STRING_specifics_t *specs = td->specifics
? (asn_OCTET_STRING_specifics_t *)td->specifics ? (asn_OCTET_STRING_specifics_t *)td->specifics
: &asn_DEF_OCTET_STRING_specs; : &asn_DEF_OCTET_STRING_specs;
BIT_STRING_t *st = (BIT_STRING_t *)*os_structure; BIT_STRING_t *st = (BIT_STRING_t *)*sptr;
asn_dec_rval_t rval; asn_dec_rval_t rval;
asn_struct_ctx_t *ctx; asn_struct_ctx_t *ctx;
ssize_t consumed_myself = 0; ssize_t consumed_myself = 0;
...@@ -190,10 +196,8 @@ OCTET_STRING_decode_ber(asn_codec_ctx_t *opt_codec_ctx, ...@@ -190,10 +196,8 @@ OCTET_STRING_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
* Create the string if does not exist. * Create the string if does not exist.
*/ */
if(st == NULL) { if(st == NULL) {
*os_structure = CALLOC(1, specs->struct_size); st = (BIT_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
st = (BIT_STRING_t *)*os_structure; if(st == NULL) RETURN(RC_FAIL);
if(st == NULL)
RETURN(RC_FAIL);
} }
/* Restore parsing context */ /* Restore parsing context */
...@@ -549,9 +553,7 @@ OCTET_STRING_encode_der(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -549,9 +553,7 @@ OCTET_STRING_encode_der(asn_TYPE_descriptor_t *td, void *sptr,
if(!cb) { if(!cb) {
er.encoded += (type_variant == _TT_BIT_STRING) + st->size; er.encoded += (type_variant == _TT_BIT_STRING) + st->size;
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0;
return er;
} }
/* /*
...@@ -574,9 +576,7 @@ OCTET_STRING_encode_der(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -574,9 +576,7 @@ OCTET_STRING_encode_der(asn_TYPE_descriptor_t *td, void *sptr,
} }
er.encoded += st->size; er.encoded += st->size;
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0;
return er;
cb_failed: cb_failed:
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
...@@ -639,9 +639,7 @@ OCTET_STRING_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -639,9 +639,7 @@ OCTET_STRING_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
} }
} }
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0;
return er;
cb_failed: cb_failed:
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
...@@ -781,9 +779,7 @@ OCTET_STRING_encode_xer_utf8(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -781,9 +779,7 @@ OCTET_STRING_encode_xer_utf8(asn_TYPE_descriptor_t *td, void *sptr,
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
er.encoded = encoded_len; er.encoded = encoded_len;
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0;
return er;
} }
/* /*
...@@ -1200,6 +1196,99 @@ OCTET_STRING_decode_xer_utf8(asn_codec_ctx_t *opt_codec_ctx, ...@@ -1200,6 +1196,99 @@ OCTET_STRING_decode_xer_utf8(asn_codec_ctx_t *opt_codec_ctx,
OCTET_STRING__convert_entrefs); OCTET_STRING__convert_entrefs);
} }
asn_dec_rval_t
OCTET_STRING_decode_uper(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints,
void **sptr, asn_per_data_t *pd) {
asn_OCTET_STRING_specifics_t *specs = td->specifics
? (asn_OCTET_STRING_specifics_t *)td->specifics
: &asn_DEF_OCTET_STRING_specs;
asn_per_constraint_t *ct = constraints ? &constraints->size
: (td->per_constraints
? &td->per_constraints->size
: &asn_DEF_OCTET_STRING_constraint);
asn_dec_rval_t rval = { RC_OK, 0 };
BIT_STRING_t *st = (BIT_STRING_t *)*sptr;
ssize_t consumed_myself = 0;
int repeat;
int unit_bits = (specs->subvariant != 1) * 7 + 1;
(void)opt_codec_ctx;
/*
* Allocate the string.
*/
if(!st) {
st = (BIT_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
if(!st) RETURN(RC_FAIL);
}
if(ct->flags & APC_EXTENSIBLE) {
int inext = per_get_few_bits(pd, 1);
if(inext < 0) RETURN(RC_FAIL);
if(inext) ct = &asn_DEF_OCTET_STRING_constraint;
consumed_myself = 0;
}
if(ct->effective_bits >= 0
&& (!st->buf || st->size < ct->upper_bound)) {
FREEMEM(st->buf);
if(unit_bits == 1) {
st->size = (ct->upper_bound + 7) >> 3;
} else {
st->size = ct->upper_bound;
}
st->buf = (uint8_t *)MALLOC(st->size + 1);
if(!st->buf) { st->size = 0; RETURN(RC_FAIL); }
}
/* X.691, #16.5: zero-length encoding */
/* X.691, #16.6: short fixed length encoding (up to 2 octets) */
/* X.691, #16.7: long fixed length encoding (up to 64K octets) */
if(ct->effective_bits == 0) {
int ret = per_get_many_bits(pd, st->buf, 0,
unit_bits * ct->upper_bound);
if(ret < 0) RETURN(RC_FAIL);
consumed_myself += unit_bits * ct->upper_bound;
st->buf[st->size] = 0;
if(unit_bits == 1 && (ct->upper_bound & 0x7))
st->bits_unused = 8 - (ct->upper_bound & 0x7);
RETURN(RC_OK);
}
st->size = 0;
do {
ssize_t len_bytes;
ssize_t len_bits;
void *p;
int ret;
/* Get the PER length */
len_bits = uper_get_length(pd, ct->effective_bits, &repeat);
if(len_bits < 0) RETURN(RC_FAIL);
if(unit_bits == 1) {
len_bytes = (len_bits + 7) >> 3;
if(len_bits & 0x7)
st->bits_unused = 8 - (len_bits & 0x7);
/* len_bits be multiple of 16K if repeat is set */
} else {
len_bytes = len_bits;
len_bits = len_bytes << 3;
}
p = REALLOC(st->buf, st->size + len_bytes + 1);
if(!p) RETURN(RC_FAIL);
st->buf = (uint8_t *)p;
ret = per_get_many_bits(pd, &st->buf[st->size], 0, len_bits);
if(ret < 0) RETURN(RC_FAIL);
st->size += len_bytes;
} while(repeat);
st->buf[st->size] = 0; /* nul-terminate */
return rval;
}
int int
OCTET_STRING_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, OCTET_STRING_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
......
...@@ -30,6 +30,7 @@ xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */ ...@@ -30,6 +30,7 @@ xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */
xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */ xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */
xer_type_encoder_f OCTET_STRING_encode_xer; xer_type_encoder_f OCTET_STRING_encode_xer;
xer_type_encoder_f OCTET_STRING_encode_xer_utf8; xer_type_encoder_f OCTET_STRING_encode_xer_utf8;
per_type_decoder_f OCTET_STRING_decode_uper;
/****************************** /******************************
* Handy conversion routines. * * Handy conversion routines. *
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_ObjectDescriptor = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_ObjectDescriptor = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_utf8, OCTET_STRING_decode_xer_utf8,
OCTET_STRING_encode_xer_utf8, OCTET_STRING_encode_xer_utf8,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_ObjectDescriptor_tags, asn_DEF_ObjectDescriptor_tags,
sizeof(asn_DEF_ObjectDescriptor_tags) sizeof(asn_DEF_ObjectDescriptor_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_ObjectDescriptor = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_ObjectDescriptor = {
asn_DEF_ObjectDescriptor_tags, asn_DEF_ObjectDescriptor_tags,
sizeof(asn_DEF_ObjectDescriptor_tags) sizeof(asn_DEF_ObjectDescriptor_tags)
/ sizeof(asn_DEF_ObjectDescriptor_tags[0]), / sizeof(asn_DEF_ObjectDescriptor_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_PrintableString = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_PrintableString = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_utf8, OCTET_STRING_decode_xer_utf8,
OCTET_STRING_encode_xer_utf8, OCTET_STRING_encode_xer_utf8,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_PrintableString_tags, asn_DEF_PrintableString_tags,
sizeof(asn_DEF_PrintableString_tags) sizeof(asn_DEF_PrintableString_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_PrintableString = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_PrintableString = {
asn_DEF_PrintableString_tags, asn_DEF_PrintableString_tags,
sizeof(asn_DEF_PrintableString_tags) sizeof(asn_DEF_PrintableString_tags)
/ sizeof(asn_DEF_PrintableString_tags[0]), / sizeof(asn_DEF_PrintableString_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
This directory contains encoder/decoder code for various encoding rules
Here are the canonical encoder/decoder algorithms that work with the tables (PER, DER, BER, XER) that work with the tables constructed by the compiler.
constructed by the compiler. The compiler itself does not generate code, The compiler itself does not generate much code. It creates parsing tables
it just creates those tables and then copies (links) over these files and then copies (links) over these files which contain generic codecs.
which contain generic algorithms.
...@@ -42,11 +42,13 @@ asn_TYPE_descriptor_t asn_DEF_REAL = { ...@@ -42,11 +42,13 @@ asn_TYPE_descriptor_t asn_DEF_REAL = {
der_encode_primitive, der_encode_primitive,
REAL_decode_xer, REAL_decode_xer,
REAL_encode_xer, REAL_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_REAL_tags, asn_DEF_REAL_tags,
sizeof(asn_DEF_REAL_tags) / sizeof(asn_DEF_REAL_tags[0]), sizeof(asn_DEF_REAL_tags) / sizeof(asn_DEF_REAL_tags[0]),
asn_DEF_REAL_tags, /* Same as above */ asn_DEF_REAL_tags, /* Same as above */
sizeof(asn_DEF_REAL_tags) / sizeof(asn_DEF_REAL_tags[0]), sizeof(asn_DEF_REAL_tags) / sizeof(asn_DEF_REAL_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -257,9 +259,7 @@ REAL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -257,9 +259,7 @@ REAL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = REAL__dump(d, flags & XER_F_CANONICAL, cb, app_key); er.encoded = REAL__dump(d, flags & XER_F_CANONICAL, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED; if(er.encoded < 0) _ASN_ENCODE_FAILED;
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0;
return er;
} }
......
...@@ -25,6 +25,7 @@ asn_TYPE_descriptor_t asn_DEF_RELATIVE_OID = { ...@@ -25,6 +25,7 @@ asn_TYPE_descriptor_t asn_DEF_RELATIVE_OID = {
der_encode_primitive, der_encode_primitive,
RELATIVE_OID_decode_xer, RELATIVE_OID_decode_xer,
RELATIVE_OID_encode_xer, RELATIVE_OID_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_RELATIVE_OID_tags, asn_DEF_RELATIVE_OID_tags,
sizeof(asn_DEF_RELATIVE_OID_tags) sizeof(asn_DEF_RELATIVE_OID_tags)
...@@ -32,6 +33,7 @@ asn_TYPE_descriptor_t asn_DEF_RELATIVE_OID = { ...@@ -32,6 +33,7 @@ asn_TYPE_descriptor_t asn_DEF_RELATIVE_OID = {
asn_DEF_RELATIVE_OID_tags, /* Same as above */ asn_DEF_RELATIVE_OID_tags, /* Same as above */
sizeof(asn_DEF_RELATIVE_OID_tags) sizeof(asn_DEF_RELATIVE_OID_tags)
/ sizeof(asn_DEF_RELATIVE_OID_tags[0]), / sizeof(asn_DEF_RELATIVE_OID_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -156,9 +158,7 @@ RELATIVE_OID_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -156,9 +158,7 @@ RELATIVE_OID_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = RELATIVE_OID__dump_body(st, cb, app_key); er.encoded = RELATIVE_OID__dump_body(st, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED; if(er.encoded < 0) _ASN_ENCODE_FAILED;
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0;
return er;
} }
int int
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_T61String = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_T61String = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex, OCTET_STRING_decode_xer_hex,
OCTET_STRING_encode_xer, OCTET_STRING_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_T61String_tags, asn_DEF_T61String_tags,
sizeof(asn_DEF_T61String_tags) sizeof(asn_DEF_T61String_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_T61String = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_T61String = {
asn_DEF_T61String_tags, asn_DEF_T61String_tags,
sizeof(asn_DEF_T61String_tags) sizeof(asn_DEF_T61String_tags)
/ sizeof(asn_DEF_T61String_tags[0]), / sizeof(asn_DEF_T61String_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_TeletexString = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_TeletexString = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex, OCTET_STRING_decode_xer_hex,
OCTET_STRING_encode_xer, OCTET_STRING_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_TeletexString_tags, asn_DEF_TeletexString_tags,
sizeof(asn_DEF_TeletexString_tags) sizeof(asn_DEF_TeletexString_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_TeletexString = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_TeletexString = {
asn_DEF_TeletexString_tags, asn_DEF_TeletexString_tags,
sizeof(asn_DEF_TeletexString_tags) sizeof(asn_DEF_TeletexString_tags)
/ sizeof(asn_DEF_TeletexString_tags[0]), / sizeof(asn_DEF_TeletexString_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -28,6 +28,7 @@ asn_TYPE_descriptor_t asn_DEF_UTCTime = { ...@@ -28,6 +28,7 @@ asn_TYPE_descriptor_t asn_DEF_UTCTime = {
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_decode_xer_utf8, OCTET_STRING_decode_xer_utf8,
UTCTime_encode_xer, UTCTime_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_UTCTime_tags, asn_DEF_UTCTime_tags,
sizeof(asn_DEF_UTCTime_tags) sizeof(asn_DEF_UTCTime_tags)
...@@ -35,6 +36,7 @@ asn_TYPE_descriptor_t asn_DEF_UTCTime = { ...@@ -35,6 +36,7 @@ asn_TYPE_descriptor_t asn_DEF_UTCTime = {
asn_DEF_UTCTime_tags, asn_DEF_UTCTime_tags,
sizeof(asn_DEF_UTCTime_tags) sizeof(asn_DEF_UTCTime_tags)
/ sizeof(asn_DEF_UTCTime_tags[0]), / sizeof(asn_DEF_UTCTime_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_UTF8String = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_UTF8String = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_utf8, OCTET_STRING_decode_xer_utf8,
OCTET_STRING_encode_xer_utf8, OCTET_STRING_encode_xer_utf8,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_UTF8String_tags, asn_DEF_UTF8String_tags,
sizeof(asn_DEF_UTF8String_tags) sizeof(asn_DEF_UTF8String_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_UTF8String = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_UTF8String = {
asn_DEF_UTF8String_tags, asn_DEF_UTF8String_tags,
sizeof(asn_DEF_UTF8String_tags) sizeof(asn_DEF_UTF8String_tags)
/ sizeof(asn_DEF_UTF8String_tags[0]), / sizeof(asn_DEF_UTF8String_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -23,6 +23,7 @@ asn_TYPE_descriptor_t asn_DEF_UniversalString = { ...@@ -23,6 +23,7 @@ asn_TYPE_descriptor_t asn_DEF_UniversalString = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
UniversalString_decode_xer, /* Convert from UTF-8 */ UniversalString_decode_xer, /* Convert from UTF-8 */
UniversalString_encode_xer, /* Convert into UTF-8 */ UniversalString_encode_xer, /* Convert into UTF-8 */
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_UniversalString_tags, asn_DEF_UniversalString_tags,
sizeof(asn_DEF_UniversalString_tags) sizeof(asn_DEF_UniversalString_tags)
...@@ -30,6 +31,7 @@ asn_TYPE_descriptor_t asn_DEF_UniversalString = { ...@@ -30,6 +31,7 @@ asn_TYPE_descriptor_t asn_DEF_UniversalString = {
asn_DEF_UniversalString_tags, asn_DEF_UniversalString_tags,
sizeof(asn_DEF_UniversalString_tags) sizeof(asn_DEF_UniversalString_tags)
/ sizeof(asn_DEF_UniversalString_tags[0]), / sizeof(asn_DEF_UniversalString_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
...@@ -167,7 +169,7 @@ UniversalString_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -167,7 +169,7 @@ UniversalString_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = UniversalString__dump(st, cb, app_key); er.encoded = UniversalString__dump(st, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED; if(er.encoded < 0) _ASN_ENCODE_FAILED;
return er; _ASN_ENCODED_OK(er);
} }
int int
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_VideotexString = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_VideotexString = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_hex, OCTET_STRING_decode_xer_hex,
OCTET_STRING_encode_xer, OCTET_STRING_encode_xer,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_VideotexString_tags, asn_DEF_VideotexString_tags,
sizeof(asn_DEF_VideotexString_tags) sizeof(asn_DEF_VideotexString_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_VideotexString = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_VideotexString = {
asn_DEF_VideotexString_tags, asn_DEF_VideotexString_tags,
sizeof(asn_DEF_VideotexString_tags) sizeof(asn_DEF_VideotexString_tags)
/ sizeof(asn_DEF_VideotexString_tags[0]), / sizeof(asn_DEF_VideotexString_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_VisibleString = { ...@@ -22,6 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_VisibleString = {
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_decode_xer_utf8, OCTET_STRING_decode_xer_utf8,
OCTET_STRING_encode_xer_utf8, OCTET_STRING_encode_xer_utf8,
0,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_VisibleString_tags, asn_DEF_VisibleString_tags,
sizeof(asn_DEF_VisibleString_tags) sizeof(asn_DEF_VisibleString_tags)
...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_VisibleString = { ...@@ -29,6 +30,7 @@ asn_TYPE_descriptor_t asn_DEF_VisibleString = {
asn_DEF_VisibleString_tags, asn_DEF_VisibleString_tags,
sizeof(asn_DEF_VisibleString_tags) sizeof(asn_DEF_VisibleString_tags)
/ sizeof(asn_DEF_VisibleString_tags[0]), / sizeof(asn_DEF_VisibleString_tags[0]),
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
#include <asn_application.h> #include <asn_application.h>
extern asn_TYPE_descriptor_t asn_DEF; /* ASN.1 type to be decoded */ extern asn_TYPE_descriptor_t asn_DEF; /* ASN.1 type to be decoded */
static asn_TYPE_descriptor_t *pduType = &asn_DEF; #ifdef ASN_PDU_COLLECTION /* Generated by asn1c: -pdu=... */
extern asn_TYPE_descriptor_t *asn_pdu_collection[];
#endif
/* /*
* Open file and parse its contens. * Open file and parse its contens.
...@@ -37,7 +39,8 @@ static int opt_stack; /* -s */ ...@@ -37,7 +39,8 @@ static int opt_stack; /* -s */
/* Input data format selector */ /* Input data format selector */
static enum input_format { static enum input_format {
INP_BER, /* -iber: BER input */ INP_BER, /* -iber: BER input */
INP_XER /* -ixer: XER input */ INP_XER, /* -ixer: XER input */
INP_PER /* -iper: Unaligned PER input */
} iform; /* -i<format> */ } iform; /* -i<format> */
/* Output data format selector */ /* Output data format selector */
...@@ -56,19 +59,26 @@ static enum output_format { ...@@ -56,19 +59,26 @@ static enum output_format {
int int
main(int ac, char **av) { main(int ac, char **av) {
static asn_TYPE_descriptor_t *pduType = &asn_DEF;
ssize_t suggested_bufsize = 8192; /* close or equal to stdio buffer */ ssize_t suggested_bufsize = 8192; /* close or equal to stdio buffer */
int number_of_iterations = 1; int number_of_iterations = 1;
int num; int num;
int ch; int ch;
/* Figure out if Unaligned PER needs to be default */
if(pduType->uper_decoder)
iform = INP_PER;
/* /*
* Pocess the command-line argments. * Pocess the command-line argments.
*/ */
while((ch = getopt(ac, av, "i:o:b:cdn:hs:")) != -1) while((ch = getopt(ac, av, "i:o:b:cdn:p:hs:")) != -1)
switch(ch) { switch(ch) {
case 'i': case 'i':
if(optarg[0] == 'b') { iform = INP_BER; break; } if(optarg[0] == 'b') { iform = INP_BER; break; }
if(optarg[0] == 'x') { iform = INP_XER; break; } if(optarg[0] == 'x') { iform = INP_XER; break; }
if(pduType->uper_decoder
&& optarg[0] == 'p') { iform = INP_PER; break; }
fprintf(stderr, "-i<format>: '%s': improper format selector", fprintf(stderr, "-i<format>: '%s': improper format selector",
optarg); optarg);
exit(EX_UNAVAILABLE); exit(EX_UNAVAILABLE);
...@@ -80,6 +90,21 @@ main(int ac, char **av) { ...@@ -80,6 +90,21 @@ main(int ac, char **av) {
fprintf(stderr, "-o<format>: '%s': improper format selector", fprintf(stderr, "-o<format>: '%s': improper format selector",
optarg); optarg);
exit(EX_UNAVAILABLE); exit(EX_UNAVAILABLE);
case 'p':
#ifdef ASN_PDU_COLLECTION
{
asn_TYPE_descriptor_t **pdu = asn_pdu_collection;
if(optarg[0] < 'A' || optarg[0] > 'Z') {
fprintf(stderr, "Available PDU types:\n");
for(; *pdu; pdu++) printf("%s\n", (*pdu)->name);
exit(0);
}
while(*pdu && strcmp((*pdu)->name, optarg)) pdu++;
if(*pdu) { pduType = *pdu; break; }
}
#endif /* ASN_PDU_COLLECTION */
fprintf(stderr, "-p %s: Unrecognized PDU\n", optarg);
exit(EX_UNAVAILABLE);
case 'b': case 'b':
suggested_bufsize = atoi(optarg); suggested_bufsize = atoi(optarg);
if(suggested_bufsize < 1 if(suggested_bufsize < 1
...@@ -115,21 +140,32 @@ main(int ac, char **av) { ...@@ -115,21 +140,32 @@ main(int ac, char **av) {
break; break;
case 'h': case 'h':
default: default:
fprintf(stderr, "Usage: %s [options] <data.ber> ...\n", av[0]);
fprintf(stderr, "Where options are:\n");
if(pduType->uper_decoder)
fprintf(stderr,
" -iper (I) Input is in Unaligned PER (Packed Encoding Rules)\n");
fprintf(stderr,
" -iber %s Input is in BER (Basic Encoding Rules)\n",
iform == INP_PER ? " " : "(I)");
fprintf(stderr, fprintf(stderr,
"Usage: %s [options] <data.ber> ...\n"
"Where options are:\n"
" -iber (I) Input is in BER (Basic Encoding Rules)\n"
" -ixer Input is in XER (XML Encoding Rules)\n" " -ixer Input is in XER (XML Encoding Rules)\n"
" -oder Output in DER (Distinguished Encoding Rules)\n" " -oder Output in DER (Distinguished Encoding Rules)\n"
" -oxer (O) Output in XER (XML Encoding Rules)\n" " -oxer (O) Output in XER (XML Encoding Rules)\n"
" -otext Output in plain semi-structured text (dump)\n" " -otext Output in plain semi-structured text (dump)\n"
" -onull Verify (decode) input, but do not output\n" " -onull Verify (decode) input, but do not output\n");
#ifdef ASN_PDU_COLLECTION
fprintf(stderr,
" -p <PDU> Specify PDU type to decode\n"
" -p list List available PDUs\n");
#endif /* ASN_PDU_COLLECTION */
fprintf(stderr,
" -b <size> Set the i/o buffer size (default is %ld)\n" " -b <size> Set the i/o buffer size (default is %ld)\n"
" -c Check ASN.1 constraints after decoding\n" " -c Check ASN.1 constraints after decoding\n"
" -d Enable debugging (-dd is even better)\n" " -d Enable debugging (-dd is even better)\n"
" -n <num> Process files <num> times\n" " -n <num> Process files <num> times\n"
" -s <size> Set the stack usage limit\n" " -s <size> Set the stack usage limit\n"
, av[0], (long)suggested_bufsize); , (long)suggested_bufsize);
exit(EX_USAGE); exit(EX_USAGE);
} }
...@@ -210,7 +246,8 @@ main(int ac, char **av) { ...@@ -210,7 +246,8 @@ main(int ac, char **av) {
/* Dump the buffer */ /* Dump the buffer */
static int write_out(const void *buffer, size_t size, void *key) { static int write_out(const void *buffer, size_t size, void *key) {
return (fwrite(buffer, 1, size, key) == size) ? 0 : -1; FILE *fp = (FILE *)key;
return (fwrite(buffer, 1, size, fp) == size) ? 0 : -1;
} }
static char *buffer; static char *buffer;
...@@ -302,6 +339,7 @@ static void *data_decode_from_file(asn_TYPE_descriptor_t *pduType, const char *f ...@@ -302,6 +339,7 @@ static void *data_decode_from_file(asn_TYPE_descriptor_t *pduType, const char *f
rval.consumed = 0; rval.consumed = 0;
while((rd = fread(fbuf, 1, fbuf_size, fp)) || !feof(fp)) { while((rd = fread(fbuf, 1, fbuf_size, fp)) || !feof(fp)) {
asn_per_data_t pd;
char *i_bptr; char *i_bptr;
size_t i_size; size_t i_size;
...@@ -330,6 +368,13 @@ static void *data_decode_from_file(asn_TYPE_descriptor_t *pduType, const char *f ...@@ -330,6 +368,13 @@ static void *data_decode_from_file(asn_TYPE_descriptor_t *pduType, const char *f
rval = xer_decode(opt_codec_ctx, pduType, rval = xer_decode(opt_codec_ctx, pduType,
(void **)&structure, i_bptr, i_size); (void **)&structure, i_bptr, i_size);
break; break;
case INP_PER:
pd.buffer = (uint8_t *)i_bptr;
pd.nboff = 0;
pd.nbits = i_size * 8;
rval = pduType->uper_decoder(opt_codec_ctx, pduType, 0,
(void **)&structure, &pd);
break;
} }
DEBUG("decode(%ld) consumed %ld, code %d", DEBUG("decode(%ld) consumed %ld, code %d",
(long)buf_len, (long)rval.consumed, rval.code); (long)buf_len, (long)rval.consumed, rval.code);
......
/*- /*-
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#ifndef _ASN_CODECS_H_ #ifndef _ASN_CODECS_H_
...@@ -61,6 +62,11 @@ typedef struct asn_enc_rval_s { ...@@ -61,6 +62,11 @@ typedef struct asn_enc_rval_s {
tmp_error.structure_ptr = sptr; \ tmp_error.structure_ptr = sptr; \
return tmp_error; \ return tmp_error; \
} while(0) } while(0)
#define _ASN_ENCODED_OK(rval) do { \
rval.structure_ptr = 0; \
rval.failed_type = 0; \
return rval; \
} while(0)
/* /*
* Type of the return value of the decoding functions (ber_decode, xer_decode) * Type of the return value of the decoding functions (ber_decode, xer_decode)
...@@ -79,6 +85,12 @@ typedef struct asn_dec_rval_s { ...@@ -79,6 +85,12 @@ typedef struct asn_dec_rval_s {
enum asn_dec_rval_code_e code; /* Result code */ enum asn_dec_rval_code_e code; /* Result code */
size_t consumed; /* Number of bytes consumed */ size_t consumed; /* Number of bytes consumed */
} asn_dec_rval_t; } asn_dec_rval_t;
#define _ASN_DECODE_FAILED do { \
asn_dec_rval_t tmp_error; \
tmp_error.code = RC_FAIL; \
tmp_error.consumed = 0; \
return tmp_error; \
} while(0)
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -119,9 +119,7 @@ der_encode_primitive(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -119,9 +119,7 @@ der_encode_primitive(asn_TYPE_descriptor_t *td, void *sptr,
} }
erval.encoded += st->size; erval.encoded += st->size;
erval.structure_ptr = 0; _ASN_ENCODED_OK(erval);
erval.failed_type = 0;
return erval;
} }
void void
......
...@@ -196,7 +196,7 @@ CHOICE_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -196,7 +196,7 @@ CHOICE_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
NEXT_PHASE(ctx); NEXT_PHASE(ctx);
ctx->step = t2m->el_no; ctx->step = t2m->el_no;
break; break;
} else if(specs->extensible == 0) { } else if(specs->ext_start == -1) {
ASN_DEBUG("Unexpected tag %s " ASN_DEBUG("Unexpected tag %s "
"in non-extensible CHOICE %s", "in non-extensible CHOICE %s",
ber_tlv_tag_string(tlv_tag), td->name); ber_tlv_tag_string(tlv_tag), td->name);
...@@ -252,16 +252,16 @@ CHOICE_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -252,16 +252,16 @@ CHOICE_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
memb_ptr = (char *)st + elm->memb_offset; memb_ptr = (char *)st + elm->memb_offset;
memb_ptr2 = &memb_ptr; memb_ptr2 = &memb_ptr;
} }
/* Set presence to be able to free it properly at any time */
_set_present_idx(st, specs->pres_offset,
specs->pres_size, ctx->step + 1);
/* /*
* Invoke the member fetch routine according to member's type * Invoke the member fetch routine according to member's type
*/ */
rval = elm->type->ber_decoder(opt_codec_ctx, elm->type, rval = elm->type->ber_decoder(opt_codec_ctx, elm->type,
memb_ptr2, ptr, LEFT, memb_ptr2, ptr, LEFT, elm->tag_mode);
elm->tag_mode);
switch(rval.code) { switch(rval.code) {
case RC_OK: case RC_OK:
_set_present_idx(st, specs->pres_offset,
specs->pres_size, ctx->step + 1);
break; break;
case RC_WMORE: /* More data expected */ case RC_WMORE: /* More data expected */
if(!SIZE_VIOLATION) { if(!SIZE_VIOLATION) {
...@@ -377,7 +377,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -377,7 +377,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr,
if(present == 0 && td->elements_count == 0) { if(present == 0 && td->elements_count == 0) {
/* The CHOICE is empty?! */ /* The CHOICE is empty?! */
erval.encoded = 0; erval.encoded = 0;
return erval; _ASN_ENCODED_OK(erval);
} }
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
...@@ -391,7 +391,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -391,7 +391,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr,
if(memb_ptr == 0) { if(memb_ptr == 0) {
if(elm->optional) { if(elm->optional) {
erval.encoded = 0; erval.encoded = 0;
return erval; _ASN_ENCODED_OK(erval);
} }
/* Mandatory element absent */ /* Mandatory element absent */
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
...@@ -729,7 +729,7 @@ CHOICE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -729,7 +729,7 @@ CHOICE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
continue; continue;
/* It is expected extension */ /* It is expected extension */
if(specs->extensible) { if(specs->ext_start != -1) {
ASN_DEBUG("Got anticipated extension"); ASN_DEBUG("Got anticipated extension");
/* /*
* Check for (XCT_BOTH or XCT_UNKNOWN_BO) * Check for (XCT_BOTH or XCT_UNKNOWN_BO)
...@@ -810,11 +810,86 @@ CHOICE_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -810,11 +810,86 @@ CHOICE_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
if(!(flags & XER_F_CANONICAL)) _i_ASN_TEXT_INDENT(1, ilevel - 1); if(!(flags & XER_F_CANONICAL)) _i_ASN_TEXT_INDENT(1, ilevel - 1);
return er; _ASN_ENCODED_OK(er);
cb_failed: cb_failed:
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
asn_dec_rval_t
CHOICE_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics;
asn_dec_rval_t rv;
asn_per_constraint_t *ct;
asn_TYPE_member_t *elm; /* CHOICE's element */
void *memb_ptr;
void **memb_ptr2;
void *st = *sptr;
int value;
/*
* Create the target structure if it is not present already.
*/
if(!st) {
st = *sptr = CALLOC(1, specs->struct_size);
if(!st) _ASN_DECODE_FAILED;
}
if(constraints) ct = &constraints->value;
else if(td->per_constraints) ct = &td->per_constraints->value;
else ct = 0;
if(ct && ct->flags & APC_EXTENSIBLE) {
value = per_get_few_bits(pd, 1);
if(value < 0) _ASN_DECODE_FAILED;
if(value) ct = 0; /* Not restricted */
}
if(ct && ct->range_bits >= 0) {
value = per_get_few_bits(pd, ct->range_bits);
if(value < 0) _ASN_DECODE_FAILED;
if(value > ct->upper_bound)
_ASN_DECODE_FAILED;
ASN_DEBUG("CHOICE %s got index %d in range %d",
td->name, value, ct->range_bits);
} else {
if(specs->ext_start == -1)
_ASN_DECODE_FAILED;
value = uper_get_nsnnwn(pd);
if(value < 0) _ASN_DECODE_FAILED;
value += specs->ext_start;
if(value >= td->elements_count)
_ASN_DECODE_FAILED;
ASN_DEBUG("NOT IMPLEMENTED YET");
_ASN_DECODE_FAILED;
}
/* Adjust if canonical order is different from natural order */
if(specs->canonical_order)
value = specs->canonical_order[value];
/* Set presence to be able to free it later */
_set_present_idx(st, specs->pres_offset, specs->pres_size, value + 1);
elm = &td->elements[value];
if(elm->flags & ATF_POINTER) {
/* Member is a pointer to another structure */
memb_ptr2 = (void **)((char *)st + elm->memb_offset);
} else {
memb_ptr = (char *)st + elm->memb_offset;
memb_ptr2 = &memb_ptr;
}
ASN_DEBUG("Discovered CHOICE %s encodes %s", td->name, elm->name);
rv = elm->type->uper_decoder(opt_codec_ctx, elm->type,
elm->per_constraints, memb_ptr2, pd);
if(rv.code != RC_OK)
ASN_DEBUG("Failed to decode %s in %s (CHOICE)",
elm->name, td->name);
return rv;
}
int int
CHOICE_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, CHOICE_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
......
/*- /*-
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#ifndef _CONSTR_CHOICE_H_ #ifndef _CONSTR_CHOICE_H_
...@@ -26,10 +27,13 @@ typedef struct asn_CHOICE_specifics_s { ...@@ -26,10 +27,13 @@ typedef struct asn_CHOICE_specifics_s {
asn_TYPE_tag2member_t *tag2el; asn_TYPE_tag2member_t *tag2el;
int tag2el_count; int tag2el_count;
/* Canonical ordering of CHOICE elements, for PER */
int *canonical_order;
/* /*
* Extensions-related stuff. * Extensions-related stuff.
*/ */
int extensible; /* Whether CHOICE is extensible */ int ext_start; /* First member of extensions, or -1 */
} asn_CHOICE_specifics_t; } asn_CHOICE_specifics_t;
/* /*
...@@ -42,6 +46,7 @@ ber_type_decoder_f CHOICE_decode_ber; ...@@ -42,6 +46,7 @@ ber_type_decoder_f CHOICE_decode_ber;
der_type_encoder_f CHOICE_encode_der; der_type_encoder_f CHOICE_encode_der;
xer_type_decoder_f CHOICE_decode_xer; xer_type_decoder_f CHOICE_decode_xer;
xer_type_encoder_f CHOICE_encode_xer; xer_type_encoder_f CHOICE_encode_xer;
per_type_decoder_f CHOICE_decode_uper;
asn_outmost_tag_f CHOICE_outmost_tag; asn_outmost_tag_f CHOICE_outmost_tag;
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -551,7 +551,7 @@ SEQUENCE_encode_der(asn_TYPE_descriptor_t *td, ...@@ -551,7 +551,7 @@ SEQUENCE_encode_der(asn_TYPE_descriptor_t *td,
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
erval.encoded = computed_size + ret; erval.encoded = computed_size + ret;
if(!cb) return erval; if(!cb) _ASN_ENCODED_OK(erval);
/* /*
* Encode all members. * Encode all members.
...@@ -583,7 +583,7 @@ SEQUENCE_encode_der(asn_TYPE_descriptor_t *td, ...@@ -583,7 +583,7 @@ SEQUENCE_encode_der(asn_TYPE_descriptor_t *td,
*/ */
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
return erval; _ASN_ENCODED_OK(erval);
} }
...@@ -883,7 +883,7 @@ SEQUENCE_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -883,7 +883,7 @@ SEQUENCE_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1); if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
return er; _ASN_ENCODED_OK(er);
cb_failed: cb_failed:
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
...@@ -1014,3 +1014,135 @@ SEQUENCE_constraint(asn_TYPE_descriptor_t *td, const void *sptr, ...@@ -1014,3 +1014,135 @@ SEQUENCE_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
return 0; return 0;
} }
asn_dec_rval_t
SEQUENCE_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_SEQUENCE_specifics_t *specs = (asn_SEQUENCE_specifics_t *)td->specifics;
void *st = *sptr; /* Target structure. */
int extpresent = 0; /* Extension additions are present */
uint8_t *opres; /* Presence of optional root members */
asn_per_data_t opmd;
asn_dec_rval_t rv;
int edx;
(void)constraints;
if(!st) {
st = *sptr = CALLOC(1, specs->struct_size);
if(!st) _ASN_DECODE_FAILED;
}
ASN_DEBUG("Decoding %s as SEQUENCE (UPER)", td->name);
/* Handle extensions */
if(specs->ext_before >= 0) {
extpresent = per_get_few_bits(pd, 1);
if(extpresent < 0) _ASN_DECODE_FAILED;
}
/* Prepare a place and read-in the presence bitmap */
if(specs->roms_count) {
opres = (uint8_t *)MALLOC(((specs->roms_count + 7) >> 3) + 1);
if(!opres) _ASN_DECODE_FAILED;
/* Get the presence map */
if(per_get_many_bits(pd, opres, 0, specs->roms_count)) {
FREEMEM(opres);
_ASN_DECODE_FAILED;
}
opmd.buffer = opres;
opmd.nboff = 0;
opmd.nbits = specs->roms_count;
ASN_DEBUG("Read in presence bitmap for %s of %d bits (%x..)",
td->name, specs->roms_count, *opres);
} else {
opres = 0;
memset(&opmd, 0, sizeof opmd);
}
/*
* Get the sequence ROOT elements.
*/
for(edx = 0; edx < ((specs->ext_before < 0)
? td->elements_count : specs->ext_before + 1); edx++) {
asn_TYPE_member_t *elm = &td->elements[edx];
void *memb_ptr; /* Pointer to the member */
void **memb_ptr2; /* Pointer to that pointer */
/* Fetch the pointer to this member */
if(elm->flags & ATF_POINTER) {
memb_ptr2 = (void **)((char *)st + elm->memb_offset);
} else {
memb_ptr = (char *)st + elm->memb_offset;
memb_ptr2 = &memb_ptr;
}
/* Deal with optionality */
if(elm->optional) {
int present = per_get_few_bits(&opmd, 1);
ASN_DEBUG("Member %s->%s is optional, p=%d (%d->%d)",
td->name, elm->name, present,
(int)opmd.nboff, (int)opmd.nbits);
if(present == 0) {
/* This element is not present */
if(elm->default_value) {
/* Fill-in DEFAULT */
if(elm->default_value(memb_ptr2)) {
FREEMEM(opres);
_ASN_DECODE_FAILED;
}
}
/* The member is just not present */
continue;
}
/* Fall through */
}
/* Fetch the member from the stream */
ASN_DEBUG("Decoding member %s in %s", elm->name, td->name);
rv = elm->type->uper_decoder(opt_codec_ctx, elm->type,
elm->per_constraints, memb_ptr2, pd);
if(rv.code != RC_OK) {
ASN_DEBUG("Failed decode %s in %s",
elm->name, td->name);
FREEMEM(opres);
return rv;
}
}
/*
* Deal with extensions.
*/
if(extpresent) {
ASN_DEBUG("Extensibility for %s: NOT IMPLEMENTED", td->name);
_ASN_DECODE_FAILED;
} else {
for(edx = specs->roms_count; edx < specs->roms_count
+ specs->aoms_count; edx++) {
asn_TYPE_member_t *elm = &td->elements[edx];
void *memb_ptr; /* Pointer to the member */
void **memb_ptr2; /* Pointer to that pointer */
if(!elm->default_value) continue;
/* Fetch the pointer to this member */
if(elm->flags & ATF_POINTER) {
memb_ptr2 = (void **)((char *)st + elm->memb_offset);
} else {
memb_ptr = (char *)st + elm->memb_offset;
memb_ptr2 = &memb_ptr;
}
/* Set default value */
if(elm->default_value(memb_ptr2)) {
FREEMEM(opres);
_ASN_DECODE_FAILED;
}
}
}
rv.consumed = 0;
rv.code = RC_OK;
return rv;
}
...@@ -24,6 +24,14 @@ typedef struct asn_SEQUENCE_specifics_s { ...@@ -24,6 +24,14 @@ typedef struct asn_SEQUENCE_specifics_s {
asn_TYPE_tag2member_t *tag2el; asn_TYPE_tag2member_t *tag2el;
int tag2el_count; int tag2el_count;
/*
* Optional members of the extensions root (roms) or additions (aoms).
* Meaningful for PER.
*/
int *oms; /* Optional MemberS */
int roms_count; /* Root optional members count */
int aoms_count; /* Additions optional members count */
/* /*
* Description of an extensions group. * Description of an extensions group.
*/ */
...@@ -42,6 +50,7 @@ ber_type_decoder_f SEQUENCE_decode_ber; ...@@ -42,6 +50,7 @@ ber_type_decoder_f SEQUENCE_decode_ber;
der_type_encoder_f SEQUENCE_encode_der; der_type_encoder_f SEQUENCE_encode_der;
xer_type_decoder_f SEQUENCE_decode_xer; xer_type_decoder_f SEQUENCE_decode_xer;
xer_type_encoder_f SEQUENCE_encode_xer; xer_type_encoder_f SEQUENCE_encode_xer;
per_type_decoder_f SEQUENCE_decode_uper;
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -51,9 +51,7 @@ SEQUENCE_OF_encode_der(asn_TYPE_descriptor_t *td, void *ptr, ...@@ -51,9 +51,7 @@ SEQUENCE_OF_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
computed_size += encoding_size; computed_size += encoding_size;
if(!cb) { if(!cb) {
erval.encoded = computed_size; erval.encoded = computed_size;
erval.structure_ptr = 0; _ASN_ENCODED_OK(erval);
erval.failed_type = 0;
return erval;
} }
ASN_DEBUG("Encoding members of SEQUENCE OF %s", td->name); ASN_DEBUG("Encoding members of SEQUENCE OF %s", td->name);
...@@ -136,7 +134,7 @@ SEQUENCE_OF_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -136,7 +134,7 @@ SEQUENCE_OF_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1); if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
return er; _ASN_ENCODED_OK(er);
cb_failed: cb_failed:
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
......
...@@ -21,6 +21,7 @@ extern "C" { ...@@ -21,6 +21,7 @@ extern "C" {
#define SEQUENCE_OF_constraint SET_OF_constraint #define SEQUENCE_OF_constraint SET_OF_constraint
#define SEQUENCE_OF_decode_ber SET_OF_decode_ber #define SEQUENCE_OF_decode_ber SET_OF_decode_ber
#define SEQUENCE_OF_decode_xer SET_OF_decode_xer #define SEQUENCE_OF_decode_xer SET_OF_decode_xer
#define SEQUENCE_OF_decode_uper SET_OF_decode_uper
der_type_encoder_f SEQUENCE_OF_encode_der; der_type_encoder_f SEQUENCE_OF_encode_der;
xer_type_encoder_f SEQUENCE_OF_encode_xer; xer_type_encoder_f SEQUENCE_OF_encode_xer;
......
...@@ -536,7 +536,7 @@ SET_encode_der(asn_TYPE_descriptor_t *td, ...@@ -536,7 +536,7 @@ SET_encode_der(asn_TYPE_descriptor_t *td,
if(ret == -1) _ASN_ENCODE_FAILED; if(ret == -1) _ASN_ENCODE_FAILED;
er.encoded = computed_size + ret; er.encoded = computed_size + ret;
if(!cb) return er; if(!cb) _ASN_ENCODED_OK(er);
/* /*
* Encode all members. * Encode all members.
...@@ -570,7 +570,7 @@ SET_encode_der(asn_TYPE_descriptor_t *td, ...@@ -570,7 +570,7 @@ SET_encode_der(asn_TYPE_descriptor_t *td,
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
return er; _ASN_ENCODED_OK(er);
} }
#undef XER_ADVANCE #undef XER_ADVANCE
...@@ -857,7 +857,7 @@ SET_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -857,7 +857,7 @@ SET_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1); if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
return er; _ASN_ENCODED_OK(er);
cb_failed: cb_failed:
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
......
/*- /*-
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h> #include <asn_internal.h>
...@@ -356,7 +357,7 @@ SET_OF_encode_der(asn_TYPE_descriptor_t *td, void *ptr, ...@@ -356,7 +357,7 @@ SET_OF_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
if(!cb) { if(!cb) {
erval.encoded = computed_size; erval.encoded = computed_size;
return erval; _ASN_ENCODED_OK(erval);
} }
/* /*
...@@ -448,7 +449,7 @@ SET_OF_encode_der(asn_TYPE_descriptor_t *td, void *ptr, ...@@ -448,7 +449,7 @@ SET_OF_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
erval.encoded = computed_size; erval.encoded = computed_size;
} }
return erval; _ASN_ENCODED_OK(erval);
} }
#undef XER_ADVANCE #undef XER_ADVANCE
...@@ -748,7 +749,7 @@ cleanup: ...@@ -748,7 +749,7 @@ cleanup:
} }
free(encs); free(encs);
} }
return er; _ASN_ENCODED_OK(er);
} }
int int
...@@ -850,3 +851,88 @@ SET_OF_constraint(asn_TYPE_descriptor_t *td, const void *sptr, ...@@ -850,3 +851,88 @@ SET_OF_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
return 0; return 0;
} }
asn_dec_rval_t
SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_dec_rval_t rv;
asn_SET_OF_specifics_t *specs = (asn_SET_OF_specifics_t *)td->specifics;
asn_TYPE_member_t *elm = td->elements; /* Single one */
void *st = *sptr;
asn_anonymous_set_ *list;
asn_per_constraint_t *ct;
int repeat = 0;
ssize_t nelems;
/*
* Create the target structure if it is not present already.
*/
if(!st) {
st = *sptr = CALLOC(1, specs->struct_size);
if(!st) _ASN_DECODE_FAILED;
}
list = _A_SET_FROM_VOID(st);
/* Figure out which constraints to use */
if(constraints) ct = &constraints->size;
else if(td->per_constraints) ct = &td->per_constraints->size;
else ct = 0;
if(ct && ct->flags & APC_EXTENSIBLE) {
int value = per_get_few_bits(pd, 1);
if(value < 0) _ASN_DECODE_FAILED;
if(value) ct = 0; /* Not restricted! */
}
if(ct && ct->effective_bits >= 0) {
/* X.691, #19.5: No length determinant */
nelems = per_get_few_bits(pd, ct->effective_bits);
ASN_DEBUG("Preparing to fetch %ld+%ld elements from %s",
(long)nelems, ct->lower_bound, td->name);
if(nelems < 0) _ASN_DECODE_FAILED;
nelems += ct->lower_bound;
} else {
nelems = -1;
}
do {
int i;
if(nelems < 0) {
nelems = uper_get_length(pd,
ct ? ct->effective_bits : -1, &repeat);
ASN_DEBUG("Got to decode %d elements (eff %d)",
nelems, ct ? ct->effective_bits : -1);
if(nelems < 0) _ASN_DECODE_FAILED;
}
for(i = 0; i < nelems; i++) {
void *ptr = 0;
ASN_DEBUG("SET OF %s decoding", elm->type->name);
rv = elm->type->uper_decoder(opt_codec_ctx, elm->type,
elm->per_constraints, &ptr, pd);
ASN_DEBUG("%s SET OF %s decoded %d, %p",
td->name, elm->type->name, rv.code, ptr);
if(rv.code == RC_OK) {
if(ASN_SET_ADD(list, ptr) == 0)
continue;
ASN_DEBUG("Failed to add element into %s",
td->name);
/* Fall through */
} else {
ASN_DEBUG("Failed decoding %s of %s (SET OF)",
elm->type->name, td->name);
}
if(ptr) elm->type->free_struct(elm->type, ptr, 0);
_ASN_DECODE_FAILED;
}
nelems = -1; /* Allow uper_get_length() */
} while(repeat);
ASN_DEBUG("Decoded %s as SET OF", td->name);
rv.code = RC_OK;
rv.consumed = 0;
return rv;
}
...@@ -32,6 +32,7 @@ ber_type_decoder_f SET_OF_decode_ber; ...@@ -32,6 +32,7 @@ ber_type_decoder_f SET_OF_decode_ber;
der_type_encoder_f SET_OF_encode_der; der_type_encoder_f SET_OF_encode_der;
xer_type_decoder_f SET_OF_decode_xer; xer_type_decoder_f SET_OF_decode_xer;
xer_type_encoder_f SET_OF_encode_xer; xer_type_encoder_f SET_OF_encode_xer;
per_type_decoder_f SET_OF_decode_uper;
#ifdef __cplusplus #ifdef __cplusplus
} }
......
/*- /*-
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
/* /*
...@@ -38,6 +39,7 @@ typedef struct asn_struct_ctx_s { ...@@ -38,6 +39,7 @@ typedef struct asn_struct_ctx_s {
#include <der_encoder.h> /* Distinguished Encoding Rules encoder */ #include <der_encoder.h> /* Distinguished Encoding Rules encoder */
#include <xer_decoder.h> /* Decoder of XER (XML, text) */ #include <xer_decoder.h> /* Decoder of XER (XML, text) */
#include <xer_encoder.h> /* Encoder into XER (XML, text) */ #include <xer_encoder.h> /* Encoder into XER (XML, text) */
#include <per_decoder.h> /* Packet Encoding Rules decoder */
#include <constraints.h> /* Subtype constraints support */ #include <constraints.h> /* Subtype constraints support */
/* /*
...@@ -91,6 +93,7 @@ typedef struct asn_TYPE_descriptor_s { ...@@ -91,6 +93,7 @@ typedef struct asn_TYPE_descriptor_s {
der_type_encoder_f *der_encoder; /* Canonical DER encoder */ der_type_encoder_f *der_encoder; /* Canonical DER encoder */
xer_type_decoder_f *xer_decoder; /* Generic XER decoder */ xer_type_decoder_f *xer_decoder; /* Generic XER decoder */
xer_type_encoder_f *xer_encoder; /* [Canonical] XER encoder */ xer_type_encoder_f *xer_encoder; /* [Canonical] XER encoder */
per_type_decoder_f *uper_decoder; /* Unaligned PER decoder */
/*********************************************************************** /***********************************************************************
* Internally useful members. Not to be used by applications directly. * * Internally useful members. Not to be used by applications directly. *
...@@ -105,6 +108,8 @@ typedef struct asn_TYPE_descriptor_s { ...@@ -105,6 +108,8 @@ typedef struct asn_TYPE_descriptor_s {
ber_tlv_tag_t *all_tags;/* Every tag for BER/containment */ ber_tlv_tag_t *all_tags;/* Every tag for BER/containment */
int all_tags_count; /* Number of tags */ int all_tags_count; /* Number of tags */
asn_per_constraints_t *per_constraints; /* PER compiled constraints */
/* /*
* An ASN.1 production type members (members of SEQUENCE, SET, CHOICE). * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE).
*/ */
...@@ -135,6 +140,8 @@ typedef struct asn_TYPE_member_s { ...@@ -135,6 +140,8 @@ typedef struct asn_TYPE_member_s {
int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */ int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */
asn_TYPE_descriptor_t *type; /* Member type descriptor */ asn_TYPE_descriptor_t *type; /* Member type descriptor */
asn_constr_check_f *memb_constraints; /* Constraints validator */ asn_constr_check_f *memb_constraints; /* Constraints validator */
asn_per_constraints_t *per_constraints; /* PER compiled constraints */
int (*default_value)(void **sptr); /* DEFAULT <value> */
char *name; /* ASN.1 identifier of the element */ char *name; /* ASN.1 identifier of the element */
} asn_TYPE_member_t; } asn_TYPE_member_t;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
ANY.h ANY.c ANY.h ANY.c
BMPString.h BMPString.c UTF8String.h BMPString.h BMPString.c UTF8String.h
BOOLEAN.h BOOLEAN.c BOOLEAN.h BOOLEAN.c
ENUMERATED.h ENUMERATED.c INTEGER.h ENUMERATED.h ENUMERATED.c INTEGER.h NativeEnumerated.h
GeneralString.h GeneralString.c GeneralString.h GeneralString.c
GeneralizedTime.h GeneralizedTime.c GeneralizedTime.h GeneralizedTime.c
GraphicString.h GraphicString.c GraphicString.h GraphicString.c
...@@ -58,4 +58,10 @@ constraints.h constraints.c # Subtype constraints support ...@@ -58,4 +58,10 @@ constraints.h constraints.c # Subtype constraints support
xer_support.h xer_support.c # XML parsing xer_support.h xer_support.c # XML parsing
xer_decoder.h xer_decoder.c # XER decoding support xer_decoder.h xer_decoder.c # XER decoding support
xer_encoder.h xer_encoder.c # XER encoding support xer_encoder.h xer_encoder.c # XER encoding support
per_decoder.h per_support.h # PER declarations, just in case
#asn-decoder-template.c # Template for quick decoder creation #asn-decoder-template.c # Template for quick decoder creation
CODEC-PER: # THIS IS A SPECIAL SECTION
per_support.h per_support.c # PER parsing
per_decoder.h per_decoder.c # PER decoding support
#include <asn_application.h>
#include <per_decoder.h>
/*-
* Copyright (c) 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef _PER_DECODER_H_
#define _PER_DECODER_H_
#include <asn_application.h>
#include <per_support.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Pre-computed PER constraints.
*/
enum asn_per_constraint_flags {
APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */
APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */
APC_CONSTRAINED = 0x2, /* Fully constrained */
APC_EXTENSIBLE = 0x4 /* May have extension */
};
typedef struct asn_per_constraint_s {
enum asn_per_constraint_flags flags;
int range_bits; /* Full number of bits in the range */
int effective_bits; /* Effective bits */
long lower_bound; /* "lb" value */
long upper_bound; /* "ub" value */
} asn_per_constraint_t;
typedef struct asn_per_constraints_s {
asn_per_constraint_t value;
asn_per_constraint_t size;
} asn_per_constraints_t;
struct asn_TYPE_descriptor_s; /* Forward declaration */
/*
* Type of the type-specific PER decoder function.
*/
typedef asn_dec_rval_t (per_type_decoder_f)(asn_codec_ctx_t *opt_codec_ctx,
struct asn_TYPE_descriptor_s *type_descriptor,
asn_per_constraints_t *constraints,
void **struct_ptr,
asn_per_data_t *per_data
);
#ifdef __cplusplus
}
#endif
#endif /* _PER_DECODER_H_ */
/*
* Copyright (c) 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_system.h>
#include <per_support.h>
/*
* Extract a small number of bits (<= 24) from the specified PER data pointer.
*/
int32_t
per_get_few_bits(asn_per_data_t *pd, int nbits) {
size_t off; /* Next after last bit offset */
uint32_t accum;
uint8_t *buf;
if(nbits < 0 || pd->nboff + nbits > pd->nbits)
return -1;
if(nbits == 0)
return 0;
/*
* Normalize position indicator.
*/
if(pd->nboff >= 8) {
pd->buffer += (pd->nboff >> 3);
pd->nbits -= (pd->nboff & ~0x07);
pd->nboff &= 0x07;
}
off = (pd->nboff += nbits);
buf = pd->buffer;
/*
* Extract specified number of bits.
*/
if(off <= 8)
accum = (buf[0]) >> (8 - off);
else if(off <= 16)
accum = ((buf[0] << 8) + buf[1]) >> (16 - off);
else if(off <= 24)
accum = ((buf[0] << 16) + (buf[1] << 8) + buf[2]) >> (24 - off);
else if(off <= 31)
accum = ((buf[0] << 24) + (buf[1] << 16)
+ (buf[2] << 8) + (buf[3])) >> (32 - off);
else {
pd->nboff -= nbits; /* Oops, revert back */
return -1;
}
return (accum & ((1 << nbits) - 1));
}
/*
* Extract a large number of bits from the specified PER data pointer.
*/
int
per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int alright, int nbits) {
int32_t value;
if(alright && (nbits & 7)) {
/* Perform right alignment of a first few bits */
value = per_get_few_bits(pd, nbits & 0x07);
if(value < 0) return -1;
*dst++ = value; /* value is already right-aligned */
nbits &= ~7;
}
while(nbits) {
if(nbits >= 24) {
value = per_get_few_bits(pd, 24);
if(value < 0) return -1;
*(dst++) = value >> 16;
*(dst++) = value >> 8;
*(dst++) = value;
nbits -= 24;
} else {
value = per_get_few_bits(pd, nbits);
if(value < 0) return -1;
if(nbits & 7) { /* implies alright */
value <<= 8 - (nbits & 7),
nbits += 8 - (nbits & 7);
if(nbits > 24)
*dst++ = value >> 24;
}
if(nbits > 16)
*dst++ = value >> 16;
if(nbits > 8)
*dst++ = value >> 8;
*dst++ = value;
break;
}
}
return 0;
}
/*
* Get the length "n" from the stream.
*/
ssize_t
uper_get_length(asn_per_data_t *pd, int ebits, int *repeat) {
ssize_t value;
*repeat = 0;
if(ebits >= 0) return per_get_few_bits(pd, ebits);
value = per_get_few_bits(pd, 8);
if(value < 0) return -1;
if((value & 128) == 0) /* #10.9.3.6 */
return (value & 0x7F);
if((value & 64) == 0) { /* #10.9.3.7 */
value = ((value & 63) << 8) | per_get_few_bits(pd, 8);
if(value < 0) return -1;
return value;
}
value &= 63; /* this is "m" from X.691, #10.9.3.8 */
if(value < 1 || value > 4)
return -1;
*repeat = 1;
return (16384 * value);
}
/*
* Get the normally small non-negative whole number.
* X.691, #10.6
*/
ssize_t
uper_get_nsnnwn(asn_per_data_t *pd) {
ssize_t value;
value = per_get_few_bits(pd, 7);
if(value & 64) { /* implicit (value < 0) */
value &= 63;
value <<= 2;
value |= per_get_few_bits(pd, 2);
if(value & 128) /* implicit (value < 0) */
return -1;
if(value == 0)
return 0;
if(value >= 3)
return -1;
value = per_get_few_bits(pd, 8 * value);
return value;
}
return value;
}
/*
* Copyright (c) 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef _PER_SUPPORT_H_
#define _PER_SUPPORT_H_
#include <asn_system.h> /* Platform-specific types */
#ifdef __cplusplus
extern "C" {
#endif
/*
* This structure describes a position inside a PER bit stream.
*/
typedef struct asn_per_data_s {
uint8_t *buffer; /* Pointer to the octet stream */
size_t nboff; /* Bit offset to the meaningful bit */
size_t nbits; /* Number of bits in the stream */
} asn_per_data_t;
/*
* Extract a small number of bits (<= 24) from the specified PER data pointer.
* This function returns -1 if the specified number of bits could not be
* extracted due to EOD or other conditions.
*/
int32_t per_get_few_bits(asn_per_data_t *per_data, int get_nbits);
/*
* Extract a large number of bits from the specified PER data pointer.
* This function returns -1 if the specified number of bits could not be
* extracted due to EOD or other conditions.
*/
int per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int right_align,
int get_nbits);
/*
* Get the length "n" from the Unaligned PER stream.
*/
ssize_t uper_get_length(asn_per_data_t *pd,
int effective_bound_bits,
int *repeat);
/*
* Get the normally small non-negative whole number.
*/
ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
#ifdef __cplusplus
}
#endif
#endif /* _PER_SUPPORT_H_ */
...@@ -10,7 +10,8 @@ check_PROGRAMS = \ ...@@ -10,7 +10,8 @@ check_PROGRAMS = \
check-UTCTime \ check-UTCTime \
check-INTEGER \ check-INTEGER \
check-REAL \ check-REAL \
check-XER check-XER \
check-PER
LDADD = -lm LDADD = -lm
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# PARTICULAR PURPOSE. # PARTICULAR PURPOSE.
@SET_MAKE@ @SET_MAKE@
SOURCES = check-GeneralizedTime.c check-INTEGER.c check-OCTET_STRING.c check-OIDs.c check-REAL.c check-UTCTime.c check-UTF8String.c check-XER.c check-ber_tlv_tag.c check-length.c SOURCES = check-GeneralizedTime.c check-INTEGER.c check-OCTET_STRING.c check-OIDs.c check-PER.c check-REAL.c check-UTCTime.c check-UTF8String.c check-XER.c check-ber_tlv_tag.c check-length.c
srcdir = @srcdir@ srcdir = @srcdir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
...@@ -40,7 +40,7 @@ check_PROGRAMS = check-ber_tlv_tag$(EXEEXT) check-length$(EXEEXT) \ ...@@ -40,7 +40,7 @@ check_PROGRAMS = check-ber_tlv_tag$(EXEEXT) check-length$(EXEEXT) \
check-OIDs$(EXEEXT) check-GeneralizedTime$(EXEEXT) \ check-OIDs$(EXEEXT) check-GeneralizedTime$(EXEEXT) \
check-OCTET_STRING$(EXEEXT) check-UTF8String$(EXEEXT) \ check-OCTET_STRING$(EXEEXT) check-UTF8String$(EXEEXT) \
check-UTCTime$(EXEEXT) check-INTEGER$(EXEEXT) \ check-UTCTime$(EXEEXT) check-INTEGER$(EXEEXT) \
check-REAL$(EXEEXT) check-XER$(EXEEXT) check-REAL$(EXEEXT) check-XER$(EXEEXT) check-PER$(EXEEXT)
subdir = skeletons/tests subdir = skeletons/tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
...@@ -66,6 +66,10 @@ check_OIDs_SOURCES = check-OIDs.c ...@@ -66,6 +66,10 @@ check_OIDs_SOURCES = check-OIDs.c
check_OIDs_OBJECTS = check-OIDs.$(OBJEXT) check_OIDs_OBJECTS = check-OIDs.$(OBJEXT)
check_OIDs_LDADD = $(LDADD) check_OIDs_LDADD = $(LDADD)
check_OIDs_DEPENDENCIES = check_OIDs_DEPENDENCIES =
check_PER_SOURCES = check-PER.c
check_PER_OBJECTS = check-PER.$(OBJEXT)
check_PER_LDADD = $(LDADD)
check_PER_DEPENDENCIES =
check_REAL_SOURCES = check-REAL.c check_REAL_SOURCES = check-REAL.c
check_REAL_OBJECTS = check-REAL.$(OBJEXT) check_REAL_OBJECTS = check-REAL.$(OBJEXT)
check_REAL_LDADD = $(LDADD) check_REAL_LDADD = $(LDADD)
...@@ -96,7 +100,7 @@ am__depfiles_maybe = depfiles ...@@ -96,7 +100,7 @@ am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/check-GeneralizedTime.Po \ @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/check-GeneralizedTime.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/check-INTEGER.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check-INTEGER.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/check-OCTET_STRING.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check-OCTET_STRING.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/check-OIDs.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check-OIDs.Po ./$(DEPDIR)/check-PER.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/check-REAL.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check-REAL.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/check-UTCTime.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check-UTCTime.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/check-UTF8String.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check-UTF8String.Po \
...@@ -112,12 +116,13 @@ CCLD = $(CC) ...@@ -112,12 +116,13 @@ CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@ $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = check-GeneralizedTime.c check-INTEGER.c check-OCTET_STRING.c \ SOURCES = check-GeneralizedTime.c check-INTEGER.c check-OCTET_STRING.c \
check-OIDs.c check-REAL.c check-UTCTime.c check-UTF8String.c \ check-OIDs.c check-PER.c check-REAL.c check-UTCTime.c \
check-XER.c check-ber_tlv_tag.c check-length.c
DIST_SOURCES = check-GeneralizedTime.c check-INTEGER.c \
check-OCTET_STRING.c check-OIDs.c check-REAL.c check-UTCTime.c \
check-UTF8String.c check-XER.c check-ber_tlv_tag.c \ check-UTF8String.c check-XER.c check-ber_tlv_tag.c \
check-length.c check-length.c
DIST_SOURCES = check-GeneralizedTime.c check-INTEGER.c \
check-OCTET_STRING.c check-OIDs.c check-PER.c check-REAL.c \
check-UTCTime.c check-UTF8String.c check-XER.c \
check-ber_tlv_tag.c check-length.c
ETAGS = etags ETAGS = etags
CTAGS = ctags CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
...@@ -285,6 +290,9 @@ check-OCTET_STRING$(EXEEXT): $(check_OCTET_STRING_OBJECTS) $(check_OCTET_STRING_ ...@@ -285,6 +290,9 @@ check-OCTET_STRING$(EXEEXT): $(check_OCTET_STRING_OBJECTS) $(check_OCTET_STRING_
check-OIDs$(EXEEXT): $(check_OIDs_OBJECTS) $(check_OIDs_DEPENDENCIES) check-OIDs$(EXEEXT): $(check_OIDs_OBJECTS) $(check_OIDs_DEPENDENCIES)
@rm -f check-OIDs$(EXEEXT) @rm -f check-OIDs$(EXEEXT)
$(LINK) $(check_OIDs_LDFLAGS) $(check_OIDs_OBJECTS) $(check_OIDs_LDADD) $(LIBS) $(LINK) $(check_OIDs_LDFLAGS) $(check_OIDs_OBJECTS) $(check_OIDs_LDADD) $(LIBS)
check-PER$(EXEEXT): $(check_PER_OBJECTS) $(check_PER_DEPENDENCIES)
@rm -f check-PER$(EXEEXT)
$(LINK) $(check_PER_LDFLAGS) $(check_PER_OBJECTS) $(check_PER_LDADD) $(LIBS)
check-REAL$(EXEEXT): $(check_REAL_OBJECTS) $(check_REAL_DEPENDENCIES) check-REAL$(EXEEXT): $(check_REAL_OBJECTS) $(check_REAL_DEPENDENCIES)
@rm -f check-REAL$(EXEEXT) @rm -f check-REAL$(EXEEXT)
$(LINK) $(check_REAL_LDFLAGS) $(check_REAL_OBJECTS) $(check_REAL_LDADD) $(LIBS) $(LINK) $(check_REAL_LDFLAGS) $(check_REAL_OBJECTS) $(check_REAL_LDADD) $(LIBS)
...@@ -314,6 +322,7 @@ distclean-compile: ...@@ -314,6 +322,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-INTEGER.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-INTEGER.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-OCTET_STRING.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-OCTET_STRING.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-OIDs.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-OIDs.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-PER.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-REAL.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-REAL.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-UTCTime.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-UTCTime.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-UTF8String.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-UTF8String.Po@am__quote@
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <der_encoder.c> #include <der_encoder.c>
#include <xer_decoder.c> #include <xer_decoder.c>
#include <xer_support.c> #include <xer_support.c>
#include <per_support.c>
#include <constraints.c> #include <constraints.c>
static char *shared_scratch_start; static char *shared_scratch_start;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <BIT_STRING.c> #include <BIT_STRING.c>
#include <xer_decoder.c> #include <xer_decoder.c>
#include <xer_support.c> #include <xer_support.c>
#include <per_support.c>
#include <ber_decoder.c> #include <ber_decoder.c>
#include <ber_tlv_length.c> #include <ber_tlv_length.c>
#include <ber_tlv_tag.c> #include <ber_tlv_tag.c>
......
#include <per_support.c>
#include <assert.h>
int
main() {
uint8_t buf[] = { 0xB7, 0x19, 0x2F, 0xEE, 0xAD };
uint8_t tmpbuf[10];
int32_t z;
asn_per_data_t pos;
pos.buffer = buf;
pos.nboff = 0;
pos.nbits = sizeof(buf) * 8;
z = per_get_few_bits(&pos, 32);
assert(z == -1);
z = per_get_few_bits(&pos, 0);
assert(z == 0);
assert(pos.nboff == 0);
z = per_get_few_bits(&pos, 1);
assert(z == 1);
assert(pos.nboff == 1);
z = per_get_few_bits(&pos, 2);
assert(z == 1);
assert(pos.nboff == 3);
z = per_get_few_bits(&pos, 2);
assert(z == 2);
assert(pos.nboff == 5);
z = per_get_few_bits(&pos, 3);
assert(z == 7);
assert(pos.nboff == 8);
assert(pos.nbits == sizeof(buf) * 8);
z = per_get_few_bits(&pos, 8);
assert(z == 0x19);
assert(pos.nboff == 8);
assert(pos.nbits == (sizeof(buf) - 1) * 8);
z = per_get_few_bits(&pos, 1);
assert(z == 0);
assert(pos.nboff == 1);
assert(pos.nbits == (sizeof(buf) - 2) * 8);
z = per_get_few_bits(&pos, 3);
assert(z == 2);
assert(pos.nboff == 4);
assert(pos.nbits == (sizeof(buf) - 2) * 8);
z = per_get_few_bits(&pos, 8);
assert(z == 254);
assert(pos.nboff == 12);
pos.buffer = buf;
pos.nboff = 2;
pos.nbits = sizeof(buf) * 8;
z = per_get_few_bits(&pos, 24);
assert(z == 14443711);
pos.buffer = buf;
pos.nboff = 0;
pos.nbits = sizeof(buf) * 8;
z = per_get_many_bits(&pos, tmpbuf, 0, sizeof(buf) * 8);
assert(z == 0);
assert(buf[0] == tmpbuf[0]);
assert(buf[1] == tmpbuf[1]);
assert(buf[2] == tmpbuf[2]);
assert(buf[3] == tmpbuf[3]);
assert(buf[4] == tmpbuf[4]);
pos.buffer = buf;
pos.nboff = 1;
pos.nbits = sizeof(buf) * 8;
z = per_get_many_bits(&pos, tmpbuf, 0, sizeof(buf) * 8);
assert(z == -1);
pos.buffer = buf;
pos.nboff = 1;
pos.nbits = sizeof(buf) * 8;
z = per_get_many_bits(&pos, tmpbuf, 0, sizeof(buf) * 8 - 1);
assert(z == 0);
assert(tmpbuf[0] == 110);
assert(tmpbuf[1] == 50);
assert(tmpbuf[2] == 95);
assert(tmpbuf[3] == 221);
assert(tmpbuf[4] == 90);
pos.buffer = buf;
pos.nboff = 1;
pos.nbits = sizeof(buf) * 8;
z = per_get_many_bits(&pos, tmpbuf, 1, sizeof(buf) * 8 - 1);
assert(z == 0);
assert(tmpbuf[0] == 55);
assert(tmpbuf[0] != buf[0]);
assert(tmpbuf[1] == buf[1]);
assert(tmpbuf[2] == buf[2]);
assert(tmpbuf[3] == buf[3]);
assert(tmpbuf[4] == buf[4]);
return 0;
}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <der_encoder.c> #include <der_encoder.c>
#include <xer_decoder.c> #include <xer_decoder.c>
#include <xer_support.c> #include <xer_support.c>
#include <per_support.c>
#include <constraints.c> #include <constraints.c>
#include <sys/time.h> #include <sys/time.h>
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <der_encoder.c> #include <der_encoder.c>
#include <xer_decoder.c> #include <xer_decoder.c>
#include <xer_support.c> #include <xer_support.c>
#include <per_support.c>
#include <constraints.c> #include <constraints.c>
#undef ADVANCE #undef ADVANCE
#undef RETURN #undef RETURN
......
...@@ -32,9 +32,7 @@ xer_encode(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -32,9 +32,7 @@ xer_encode(asn_TYPE_descriptor_t *td, void *sptr,
er.encoded = 4 + xcan + (2 * mlen) + tmper.encoded; er.encoded = 4 + xcan + (2 * mlen) + tmper.encoded;
er.structure_ptr = 0; _ASN_ENCODED_OK(er);
er.failed_type = 0;
return er;
cb_failed: cb_failed:
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
} }
......
...@@ -4,11 +4,7 @@ ...@@ -4,11 +4,7 @@
* All rights reserved. * All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <errno.h> #include <asn_system.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <xer_support.h> #include <xer_support.h>
/* Parser states */ /* Parser states */
......
This diff is collapsed.
...@@ -49,6 +49,8 @@ static asn_TYPE_member_t asn_MBR_T_1[] = { ...@@ -49,6 +49,8 @@ static asn_TYPE_member_t asn_MBR_T_1[] = {
.tag_mode = -1, /* IMPLICIT tag at current level */ .tag_mode = -1, /* IMPLICIT tag at current level */
.type = &asn_DEF_INTEGER, .type = &asn_DEF_INTEGER,
.memb_constraints = 0, /* Defer constraints checking to the member type */ .memb_constraints = 0, /* Defer constraints checking to the member type */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.name = "i" .name = "i"
}, },
{ ATF_NOFLAGS, 0, offsetof(struct T, s), { ATF_NOFLAGS, 0, offsetof(struct T, s),
...@@ -56,6 +58,8 @@ static asn_TYPE_member_t asn_MBR_T_1[] = { ...@@ -56,6 +58,8 @@ static asn_TYPE_member_t asn_MBR_T_1[] = {
.tag_mode = 0, .tag_mode = 0,
.type = &asn_DEF_IA5String, .type = &asn_DEF_IA5String,
.memb_constraints = 0, /* Defer constraints checking to the member type */ .memb_constraints = 0, /* Defer constraints checking to the member type */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.name = "s" .name = "s"
}, },
{ ATF_POINTER, 1, offsetof(struct T, b), { ATF_POINTER, 1, offsetof(struct T, b),
...@@ -63,30 +67,32 @@ static asn_TYPE_member_t asn_MBR_T_1[] = { ...@@ -63,30 +67,32 @@ static asn_TYPE_member_t asn_MBR_T_1[] = {
.tag_mode = -1, /* IMPLICIT tag at current level */ .tag_mode = -1, /* IMPLICIT tag at current level */
.type = &asn_DEF_BOOLEAN, .type = &asn_DEF_BOOLEAN,
.memb_constraints = 0, /* Defer constraints checking to the member type */ .memb_constraints = 0, /* Defer constraints checking to the member type */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.name = "b" .name = "b"
}, },
}; };
static ber_tlv_tag_t asn_DEF_T_1_tags[] = { static ber_tlv_tag_t asn_DEF_T_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (17 << 2)) (ASN_TAG_CLASS_UNIVERSAL | (17 << 2))
}; };
static asn_TYPE_tag2member_t asn_MAP_T_1_tag2el[] = { static asn_TYPE_tag2member_t asn_MAP_T_tag2el_1[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)), 1, 0, 0 }, /* s at 16 */ { (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)), 1, 0, 0 }, /* s at 16 */
{ (ASN_TAG_CLASS_APPLICATION | (3 << 2)), 0, 0, 0 }, /* i at 15 */ { (ASN_TAG_CLASS_APPLICATION | (3 << 2)), 0, 0, 0 }, /* i at 15 */
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* b at 18 */ { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* b at 18 */
}; };
static uint8_t asn_MAP_T_1_mmap[(3 + (8 * sizeof(unsigned int)) - 1) / 8] = { static uint8_t asn_MAP_T_mmap_1[(3 + (8 * sizeof(unsigned int)) - 1) / 8] = {
(1 << 7) | (1 << 6) | (0 << 5) (1 << 7) | (1 << 6) | (0 << 5)
}; };
static asn_SET_specifics_t asn_SPC_T_1_specs = { static asn_SET_specifics_t asn_SPC_T_specs_1 = {
sizeof(struct T), sizeof(struct T),
offsetof(struct T, _asn_ctx), offsetof(struct T, _asn_ctx),
offsetof(struct T, _presence_map), offsetof(struct T, _presence_map),
asn_MAP_T_1_tag2el, asn_MAP_T_tag2el_1,
3, /* Count of tags in the map */ 3, /* Count of tags in the map */
asn_MAP_T_1_tag2el, /* Same as above */ asn_MAP_T_tag2el_1, /* Same as above */
3, /* Count of tags in the CXER map */ 3, /* Count of tags in the CXER map */
1, /* Whether extensible */ 1, /* Whether extensible */
(unsigned int *)asn_MAP_T_1_mmap /* Mandatory elements map */ (unsigned int *)asn_MAP_T_mmap_1 /* Mandatory elements map */
}; };
asn_TYPE_descriptor_t asn_DEF_T = { asn_TYPE_descriptor_t asn_DEF_T = {
"T", "T",
...@@ -98,15 +104,17 @@ asn_TYPE_descriptor_t asn_DEF_T = { ...@@ -98,15 +104,17 @@ asn_TYPE_descriptor_t asn_DEF_T = {
SET_encode_der, SET_encode_der,
SET_decode_xer, SET_decode_xer,
SET_encode_xer, SET_encode_xer,
0, /* No PER decoder, -gen-PER to enable */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_T_1_tags, asn_DEF_T_tags_1,
sizeof(asn_DEF_T_1_tags) sizeof(asn_DEF_T_tags_1)
/sizeof(asn_DEF_T_1_tags[0]), /* 1 */ /sizeof(asn_DEF_T_tags_1[0]), /* 1 */
asn_DEF_T_1_tags, /* Same as above */ asn_DEF_T_tags_1, /* Same as above */
sizeof(asn_DEF_T_1_tags) sizeof(asn_DEF_T_tags_1)
/sizeof(asn_DEF_T_1_tags[0]), /* 1 */ /sizeof(asn_DEF_T_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
asn_MBR_T_1, asn_MBR_T_1,
3, /* Elements count */ 3, /* Elements count */
&asn_SPC_T_1_specs /* Additional specs */ &asn_SPC_T_specs_1 /* Additional specs */
}; };
...@@ -37,4 +37,6 @@ BEGIN ...@@ -37,4 +37,6 @@ BEGIN
-- not to the SET OF's embedded SEQUENCE! -- not to the SET OF's embedded SEQUENCE!
} }
SSS ::= SEQUENCE OF SET OF SEQUENCE OF BIT STRING
END END
...@@ -23,4 +23,6 @@ Stuff ::= SET { ...@@ -23,4 +23,6 @@ Stuff ::= SET {
} }
} }
SSS ::= SEQUENCE OF SET OF SEQUENCE OF BIT STRING
END END
This diff is collapsed.
...@@ -33,13 +33,15 @@ static asn_TYPE_member_t asn_MBR_Programming_1[] = { ...@@ -33,13 +33,15 @@ static asn_TYPE_member_t asn_MBR_Programming_1[] = {
.tag_mode = -1, /* IMPLICIT tag at current level */ .tag_mode = -1, /* IMPLICIT tag at current level */
.type = &asn_DEF_Fault, .type = &asn_DEF_Fault,
.memb_constraints = 0, /* Defer constraints checking to the member type */ .memb_constraints = 0, /* Defer constraints checking to the member type */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.name = "" .name = ""
}, },
}; };
static ber_tlv_tag_t asn_DEF_Programming_1_tags[] = { static ber_tlv_tag_t asn_DEF_Programming_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
}; };
static asn_SET_OF_specifics_t asn_SPC_Programming_1_specs = { static asn_SET_OF_specifics_t asn_SPC_Programming_specs_1 = {
sizeof(struct Programming), sizeof(struct Programming),
offsetof(struct Programming, _asn_ctx), offsetof(struct Programming, _asn_ctx),
0, /* XER encoding is XMLDelimitedItemList */ 0, /* XER encoding is XMLDelimitedItemList */
...@@ -54,16 +56,18 @@ asn_TYPE_descriptor_t asn_DEF_Programming = { ...@@ -54,16 +56,18 @@ asn_TYPE_descriptor_t asn_DEF_Programming = {
SEQUENCE_OF_encode_der, SEQUENCE_OF_encode_der,
SEQUENCE_OF_decode_xer, SEQUENCE_OF_decode_xer,
SEQUENCE_OF_encode_xer, SEQUENCE_OF_encode_xer,
0, /* No PER decoder, -gen-PER to enable */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_Programming_1_tags, asn_DEF_Programming_tags_1,
sizeof(asn_DEF_Programming_1_tags) sizeof(asn_DEF_Programming_tags_1)
/sizeof(asn_DEF_Programming_1_tags[0]), /* 1 */ /sizeof(asn_DEF_Programming_tags_1[0]), /* 1 */
asn_DEF_Programming_1_tags, /* Same as above */ asn_DEF_Programming_tags_1, /* Same as above */
sizeof(asn_DEF_Programming_1_tags) sizeof(asn_DEF_Programming_tags_1)
/sizeof(asn_DEF_Programming_1_tags[0]), /* 1 */ /sizeof(asn_DEF_Programming_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
asn_MBR_Programming_1, asn_MBR_Programming_1,
1, /* Single element */ 1, /* Single element */
&asn_SPC_Programming_1_specs /* Additional specs */ &asn_SPC_Programming_specs_1 /* Additional specs */
}; };
...@@ -101,13 +105,15 @@ static asn_TYPE_member_t asn_MBR_Fault_1[] = { ...@@ -101,13 +105,15 @@ static asn_TYPE_member_t asn_MBR_Fault_1[] = {
.tag_mode = 0, .tag_mode = 0,
.type = &asn_DEF_Error, .type = &asn_DEF_Error,
.memb_constraints = 0, /* Defer constraints checking to the member type */ .memb_constraints = 0, /* Defer constraints checking to the member type */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.name = "" .name = ""
}, },
}; };
static ber_tlv_tag_t asn_DEF_Fault_1_tags[] = { static ber_tlv_tag_t asn_DEF_Fault_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (17 << 2)) (ASN_TAG_CLASS_UNIVERSAL | (17 << 2))
}; };
static asn_SET_OF_specifics_t asn_SPC_Fault_1_specs = { static asn_SET_OF_specifics_t asn_SPC_Fault_specs_1 = {
sizeof(struct Fault), sizeof(struct Fault),
offsetof(struct Fault, _asn_ctx), offsetof(struct Fault, _asn_ctx),
0, /* XER encoding is XMLDelimitedItemList */ 0, /* XER encoding is XMLDelimitedItemList */
...@@ -122,16 +128,18 @@ asn_TYPE_descriptor_t asn_DEF_Fault = { ...@@ -122,16 +128,18 @@ asn_TYPE_descriptor_t asn_DEF_Fault = {
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_decode_xer, SET_OF_decode_xer,
SET_OF_encode_xer, SET_OF_encode_xer,
0, /* No PER decoder, -gen-PER to enable */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_Fault_1_tags, asn_DEF_Fault_tags_1,
sizeof(asn_DEF_Fault_1_tags) sizeof(asn_DEF_Fault_tags_1)
/sizeof(asn_DEF_Fault_1_tags[0]), /* 1 */ /sizeof(asn_DEF_Fault_tags_1[0]), /* 1 */
asn_DEF_Fault_1_tags, /* Same as above */ asn_DEF_Fault_tags_1, /* Same as above */
sizeof(asn_DEF_Fault_1_tags) sizeof(asn_DEF_Fault_tags_1)
/sizeof(asn_DEF_Fault_1_tags[0]), /* 1 */ /sizeof(asn_DEF_Fault_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
asn_MBR_Fault_1, asn_MBR_Fault_1,
1, /* Single element */ 1, /* Single element */
&asn_SPC_Fault_1_specs /* Additional specs */ &asn_SPC_Fault_specs_1 /* Additional specs */
}; };
...@@ -157,14 +165,15 @@ extern asn_TYPE_descriptor_t asn_DEF_Error; ...@@ -157,14 +165,15 @@ extern asn_TYPE_descriptor_t asn_DEF_Error;
/*** <<< STAT-DEFS [Error] >>> ***/ /*** <<< STAT-DEFS [Error] >>> ***/
static ber_tlv_tag_t asn_DEF_Error_1_tags[] = { static ber_tlv_tag_t asn_DEF_Error_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
}; };
static asn_SEQUENCE_specifics_t asn_SPC_Error_1_specs = { static asn_SEQUENCE_specifics_t asn_SPC_Error_specs_1 = {
sizeof(struct Error), sizeof(struct Error),
offsetof(struct Error, _asn_ctx), offsetof(struct Error, _asn_ctx),
0, /* No top level tags */ 0, /* No top level tags */
0, /* No tags in the map */ 0, /* No tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */ -1, /* Start extensions */
-1 /* Stop extensions */ -1 /* Stop extensions */
}; };
...@@ -178,14 +187,16 @@ asn_TYPE_descriptor_t asn_DEF_Error = { ...@@ -178,14 +187,16 @@ asn_TYPE_descriptor_t asn_DEF_Error = {
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_decode_xer, SEQUENCE_decode_xer,
SEQUENCE_encode_xer, SEQUENCE_encode_xer,
0, /* No PER decoder, -gen-PER to enable */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_Error_1_tags, asn_DEF_Error_tags_1,
sizeof(asn_DEF_Error_1_tags) sizeof(asn_DEF_Error_tags_1)
/sizeof(asn_DEF_Error_1_tags[0]), /* 1 */ /sizeof(asn_DEF_Error_tags_1[0]), /* 1 */
asn_DEF_Error_1_tags, /* Same as above */ asn_DEF_Error_tags_1, /* Same as above */
sizeof(asn_DEF_Error_1_tags) sizeof(asn_DEF_Error_tags_1)
/sizeof(asn_DEF_Error_1_tags[0]), /* 1 */ /sizeof(asn_DEF_Error_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
0, 0, /* No members */ 0, 0, /* No members */
&asn_SPC_Error_1_specs /* Additional specs */ &asn_SPC_Error_specs_1 /* Additional specs */
}; };
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -16,7 +16,7 @@ BEGIN ...@@ -16,7 +16,7 @@ BEGIN
Int1 ::= INTEGER Int1 ::= INTEGER
Int2 ::= Int1 (0..MAX) -- X.680-0207::41.4.4 Int2 ::= Int1 (0..MAX) -- X.680-0207::41.4.4
Int3 ::= Int2 (MIN..ten) -- Means (0..10) Int3 ::= Int2 (MIN..ten) -- Means (0..10)
Int4 ::= Int3 (5..MAX,...,1..4) -- Means (5..10,...,1..4) Int4 ::= Int3 (5..MAX,...,1..4) -- Means (1..10,...)
Int5 ::= Int4 (MIN..5) -- Means (5) Int5 ::= Int4 (MIN..5) -- Means (5)
-- Int6 ::= INTEGER (Int5) -- -- Not yet supported -- Int6 ::= INTEGER (Int5) -- -- Not yet supported
...@@ -52,6 +52,23 @@ BEGIN ...@@ -52,6 +52,23 @@ BEGIN
VisibleIdentifier ::= Identifier VisibleIdentifier ::= Identifier
Sequence ::= SEQUENCE {
int1-c Int1 (-2..MAX) DEFAULT 3,
int4 [2] Int4,
int4-c Int4 (MIN..7),
bool BOOLEAN DEFAULT 1,
enum-c ENUMERATED { one(1), two(2), ..., three(3) },
...,
int5-c Int5 (5) OPTIONAL,
...,
null NULL OPTIONAL
}
SequenceOf ::= SEQUENCE (SIZE(1..2)) OF Sequence
Enum0 ::= ENUMERATED { one, two }
Enum1 ::= ENUMERATED { one, two } (one)
END END
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment