decode SET OF in OER

This commit is contained in:
Lev Walkin 2017-08-29 23:38:31 -07:00
parent 84382cc1f5
commit 96f9921b09
9 changed files with 62 additions and 28 deletions

View File

@ -287,6 +287,7 @@ ASN_MODULE_SOURCES+=NativeInteger_oer.c
ASN_MODULE_SOURCES+=NativeEnumerated_oer.c
ASN_MODULE_SOURCES+=constr_SEQUENCE_oer.c
ASN_MODULE_SOURCES+=constr_CHOICE_oer.c
ASN_MODULE_SOURCES+=constr_SET_OF_oer.c
ASN_CONVERTER_SOURCES+=pdu_collection.c

View File

@ -72,6 +72,7 @@ libasn1cskeletons_la_SOURCES = \
constr_SEQUENCE_OF.c constr_SEQUENCE_OF.h \
constr_SET.c constr_SET.h \
constr_SET_OF.c constr_SET_OF.h \
constr_SET_OF_oer.c \
constr_TYPE.c constr_TYPE.h \
constraints.c constraints.h \
der_encoder.c der_encoder.h \

View File

@ -41,23 +41,23 @@ NativeInteger_decode_oer(asn_codec_ctx_t *opt_codec_ctx,
if(specs && specs->field_unsigned) {
unsigned long ul;
if(asn_INTEGER2ulong(&tmpint, &ul) != 0) {
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
rval.code = RC_FAIL;
rval.consumed = 0;
return rval;
} else {
int ok = asn_INTEGER2ulong(&tmpint, &ul) == 0;
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
if(ok) {
*native = ul;
} else {
rval.code = RC_FAIL;
return rval;
}
} else {
long l;
if(asn_INTEGER2long(&tmpint, &l) != 0) {
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
rval.code = RC_FAIL;
rval.consumed = 0;
return rval;
} else {
int ok = asn_INTEGER2long(&tmpint, &l) == 0;
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
if(ok) {
*native = l;
} else {
rval.code = RC_FAIL;
return rval;
}
}

View File

@ -15,6 +15,7 @@
#undef RETURN
#define RETURN(_code) \
do { \
asn_dec_rval_t rval; \
rval.code = _code; \
rval.consumed = consumed_myself; \
return rval; \
@ -38,7 +39,12 @@
ctx->phase++; \
ctx->step = 0; \
} while(0)
#undef SET_PHASE
#define SET_PHASE(ctx, value) \
do { \
ctx->phase = value; \
ctx->step = 0; \
} while(0)
/*
* Tags are canonically sorted in the tag to member table.
@ -136,8 +142,6 @@ CHOICE_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
void *st = *struct_ptr; /* Target structure. */
asn_struct_ctx_t *ctx; /* Decoder context */
asn_dec_rval_t rval; /* Return code from subparsers */
ssize_t consumed_myself = 0; /* Consumed bytes from ptr */
(void)constraints;
@ -196,7 +200,9 @@ CHOICE_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
RETURN(RC_FAIL);
} else {
/* Skip open type extension */
ASN_DEBUG("Not implemented skipping open type extension");
ASN_DEBUG(
"Not implemented skipping open type extension for tag %s",
ber_tlv_tag_string(tlv_tag));
RETURN(RC_FAIL);
}
} while(0);
@ -204,10 +210,12 @@ CHOICE_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
ADVANCE(tag_len);
}
/* Fall through */
case 1: {
asn_TYPE_member_t *elm = &elements[ctx->step]; /* CHOICE's element */
void *memb_ptr; /* Pointer to the member */
void **memb_ptr2; /* Pointer to that pointer */
asn_dec_rval_t rval;
/*
* Compute the position of the member inside a structure,
@ -240,8 +248,22 @@ CHOICE_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
elm->oer_constraints, memb_ptr2, ptr,
size);
rval.consumed += consumed_myself;
switch(rval.code) {
case RC_OK:
NEXT_PHASE(ctx);
case RC_WMORE:
break;
case RC_FAIL:
SET_PHASE(ctx, 3); /* => 3 */
}
return rval;
}
case 2:
/* Already decoded everything */
RETURN(RC_OK);
case 3:
/* Failed to decode, after all */
RETURN(RC_FAIL);
}
RETURN(RC_FAIL);

View File

@ -220,8 +220,8 @@ asn_TYPE_operation_t asn_OP_SEQUENCE_OF = {
0,
0,
#else
0,
0,
SEQUENCE_OF_decode_oer,
SEQUENCE_OF_encode_oer,
#endif /* ASN_DISABLE_OER_SUPPORT */
#ifdef ASN_DISABLE_PER_SUPPORT
0,

View File

@ -23,6 +23,8 @@ extern "C" {
#define SEQUENCE_OF_decode_ber SET_OF_decode_ber
#define SEQUENCE_OF_decode_xer SET_OF_decode_xer
#define SEQUENCE_OF_decode_uper SET_OF_decode_uper
#define SEQUENCE_OF_decode_oer SET_OF_decode_oer
#define SEQUENCE_OF_encode_oer SET_OF_encode_oer
der_type_encoder_f SEQUENCE_OF_encode_der;
xer_type_encoder_f SEQUENCE_OF_encode_xer;
per_type_encoder_f SEQUENCE_OF_encode_uper;

View File

@ -981,8 +981,13 @@ asn_TYPE_operation_t asn_OP_SET_OF = {
SET_OF_encode_der,
SET_OF_decode_xer,
SET_OF_encode_xer,
#ifdef ASN_DISABLE_OER_SUPPORT
0,
0,
#else
SET_OF_decode_oer,
SET_OF_decode_oer,
#endif
#ifdef ASN_DISABLE_PER_SUPPORT
0,
0,

View File

@ -2,8 +2,8 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef _CONSTR_SET_OF_H_
#define _CONSTR_SET_OF_H_
#ifndef CONSTR_SET_OF_H
#define CONSTR_SET_OF_H
#include <asn_application.h>
@ -12,14 +12,14 @@ extern "C" {
#endif
typedef const struct asn_SET_OF_specifics_s {
/*
* Target structure description.
*/
int struct_size; /* Size of the target structure. */
int ctx_offset; /* Offset of the asn_struct_ctx_t member */
/*
* Target structure description.
*/
unsigned struct_size; /* Size of the target structure. */
unsigned ctx_offset; /* Offset of the asn_struct_ctx_t member */
/* XER-specific stuff */
int as_XMLValueList; /* The member type must be encoded like this */
/* XER-specific stuff */
int as_XMLValueList; /* The member type must be encoded like this */
} asn_SET_OF_specifics_t;
/*
@ -33,6 +33,8 @@ ber_type_decoder_f SET_OF_decode_ber;
der_type_encoder_f SET_OF_encode_der;
xer_type_decoder_f SET_OF_decode_xer;
xer_type_encoder_f SET_OF_encode_xer;
oer_type_decoder_f SET_OF_decode_oer;
oer_type_encoder_f SET_OF_encode_oer;
per_type_decoder_f SET_OF_decode_uper;
per_type_encoder_f SET_OF_encode_uper;
extern asn_TYPE_operation_t asn_OP_SET_OF;
@ -41,4 +43,4 @@ extern asn_TYPE_operation_t asn_OP_SET_OF;
}
#endif
#endif /* _CONSTR_SET_OF_H_ */
#endif /* CONSTR_SET_OF_H */

View File

@ -78,5 +78,6 @@ NativeInteger_oer.c
NativeEnumerated_oer.c
constr_SEQUENCE_oer.c
constr_CHOICE_oer.c
constr_SET_OF_oer.c
CODEC-PER: # THIS IS A SPECIAL SECTION