Add a copy of aper_get_nsnnwn() and aper_put_nsnnwn() to per_support.c, just in case.

They're disabled by default, but can be turned on by defining USE_OLDER_APER_NSNNWN.
The main difference is - these do not use "range" argument, but receive it as dummy.
parent 46dcd14a
...@@ -369,6 +369,7 @@ aper_get_nslength(asn_per_data_t *pd) { ...@@ -369,6 +369,7 @@ aper_get_nslength(asn_per_data_t *pd) {
} }
} }
#if !defined(USE_OLDER_APER_NSNNWN)
ssize_t ssize_t
aper_get_nsnnwn(asn_per_data_t *pd, int range) { aper_get_nsnnwn(asn_per_data_t *pd, int range) {
ssize_t value; ssize_t value;
...@@ -402,6 +403,31 @@ aper_get_nsnnwn(asn_per_data_t *pd, int range) { ...@@ -402,6 +403,31 @@ aper_get_nsnnwn(asn_per_data_t *pd, int range) {
value = per_get_few_bits(pd, 8 * bytes); value = per_get_few_bits(pd, 8 * bytes);
return value; return value;
} }
#else /* old APER codec */
ssize_t
aper_get_nsnnwn(asn_per_data_t *pd, int dummy_range) {
ssize_t value;
ASN_DEBUG("Get the normally small non-negative whole number APER");
value = per_get_few_bits(pd, 7);
if(value & 64) { /* implicit (value < 0) */
value &= 63;
value <<= 2;
value |= per_get_few_bits(pd, 2);
if(value & 128) /* implicit (value < 0) */
return -1;
if(value == 0)
return 0;
if(value >= 3)
return -1;
value = per_get_few_bits(pd, 8 * value);
return value;
}
return value;
}
#endif /* don't use old APER */
int aper_put_align(asn_per_outp_t *po) { int aper_put_align(asn_per_outp_t *po) {
...@@ -458,6 +484,7 @@ aper_put_nslength(asn_per_outp_t *po, size_t length) { ...@@ -458,6 +484,7 @@ aper_put_nslength(asn_per_outp_t *po, size_t length) {
return 0; return 0;
} }
#if !defined(USE_OLDER_APER_NSNNWN)
int int
aper_put_nsnnwn(asn_per_outp_t *po, int range, int number) { aper_put_nsnnwn(asn_per_outp_t *po, int range, int number) {
int bytes; int bytes;
...@@ -503,3 +530,28 @@ aper_put_nsnnwn(asn_per_outp_t *po, int range, int number) { ...@@ -503,3 +530,28 @@ aper_put_nsnnwn(asn_per_outp_t *po, int range, int number) {
*/ */
return per_put_few_bits(po, number, 8 * bytes); return per_put_few_bits(po, number, 8 * bytes);
} }
#else /* preserve old code base in case */
int
aper_put_nsnnwn(asn_per_outp_t *po, int dummy_range, int n) {
int bytes;
ASN_DEBUG("aper_put_nsnnwn");
if(n <= 63) {
if(n < 0) return -1;
return per_put_few_bits(po, n, 7);
}
if(n < 256)
bytes = 1;
else if(n < 65536)
bytes = 2;
else if(n < 256 * 65536)
bytes = 3;
else
return -1; /* This is not a "normally small" value */
if(per_put_few_bits(po, bytes, 8))
return -1;
return per_put_few_bits(po, n, 8 * bytes);
}
#endif /* which aper_put_nsnnwn() */
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