Commit fe8c6b7e authored by Lev Walkin's avatar Lev Walkin

add OER for BOOLEAN

parent 8cec5235
......@@ -24,8 +24,8 @@ asn_TYPE_operation_t asn_OP_BOOLEAN = {
0,
0,
#else
0,
0,
BOOLEAN_decode_oer,
BOOLEAN_encode_oer,
#endif /* ASN_DISABLE_OER_SUPPORT */
#ifdef ASN_DISABLE_PER_SUPPORT
0,
......@@ -258,6 +258,8 @@ BOOLEAN_free(const asn_TYPE_descriptor_t *td, void *ptr,
}
}
#ifndef ASN_DISABLE_PER_SUPPORT
asn_dec_rval_t
BOOLEAN_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
const asn_per_constraints_t *constraints, void **sptr,
......@@ -308,6 +310,60 @@ BOOLEAN_encode_uper(asn_TYPE_descriptor_t *td,
ASN__ENCODED_OK(er);
}
#endif /* ASN_DISABLE_PER_SUPPORT */
#ifndef ASN_DISABLE_OER_SUPPORT
/*
* Encode as Canonical OER.
*/
asn_enc_rval_t
BOOLEAN_encode_oer(asn_TYPE_descriptor_t *td,
const asn_oer_constraints_t *constraints, void *sptr,
asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t er = { 1, 0, 0 };
const BOOLEAN_t *st = sptr;
uint8_t bool_value = *st ? 0xff : 0; /* 0xff mandated by OER */
(void)td;
(void)constraints; /* Constraints are unused in OER */
if(cb(&bool_value, 1, app_key) < 0) {
ASN__ENCODE_FAILED;
} else {
ASN__ENCODED_OK(er);
}
}
asn_dec_rval_t
BOOLEAN_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td,
const asn_oer_constraints_t *constraints, void **sptr,
const void *ptr, size_t size) {
asn_dec_rval_t ok = {RC_OK, 1};
BOOLEAN_t *st;
(void)opt_codec_ctx;
(void)td;
(void)constraints; /* Constraints are unused in OER */
if(size < 1) {
ASN__DECODE_STARVED;
}
if(!(st = *sptr)) {
st = (BOOLEAN_t *)(*sptr = CALLOC(1, sizeof(*st)));
if(!st) ASN__DECODE_FAILED;
}
*st = *(const uint8_t *)ptr;
return ok;
}
#endif
int
BOOLEAN_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
......@@ -318,7 +374,7 @@ BOOLEAN_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
(void)td;
if(a && b) {
if(*a == *b) {
if(!*a == !*b) { /* TRUE can be encoded by any non-zero byte. */
return 0;
} else if(!*a) {
return -1;
......@@ -334,16 +390,13 @@ BOOLEAN_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
asn_random_fill_result_t
BOOLEAN_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
const asn_encoding_constraints_t *constr,
const asn_encoding_constraints_t *constraints,
size_t max_length) {
asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
BOOLEAN_t *st = *sptr;
(void)td;
(void)constr;
if(max_length == 0) return result_skipped;
if(st == NULL) {
......@@ -353,7 +406,16 @@ BOOLEAN_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
}
}
*st = asn_random_between(0, 1);
if(!constraints) constraints = &td->encoding_constraints;
if(constraints->per_constraints) {
const asn_per_constraint_t *pc = &constraints->per_constraints->value;
if(pc->flags & APC_CONSTRAINED) {
*st = asn_random_between(pc->lower_bound, pc->upper_bound);
return result_ok;
}
}
/* Simulate booleans that are sloppily set */
*st = asn_random_between(0, 1) ? asn_random_between(1, 0x7fffffff) : 0;
return result_ok;
}
......@@ -26,10 +26,12 @@ asn_struct_print_f BOOLEAN_print;
asn_struct_compare_f BOOLEAN_compare;
ber_type_decoder_f BOOLEAN_decode_ber;
der_type_encoder_f BOOLEAN_encode_der;
xer_type_decoder_f BOOLEAN_decode_xer;
xer_type_encoder_f BOOLEAN_encode_xer;
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;
xer_type_decoder_f BOOLEAN_decode_xer;
xer_type_encoder_f BOOLEAN_encode_xer;
asn_random_fill_f BOOLEAN_random_fill;
#define BOOLEAN_constraint asn_generic_no_constraint
......
-- Test boolean. Should be easy
T ::= BOOLEAN
T ::= BOOLEAN (FALSE)
T ::= BOOLEAN (TRUE)
T ::= BOOLEAN (FALSE,...)
T ::= BOOLEAN (TRUE,...)
T ::= BOOLEAN (FALSE..TRUE)
T ::= BOOLEAN (FALSE..TRUE,...)
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