Commit 42f6c880 authored by Lev Walkin's avatar Lev Walkin

fix OER NULL and SEQUENCE extensions round-trip

parent a460cbd1
...@@ -135,15 +135,24 @@ NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -135,15 +135,24 @@ NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_dec_rval_t asn_dec_rval_t
NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
const asn_TYPE_descriptor_t *td, const asn_TYPE_descriptor_t *td,
const asn_oer_constraints_t *constraints, void **struct_ptr, const asn_oer_constraints_t *constraints, void **sptr,
const void *ptr, size_t size) { const void *ptr, size_t size) {
asn_dec_rval_t rv = {RC_OK, 0}; asn_dec_rval_t rv = {RC_OK, 0};
(void)opt_codec_ctx; (void)opt_codec_ctx;
(void)td; (void)td;
(void)constraints; (void)constraints;
(void)struct_ptr;
(void)ptr; (void)ptr;
(void)size; (void)size;
if(!*sptr) {
*sptr = MALLOC(sizeof(NULL_t));
if(*sptr) {
*(NULL_t *)*sptr = 0;
} else {
ASN__DECODE_FAILED;
}
}
return rv; return rv;
} }
......
...@@ -1517,8 +1517,18 @@ SEQUENCE_compare(const asn_TYPE_descriptor_t *td, const void *aptr, ...@@ -1517,8 +1517,18 @@ SEQUENCE_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
*(const void *const *)((const char *)bptr + elm->memb_offset); *(const void *const *)((const char *)bptr + elm->memb_offset);
if(!amemb) { if(!amemb) {
if(!bmemb) continue; if(!bmemb) continue;
if(elm->default_value_cmp
&& elm->default_value_cmp(bmemb) == 0) {
/* A is absent, but B is present and equal to DEFAULT */
continue;
}
return -1; return -1;
} else if(!bmemb) { } else if(!bmemb) {
if(elm->default_value_cmp
&& elm->default_value_cmp(amemb) == 0) {
/* B is absent, but A is present and equal to DEFAULT */
continue;
}
return 1; return 1;
} }
} else { } else {
......
...@@ -207,9 +207,10 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -207,9 +207,10 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
memb_ptr2 = element_ptrptr(st, elm, &save_memb_ptr); memb_ptr2 = element_ptrptr(st, elm, &save_memb_ptr);
rval = elm->type->op->oer_decoder(opt_codec_ctx, elm->type, rval = elm->type->op->oer_decoder(
elm->encoding_constraints.oer_constraints, opt_codec_ctx, elm->type,
memb_ptr2, ptr, size); elm->encoding_constraints.oer_constraints, memb_ptr2, ptr,
size);
} }
switch(rval.code) { switch(rval.code) {
case RC_OK: case RC_OK:
...@@ -268,7 +269,7 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -268,7 +269,7 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
len_len = oer_fetch_length(ptr, size, &len); len_len = oer_fetch_length(ptr, size, &len);
if(len_len > 0) { if(len_len > 0) {
ADVANCE(len_len); ADVANCE(len_len);
} if(len_len < 0) { } else if(len_len < 0) {
RETURN(RC_FAIL); RETURN(RC_FAIL);
} else { } else {
RETURN(RC_WMORE); RETURN(RC_WMORE);
...@@ -314,7 +315,8 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -314,7 +315,8 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
asn_bit_data_t *extadds = ctx->ptr; asn_bit_data_t *extadds = ctx->ptr;
size_t edx = ctx->step; size_t edx = ctx->step;
asn_TYPE_member_t *elm = &td->elements[edx]; asn_TYPE_member_t *elm = &td->elements[edx];
void **memb_ptr2 = element_ptrptr(st, elm, 0); void *tmp_memb_ptr;
void **memb_ptr2 = element_ptrptr(st, elm, &tmp_memb_ptr);
switch(asn_get_few_bits(extadds, 1)) { switch(asn_get_few_bits(extadds, 1)) {
case -1: case -1:
...@@ -332,9 +334,11 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -332,9 +334,11 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
continue; continue;
case 1: { case 1: {
/* Read OER open type */ /* Read OER open type */
ssize_t ot_size = oer_open_type_get(opt_codec_ctx, elm->type, ssize_t ot_size =
elm->encoding_constraints.oer_constraints, oer_open_type_get(opt_codec_ctx, elm->type,
memb_ptr2, ptr, size); elm->encoding_constraints.oer_constraints,
memb_ptr2, ptr, size);
assert(ot_size <= (ssize_t)size);
if(ot_size > 0) { if(ot_size > 0) {
ADVANCE(ot_size); ADVANCE(ot_size);
} else if(ot_size < 0) { } else if(ot_size < 0) {
...@@ -342,8 +346,12 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -342,8 +346,12 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
} else { } else {
/* Roll back open type parsing */ /* Roll back open type parsing */
asn_get_undo(extadds, 1); asn_get_undo(extadds, 1);
ASN_STRUCT_FREE(*elm->type, *memb_ptr2); if(memb_ptr2 == &tmp_memb_ptr) {
*memb_ptr2 = NULL; ASN_STRUCT_RESET(*elm->type, *memb_ptr2);
} else {
ASN_STRUCT_FREE(*elm->type, *memb_ptr2);
*memb_ptr2 = NULL;
}
RETURN(RC_WMORE); RETURN(RC_WMORE);
} }
break; break;
...@@ -385,7 +393,7 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -385,7 +393,7 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
} }
} }
return rval; RETURN(RC_OK);
} }
/* /*
...@@ -552,13 +560,14 @@ SEQUENCE_encode_oer(const asn_TYPE_descriptor_t *td, ...@@ -552,13 +560,14 @@ SEQUENCE_encode_oer(const asn_TYPE_descriptor_t *td,
&& elm->default_value_cmp(memb_ptr) == 0) { && elm->default_value_cmp(memb_ptr) == 0) {
/* Do not encode default value. */ /* Do not encode default value. */
} else { } else {
asn_enc_rval_t er = elm->type->op->oer_encoder( ssize_t wrote = oer_open_type_put(
elm->type, elm->encoding_constraints.oer_constraints, elm->type, elm->encoding_constraints.oer_constraints,
memb_ptr, cb, app_key); memb_ptr, cb, app_key);
if(er.encoded == -1) { ASN_DEBUG("Open type %s encoded in %zd, +computed=%zu", elm->type->name, wrote, computed_size);
return er; if(wrote == -1) {
ASN__ENCODE_FAILED;
} }
computed_size += er.encoded; computed_size += wrote;
} }
} else if(!elm->optional) { } else if(!elm->optional) {
ASN__ENCODE_FAILED; ASN__ENCODE_FAILED;
......
...@@ -136,6 +136,6 @@ oer_open_type_put(const asn_TYPE_descriptor_t *td, ...@@ -136,6 +136,6 @@ oer_open_type_put(const asn_TYPE_descriptor_t *td,
if(er.encoded < 0) return -1; if(er.encoded < 0) return -1;
assert(serialized_byte_count == (size_t)er.encoded); assert(serialized_byte_count == (size_t)er.encoded);
return er.encoded + len_len; return len_len + er.encoded;
} }
...@@ -48,8 +48,8 @@ typedef asn_enc_rval_t(oer_type_encoder_f)( ...@@ -48,8 +48,8 @@ typedef asn_enc_rval_t(oer_type_encoder_f)(
/* /*
* Write out the Open Type (X.696 (08/2015), #30). * Write out the Open Type (X.696 (08/2015), #30).
* RETURN VALUES: * RETURN VALUES:
* -1: Fatal error encoding the type. * -1: Fatal error encoding the type.
* >=0: Number of bytes serialized. * >0: Number of bytes serialized.
*/ */
ssize_t oer_open_type_put(const struct asn_TYPE_descriptor_s *td, ssize_t oer_open_type_put(const struct asn_TYPE_descriptor_s *td,
const asn_oer_constraints_t *constraints, const asn_oer_constraints_t *constraints,
......
...@@ -40,6 +40,7 @@ TESTS += bundles/12-UniversalString-bundle.txt ...@@ -40,6 +40,7 @@ TESTS += bundles/12-UniversalString-bundle.txt
TESTS += bundles/13-UTCTime-bundle.txt TESTS += bundles/13-UTCTime-bundle.txt
TESTS += bundles/14-GeneralizedTime-bundle.txt TESTS += bundles/14-GeneralizedTime-bundle.txt
TESTS += bundles/15-CHOICE-bundle.txt TESTS += bundles/15-CHOICE-bundle.txt
TESTS += bundles/16-SEQUENCE-bundle.txt
EXTRA_DIST = \ EXTRA_DIST = \
random-test-driver.c \ random-test-driver.c \
......
SEQUENCE { }
SEQUENCE { ... }
SEQUENCE { null NULL }
SEQUENCE { null NULL OPTIONAL }
SEQUENCE { ..., null NULL }
SEQUENCE { ..., null NULL OPTIONAL }
SEQUENCE { ..., null BOOLEAN }
SEQUENCE { ..., null BOOLEAN DEFAULT FALSE }
SEQUENCE { ..., null BOOLEAN DEFAULT TRUE }
SEQUENCE { null NULL }
SEQUENCE { null NULL, ... }
SEQUENCE { one NULL, two [2] NULL }
SEQUENCE { one [1] NULL, two [2] NULL }
SEQUENCE { one [2] NULL, two [1] NULL }
SEQUENCE { one [1] NULL, two [3] NULL }
SEQUENCE { one [3] NULL, two [1] NULL }
SEQUENCE { one [3] NULL, two [1] NULL, three [2] NULL }
SEQUENCE { one [4] NULL, two [3] NULL, three [1] NULL, four [2] NULL }
SEQUENCE { one [5] NULL, two [4] NULL, ..., three [3] NULL, four [2] NULL }
SEQUENCE { null NULL, ..., one [5] NULL, two [4] NULL, three [3] NULL, four [2] NULL }
SEQUENCE { one NULL, two [2] NULL, ... }
SEQUENCE { one NULL, ..., two [2] NULL }
SEQUENCE { one NULL, two [2] NULL, ..., three [3] NULL }
SEQUENCE { one NULL, ..., two [2] NULL, three [3] NULL }
SEQUENCE { one BOOLEAN, ..., two [2] BOOLEAN, three [3] BOOLEAN }
SEQUENCE { one BOOLEAN, two BIT STRING (SIZE(1..3)) }
SEQUENCE { null NULL, ..., one BOOLEAN, two BIT STRING (SIZE(1..3)) }
SEQUENCE { one NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)) }
SEQUENCE { null NULL, ..., one [1] NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)) }
SEQUENCE { one NULL, ..., two [2] NULL }
SEQUENCE { one [1] NULL, ..., two [2] NULL }
SEQUENCE { one [2] NULL, ..., two [1] NULL }
SEQUENCE { one [1] NULL, ..., two [3] NULL }
SEQUENCE { one [3] NULL, ..., two [1] NULL }
SEQUENCE { one [3] NULL, ..., two [1] NULL, three [2] NULL }
SEQUENCE { one [4] NULL, ..., two [3] NULL, three [1] NULL, four [2] NULL }
SEQUENCE { one [5] NULL, ..., two [4] NULL, ..., three [3] NULL, four [2] NULL }
SEQUENCE { one NULL, ..., two [2] NULL, ... }
SEQUENCE { one NULL, ..., two [2] NULL, ..., three [3] NULL }
SEQUENCE { one NULL, ..., two [2] NULL, three [3] NULL }
SEQUENCE { one BOOLEAN, ..., two [2] BOOLEAN, three [3] BOOLEAN, ... }
SEQUENCE { one BOOLEAN, ..., two BIT STRING (SIZE(1..3)) }
SEQUENCE { null NULL, ..., one BOOLEAN, two BIT STRING (SIZE(1..3)), ... }
SEQUENCE { one NULL, ..., two BOOLEAN, three BIT STRING (SIZE(1..3)) }
SEQUENCE { null NULL, ..., one [1] NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)), ... }
SEQUENCE { null NULL, ..., one [1] NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)), ..., four IA5String (SIZE(0)) }
SEQUENCE { ..., null NULL }
SEQUENCE { ..., null NULL, ... }
SEQUENCE { ..., one NULL, two [2] NULL }
SEQUENCE { ..., one [1] NULL, two [2] NULL }
SEQUENCE { ..., one [2] NULL, two [1] NULL }
SEQUENCE { ..., one [1] NULL, two [3] NULL }
SEQUENCE { ..., one [3] NULL, two [1] NULL }
SEQUENCE { ..., one [3] NULL, two [1] NULL, three [2] NULL }
SEQUENCE { ..., one [4] NULL, two [3] NULL, three [1] NULL, four [2] NULL }
SEQUENCE { ..., one [5] NULL, two [4] NULL, ..., three [3] NULL, four [2] NULL }
SEQUENCE { ..., null NULL, ..., one [5] NULL, two [4] NULL, three [3] NULL, four [2] NULL }
SEQUENCE { ..., one NULL, two [2] NULL, ... }
SEQUENCE { ..., one NULL, ..., two [2] NULL }
SEQUENCE { ..., one NULL, two [2] NULL, ..., three [3] NULL }
SEQUENCE { ..., one NULL, ..., two [2] NULL, three [3] NULL }
SEQUENCE { ..., one BOOLEAN, ..., two [2] BOOLEAN, three [3] BOOLEAN }
SEQUENCE { ..., one BOOLEAN, two BIT STRING (SIZE(1..3)) }
SEQUENCE { ..., null NULL, ..., one BOOLEAN, two BIT STRING (SIZE(1..3)) }
SEQUENCE { ..., one NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)) }
SEQUENCE { ..., null NULL, ..., one [1] NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)) }
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