aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-12-19 13:32:58 +0100
committerHarald Welte <laforge@gnumonks.org>2016-01-04 16:40:27 +0100
commit0ff796f0363143eddbf87ba7500e07418a905dd7 (patch)
tree4a5ad9aba10906c6912aa7d6f181302f364091ef
parent6e00cbce7304a6972e82a12bb5fa82e41fa541be (diff)
APER: Fix encoding of INTEGER with lower_bound != 0
When encoding an INTEGER, we need to subtract the lower bound before encoding the value. This is specified in Clause 10.5.7.x of X.691. The decoder already does this correct, but the encoder was wrong.
-rw-r--r--skeletons/INTEGER.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/skeletons/INTEGER.c b/skeletons/INTEGER.c
index c74c5b4d..9ba14bc7 100644
--- a/skeletons/INTEGER.c
+++ b/skeletons/INTEGER.c
@@ -972,28 +972,29 @@ INTEGER_encode_aper(asn_TYPE_descriptor_t *td,
/* X.691, #12.2.2 */
if(ct && ct->range_bits >= 0) {
/* #10.5.6 */
- ASN_DEBUG("Encoding integer with range %d bits",
- ct->range_bits);
+ ASN_DEBUG("Encoding integer %ld (%lu) with range %d bits",
+ value, value - ct->lower_bound, ct->range_bits);
+ unsigned long v = value - ct->lower_bound;
/* #12 <= 8 -> alignment ? */
if (ct->range_bits < 8) {
- if(per_put_few_bits(po, 0x00 | value, ct->range_bits))
+ if(per_put_few_bits(po, 0x00 | v, ct->range_bits))
_ASN_ENCODE_FAILED;
} else if (ct->range_bits == 8) {
if(aper_put_align(po) < 0)
_ASN_ENCODE_FAILED;
- if(per_put_few_bits(po, 0x00 | value, ct->range_bits))
+ if(per_put_few_bits(po, 0x00 | v, ct->range_bits))
_ASN_ENCODE_FAILED;
} else if (ct->range_bits <= 16) {
// Consume the bytes to align on octet
if(aper_put_align(po) < 0)
_ASN_ENCODE_FAILED;
- if(per_put_few_bits(po, 0x0000 | value,
+ if(per_put_few_bits(po, 0x0000 | v,
16))
_ASN_ENCODE_FAILED;
} else {
/* TODO: extend to >64 bits */
- int64_t v = value;
+ int64_t v64 = v;
int i;
/* Putting length - 1 in the minimum number of bits ex: 5 = 3bits */
@@ -1005,7 +1006,7 @@ INTEGER_encode_aper(asn_TYPE_descriptor_t *td,
_ASN_ENCODE_FAILED;
/* Put the value */
for (i = 0; i < st->size; i++) {
- if(per_put_few_bits(po, (v >> (8 * (st->size - i - 1))) & 0xff, 8)) _ASN_ENCODE_FAILED;
+ if(per_put_few_bits(po, (v64 >> (8 * (st->size - i - 1))) & 0xff, 8)) _ASN_ENCODE_FAILED;
}
}
_ASN_ENCODED_OK(er);