Commit 8d05d716 authored by Mouse's avatar Mouse

Make APER encoding/decoding of constrained OCTET_STRING correct

parent 1ad922db
......@@ -61,28 +61,36 @@ OCTET_STRING_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
switch(specs->subvariant) {
case ASN_OSUBV_ANY:
canonical_unit_bits = unit_bits = 8;
if(cval->flags & APC_CONSTRAINED)
unit_bits = cval->range_bits;
bpc = OS__BPC_CHAR;
break;
case ASN_OSUBV_STR:
canonical_unit_bits = unit_bits = 8;
/*
if(cval->flags & APC_CONSTRAINED)
unit_bits = cval->range_bits;
*/
if(cval->flags & APC_CONSTRAINED) {
/* follow power of 2 rule */
if (cval->range_bits <= 2) {
unit_bits = 2;
} else {
if (cval->range_bits <= 4) {
unit_bits = 4;
/* otherwise, unit_bits = 8; */
}
}
/* unit_bits = cval->range_bits; */
ASN_DEBUG("APER decoding ASN_OSUBV_STR range_bits = %d unit_bits = %d\n",
cval->range_bits, unit_bits);
}
bpc = OS__BPC_CHAR;
break;
case ASN_OSUBV_U16:
canonical_unit_bits = unit_bits = 16;
if(cval->flags & APC_CONSTRAINED)
if(cval->flags & APC_CONSTRAINED) {
unit_bits = cval->range_bits;
ASN_DEBUG("APER decoding ASN_OSUBV_U16 range_bits = %d\n", cval->range_bits);
}
bpc = OS__BPC_U16;
break;
case ASN_OSUBV_U32:
canonical_unit_bits = unit_bits = 32;
if(cval->flags & APC_CONSTRAINED)
if(cval->flags & APC_CONSTRAINED) {
unit_bits = cval->range_bits;
ASN_DEBUG("APER decoding ASN_OSUBV_U32 range_bits = %d\n", cval->range_bits);
}
bpc = OS__BPC_U32;
break;
/*
......@@ -275,30 +283,37 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td,
switch(specs->subvariant) {
case ASN_OSUBV_ANY:
canonical_unit_bits = unit_bits = 8;
if(cval->flags & APC_CONSTRAINED)
unit_bits = 8;
bpc = OS__BPC_CHAR;
break;
case ASN_OSUBV_STR:
canonical_unit_bits = unit_bits = 8;
/*
if(cval->flags & APC_CONSTRAINED)
unit_bits = 8;
*/
if(cval->flags & APC_CONSTRAINED) {
/* follow power of 2 rule */
if (cval->range_bits <= 2) {
unit_bits = 2;
} else {
if (cval->range_bits <= 4)
unit_bits = 4;
/* otherwise, unit_bits = 8; */
}
/* unit_bits = cval->range_bits; */
ASN_DEBUG("APER encoding ASN_OSUBV_STR range_bits = %d unit_bits = %d\n",
cval->range_bits, unit_bits);
}
bpc = OS__BPC_CHAR;
sizeinunits = st->size;
break;
case ASN_OSUBV_U16:
canonical_unit_bits = unit_bits = 16;
if(cval->flags & APC_CONSTRAINED)
if(cval->flags & APC_CONSTRAINED) {
unit_bits = cval->range_bits;
ASN_DEBUG("APER encoding ASN_OSUBV_U16 range_bits = %d\n", cval->range_bits);
}
bpc = OS__BPC_U16;
sizeinunits = st->size / 2;
break;
case ASN_OSUBV_U32:
canonical_unit_bits = unit_bits = 32;
if(cval->flags & APC_CONSTRAINED)
if(cval->flags & APC_CONSTRAINED) {
unit_bits = cval->range_bits;
ASN_DEBUG("APER encoding ASN_OSUBV_U32 range_bits = %d\n", cval->range_bits);
}
bpc = OS__BPC_U32;
sizeinunits = st->size / 4;
break;
......@@ -311,8 +326,7 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td,
canonical_unit_bits = unit_bits = 1;
bpc = OS__BPC_BIT;
sizeinunits = st->size * 8 - (st->bits_unused & 0x07);
ASN_DEBUG("BIT STRING of %d bytes",
sizeinunits);
ASN_DEBUG("BIT STRING of %d bytes", sizeinunits);
break;
}
......
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