Skip to content

Commit

Permalink
Make APER encoding/decoding of constrained OCTET_STRING correct
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse07410 committed Aug 21, 2024
1 parent 1ad922d commit 8d05d71
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions skeletons/OCTET_STRING_aper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/*
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 8d05d71

Please sign in to comment.