Skip to content

Commit

Permalink
Merge APER implementation from mouse07410's repository
Browse files Browse the repository at this point in the history
  • Loading branch information
brchiu committed Oct 24, 2017
1 parent cb59ce6 commit e129848
Show file tree
Hide file tree
Showing 86 changed files with 2,854 additions and 17 deletions.
10 changes: 6 additions & 4 deletions libasn1compiler/asn1c_C.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,12 +1433,14 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
OUT("xer_type_decoder_f %s_decode_xer;\n", p);
OUT("xer_type_encoder_f %s_encode_xer;\n", p);
if(arg->flags & A1C_GEN_OER) {
OUT("oer_type_decoder_f %s_decode_oer;\n", p);
OUT("oer_type_encoder_f %s_encode_oer;\n", p);
OUT("oer_type_decoder_f %s_decode_oer;\n", p);
OUT("oer_type_encoder_f %s_encode_oer;\n", p);
}
if(arg->flags & A1C_GEN_PER) {
OUT("per_type_decoder_f %s_decode_uper;\n", p);
OUT("per_type_encoder_f %s_encode_uper;\n", p);
OUT("per_type_decoder_f %s_decode_uper;\n", p);
OUT("per_type_encoder_f %s_encode_uper;\n", p);
OUT("per_type_decoder_f %s_decode_aper;\n", p);
OUT("per_type_encoder_f %s_encode_aper;\n", p);
}
}

Expand Down
4 changes: 3 additions & 1 deletion skeletons/ANY.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ asn_TYPE_operation_t asn_OP_ANY = {
0,
#endif /* ASN_DISABLE_OER_SUPPORT */
#ifdef ASN_DISABLE_PER_SUPPORT
0, 0,
0, 0, 0, 0,
#else
ANY_decode_uper,
ANY_encode_uper,
ANY_decode_aper,
ANY_encode_aper,
#endif /* ASN_DISABLE_PER_SUPPORT */
0, /* Random fill is not defined for ANY type */
0 /* Use generic outmost tag fetcher */
Expand Down
2 changes: 2 additions & 0 deletions skeletons/ANY.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ der_type_encoder_f ANY_encode_der;
xer_type_encoder_f ANY_encode_xer;
per_type_decoder_f ANY_decode_uper;
per_type_encoder_f ANY_encode_uper;
per_type_decoder_f ANY_decode_aper;
per_type_encoder_f ANY_encode_aper;

#define ANY_free OCTET_STRING_free
#define ANY_print OCTET_STRING_print
Expand Down
4 changes: 4 additions & 0 deletions skeletons/BIT_STRING.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ asn_TYPE_operation_t asn_OP_BIT_STRING = {
#ifdef ASN_DISABLE_PER_SUPPORT
0,
0,
0,
0,
#else
BIT_STRING_decode_uper, /* Unaligned PER decoder */
BIT_STRING_encode_uper, /* Unaligned PER encoder */
OCTET_STRING_decode_aper, /* Aligned PER decoder */
OCTET_STRING_encode_aper, /* Aligned PER encoder */
#endif /* ASN_DISABLE_PER_SUPPORT */
BIT_STRING_random_fill,
0 /* Use generic outmost tag fetcher */
Expand Down
2 changes: 2 additions & 0 deletions skeletons/BIT_STRING.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ asn_random_fill_f BIT_STRING_random_fill;
#define BIT_STRING_decode_ber OCTET_STRING_decode_ber
#define BIT_STRING_encode_der OCTET_STRING_encode_der
#define BIT_STRING_decode_xer OCTET_STRING_decode_xer_binary
#define BIT_STRING_decode_aper OCTET_STRING_decode_aper
#define BIT_STRING_encode_aper OCTET_STRING_encode_aper

#ifdef __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions skeletons/BMPString.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ asn_TYPE_operation_t asn_OP_BMPString = {
#ifdef ASN_DISABLE_PER_SUPPORT
0,
0,
0,
0,
#else
OCTET_STRING_decode_uper,
OCTET_STRING_encode_uper,
OCTET_STRING_decode_aper,
OCTET_STRING_encode_aper,
#endif /* ASN_DISABLE_PER_SUPPORT */
OCTET_STRING_random_fill,
0 /* Use generic outmost tag fetcher */
Expand Down
2 changes: 2 additions & 0 deletions skeletons/BMPString.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ xer_type_encoder_f BMPString_encode_xer;
#define BMPString_encode_der OCTET_STRING_encode_der
#define BMPString_decode_uper OCTET_STRING_decode_uper
#define BMPString_encode_uper OCTET_STRING_encode_uper
#define BMPString_decode_aper OCTET_STRING_decode_aper
#define BMPString_encode_aper OCTET_STRING_encode_aper

#ifdef __cplusplus
}
Expand Down
57 changes: 57 additions & 0 deletions skeletons/BOOLEAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ asn_TYPE_operation_t asn_OP_BOOLEAN = {
#ifdef ASN_DISABLE_PER_SUPPORT
0,
0,
0,
0,
#else
BOOLEAN_decode_uper, /* Unaligned PER decoder */
BOOLEAN_encode_uper, /* Unaligned PER encoder */
BOOLEAN_decode_aper, /* Aligned PER decoder */
BOOLEAN_encode_aper, /* Aligned PER encoder */
#endif /* ASN_DISABLE_PER_SUPPORT */
BOOLEAN_random_fill,
0 /* Use generic outmost tag fetcher */
Expand Down Expand Up @@ -310,6 +314,59 @@ BOOLEAN_encode_uper(const asn_TYPE_descriptor_t *td,
ASN__ENCODED_OK(er);
}

asn_dec_rval_t
BOOLEAN_decode_aper(const asn_codec_ctx_t *opt_codec_ctx, const asn_TYPE_descriptor_t *td,
const 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;
(void)td;

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_STARVED;
}

ASN_DEBUG("%s decoded as %s", td->name, *st ? "TRUE" : "FALSE");

rv.code = RC_OK;
rv.consumed = 1;
return rv;
}

asn_enc_rval_t
BOOLEAN_encode_aper(const asn_TYPE_descriptor_t *td,
const asn_per_constraints_t *constraints,
const void *sptr, asn_per_outp_t *po) {
const BOOLEAN_t *st = (const BOOLEAN_t *)sptr;
asn_enc_rval_t er;

(void)constraints;

if(!st) ASN__ENCODE_FAILED;

per_put_few_bits(po, *st ? 1 : 0, 1);

ASN__ENCODED_OK(er);
}

#endif /* ASN_DISABLE_PER_SUPPORT */

#ifndef ASN_DISABLE_OER_SUPPORT
Expand Down
2 changes: 2 additions & 0 deletions skeletons/BOOLEAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ oer_type_decoder_f BOOLEAN_decode_oer;
oer_type_encoder_f BOOLEAN_encode_oer;
per_type_decoder_f BOOLEAN_decode_uper;
per_type_encoder_f BOOLEAN_encode_uper;
per_type_decoder_f BOOLEAN_decode_aper;
per_type_encoder_f BOOLEAN_encode_aper;
xer_type_decoder_f BOOLEAN_decode_xer;
xer_type_encoder_f BOOLEAN_encode_xer;
asn_random_fill_f BOOLEAN_random_fill;
Expand Down
45 changes: 42 additions & 3 deletions skeletons/ENUMERATED.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ asn_TYPE_operation_t asn_OP_ENUMERATED = {
INTEGER_compare, /* Implemented in terms of INTEGER */
ber_decode_primitive,
INTEGER_encode_der, /* Implemented in terms of INTEGER */
INTEGER_decode_xer, /* This is temporary! */
INTEGER_decode_xer, /* This is temporary! */
INTEGER_encode_xer,
#ifdef ASN_DISABLE_OER_SUPPORT
0,
Expand All @@ -32,9 +32,13 @@ asn_TYPE_operation_t asn_OP_ENUMERATED = {
#ifdef ASN_DISABLE_PER_SUPPORT
0,
0,
0,
0,
#else
ENUMERATED_decode_uper, /* Unaligned PER decoder */
ENUMERATED_encode_uper, /* Unaligned PER encoder */
ENUMERATED_decode_uper, /* Unaligned PER decoder */
ENUMERATED_encode_uper, /* Unaligned PER encoder */
ENUMERATED_decode_aper, /* Aligned PER decoder */
ENUMERATED_encode_aper, /* Aligned PER encoder */
#endif /* ASN_DISABLE_PER_SUPPORT */
ENUMERATED_random_fill,
0 /* Use generic outmost tag fetcher */
Expand Down Expand Up @@ -138,4 +142,39 @@ ENUMERATED_encode_uper(const asn_TYPE_descriptor_t *td,
return NativeEnumerated_encode_uper(td, constraints, &value, po);
}

asn_dec_rval_t
ENUMERATED_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
const asn_TYPE_descriptor_t *td,
const 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;
void *vptr = &value;

if(!st) {
st = (ENUMERATED_t *)(*sptr = CALLOC(1, sizeof(*st)));
if(!st) ASN__DECODE_FAILED;
}

rval = NativeEnumerated_decode_aper(opt_codec_ctx, td, constraints,
(void **)&vptr, pd);
if(rval.code == RC_OK)
if(asn_long2INTEGER(st, value))
rval.code = RC_FAIL;
return rval;
}

asn_enc_rval_t
ENUMERATED_encode_aper(const asn_TYPE_descriptor_t *td,
const asn_per_constraints_t *constraints,
const void *sptr, asn_per_outp_t *po) {
const ENUMERATED_t *st = (const ENUMERATED_t *)sptr;
long value;

if(asn_INTEGER2long(st, &value))
ASN__ENCODE_FAILED;

return NativeEnumerated_encode_aper(td, constraints, &value, po);
}
#endif /* ASN_DISABLE_PER_SUPPORT */

2 changes: 2 additions & 0 deletions skeletons/ENUMERATED.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ oer_type_decoder_f ENUMERATED_decode_oer;
oer_type_encoder_f ENUMERATED_encode_oer;
per_type_decoder_f ENUMERATED_decode_uper;
per_type_encoder_f ENUMERATED_encode_uper;
per_type_decoder_f ENUMERATED_decode_aper;
per_type_encoder_f ENUMERATED_encode_aper;

#define ENUMERATED_free ASN__PRIMITIVE_TYPE_free
#define ENUMERATED_print INTEGER_print
Expand Down
4 changes: 4 additions & 0 deletions skeletons/GeneralString.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ asn_TYPE_operation_t asn_OP_GeneralString = {
#ifdef ASN_DISABLE_PER_SUPPORT
0,
0,
0,
0,
#else
OCTET_STRING_decode_uper, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_uper,
OCTET_STRING_decode_aper, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_aper,
#endif /* ASN_DISABLE_PER_SUPPORT */
OCTET_STRING_random_fill,
0 /* Use generic outmost tag fetcher */
Expand Down
2 changes: 2 additions & 0 deletions skeletons/GeneralString.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern asn_TYPE_operation_t asn_OP_GeneralString;
#define GeneralString_encode_xer OCTET_STRING_encode_xer
#define GeneralString_decode_uper OCTET_STRING_decode_uper
#define GeneralString_encode_uper OCTET_STRING_encode_uper
#define GeneralString_decode_aper OCTET_STRING_decode_aper
#define GeneralString_encode_aper OCTET_STRING_encode_aper

#ifdef __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions skeletons/GeneralizedTime.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,13 @@ asn_TYPE_operation_t asn_OP_GeneralizedTime = {
#ifdef ASN_DISABLE_PER_SUPPORT
0,
0,
0,
0,
#else
OCTET_STRING_decode_uper,
OCTET_STRING_encode_uper,
OCTET_STRING_decode_aper,
OCTET_STRING_encode_aper,
#endif /* ASN_DISABLE_PER_SUPPORT */
GeneralizedTime_random_fill,
0 /* Use generic outmost tag fetcher */
Expand Down
2 changes: 2 additions & 0 deletions skeletons/GeneralizedTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ asn_random_fill_f GeneralizedTime_random_fill;
#define GeneralizedTime_decode_xer OCTET_STRING_decode_xer_utf8
#define GeneralizedTime_decode_uper OCTET_STRING_decode_uper
#define GeneralizedTime_encode_uper OCTET_STRING_encode_uper
#define GeneralizedTime_decode_aper OCTET_STRING_decode_aper
#define GeneralizedTime_encode_aper OCTET_STRING_encode_aper

/***********************
* Some handy helpers. *
Expand Down
4 changes: 4 additions & 0 deletions skeletons/GraphicString.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ asn_TYPE_operation_t asn_OP_GraphicString = {
#ifdef ASN_DISABLE_PER_SUPPORT
0,
0,
0,
0,
#else
OCTET_STRING_decode_uper, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_uper,
OCTET_STRING_decode_aper, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_aper,
#endif /* ASN_DISABLE_PER_SUPPORT */
OCTET_STRING_random_fill,
0 /* Use generic outmost tag fetcher */
Expand Down
2 changes: 2 additions & 0 deletions skeletons/GraphicString.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern asn_TYPE_operation_t asn_OP_GraphicString;
#define GraphicString_encode_xer OCTET_STRING_encode_xer
#define GraphicString_decode_uper OCTET_STRING_decode_uper
#define GraphicString_encode_uper OCTET_STRING_encode_uper
#define GraphicString_decode_aper OCTET_STRING_decode_aper
#define GraphicString_encode_aper OCTET_STRING_encode_aper

#ifdef __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions skeletons/IA5String.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ asn_TYPE_operation_t asn_OP_IA5String = {
#ifdef ASN_DISABLE_PER_SUPPORT
0,
0,
0,
0,
#else
OCTET_STRING_decode_uper,
OCTET_STRING_encode_uper,
OCTET_STRING_decode_aper,
OCTET_STRING_encode_aper,
#endif /* ASN_DISABLE_PER_SUPPORT */
OCTET_STRING_random_fill,
0 /* Use generic outmost tag fetcher */
Expand Down
2 changes: 2 additions & 0 deletions skeletons/IA5String.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ asn_constr_check_f IA5String_constraint;
#define IA5String_encode_xer OCTET_STRING_encode_xer_utf8
#define IA5String_decode_uper OCTET_STRING_decode_uper
#define IA5String_encode_uper OCTET_STRING_encode_uper
#define IA5String_decode_aper OCTET_STRING_decode_aper
#define IA5String_encode_aper OCTET_STRING_encode_aper

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit e129848

Please sign in to comment.