unsigned integer of 32-bit widtth support for per
diff --git a/skeletons/INTEGER.c b/skeletons/INTEGER.c
index a51dd11..54a402b 100644
--- a/skeletons/INTEGER.c
+++ b/skeletons/INTEGER.c
@@ -158,7 +158,9 @@
} else {
scrsize = sizeof(scratch);
scr = scratch;
- ret = snprintf(scr, scrsize, "%ld", accum);
+ ret = snprintf(scr, scrsize,
+ (specs && specs->field_unsigned)
+ ?"%lu":"%ld", accum);
}
assert(ret > 0 && (size_t)ret < scrsize);
return (cb(scr, ret, app_key) < 0) ? -1 : ret;
@@ -554,6 +556,7 @@
asn_dec_rval_t
INTEGER_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+ asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
asn_dec_rval_t rval = { RC_OK, 0 };
INTEGER_t *st = (INTEGER_t *)*sptr;
asn_per_constraint_t *ct;
@@ -611,7 +614,9 @@
ASN_DEBUG("Got value %ld + low %ld",
value, ct->lower_bound);
value += ct->lower_bound;
- if(asn_long2INTEGER(st, value))
+ if((specs && specs->field_unsigned)
+ ? asn_ulong2INTEGER(st, value)
+ : asn_long2INTEGER(st, value))
_ASN_DECODE_FAILED;
return rval;
}
@@ -657,6 +662,7 @@
asn_enc_rval_t
INTEGER_encode_uper(asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
+ asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
asn_enc_rval_t er;
INTEGER_t *st = (INTEGER_t *)sptr;
const uint8_t *buf;
@@ -673,21 +679,41 @@
if(ct) {
int inext = 0;
- if(asn_INTEGER2long(st, &value))
- _ASN_ENCODE_FAILED;
- /* Check proper range */
- if(ct->flags & APC_SEMI_CONSTRAINED) {
- if(value < ct->lower_bound)
- inext = 1;
- } else if(ct->range_bits >= 0) {
- if(value < ct->lower_bound
- || value > ct->upper_bound)
- inext = 1;
+ if(specs && specs->field_unsigned) {
+ unsigned long uval;
+ if(asn_INTEGER2ulong(st, &uval))
+ _ASN_ENCODE_FAILED;
+ /* Check proper range */
+ if(ct->flags & APC_SEMI_CONSTRAINED) {
+ if(uval < (unsigned long)ct->lower_bound)
+ inext = 1;
+ } else if(ct->range_bits >= 0) {
+ if(uval < (unsigned long)ct->lower_bound
+ || uval > (unsigned long)ct->upper_bound)
+ inext = 1;
+ }
+ ASN_DEBUG("Value %lu (%02x/%d) lb %lu ub %lu %s",
+ uval, st->buf[0], st->size,
+ ct->lower_bound, ct->upper_bound,
+ inext ? "ext" : "fix");
+ value = uval;
+ } else {
+ if(asn_INTEGER2long(st, &value))
+ _ASN_ENCODE_FAILED;
+ /* Check proper range */
+ if(ct->flags & APC_SEMI_CONSTRAINED) {
+ if(value < ct->lower_bound)
+ inext = 1;
+ } else if(ct->range_bits >= 0) {
+ if(value < ct->lower_bound
+ || value > ct->upper_bound)
+ inext = 1;
+ }
+ ASN_DEBUG("Value %ld (%02x/%d) lb %ld ub %ld %s",
+ value, st->buf[0], st->size,
+ ct->lower_bound, ct->upper_bound,
+ inext ? "ext" : "fix");
}
- ASN_DEBUG("Value %ld (%02x/%d) lb %ld ub %ld %s",
- value, st->buf[0], st->size,
- ct->lower_bound, ct->upper_bound,
- inext ? "ext" : "fix");
if(ct->flags & APC_EXTENSIBLE) {
if(per_put_few_bits(po, inext, 1))
_ASN_ENCODE_FAILED;
diff --git a/skeletons/INTEGER.h b/skeletons/INTEGER.h
index b87c794..8411bfc 100644
--- a/skeletons/INTEGER.h
+++ b/skeletons/INTEGER.h
@@ -30,6 +30,8 @@
int map_count; /* Elements in either map */
int extension; /* This map is extensible */
int strict_enumeration; /* Enumeration set is fixed */
+ int field_width; /* Size of native integer */
+ int field_unsigned; /* Signed=0, unsigned=1 */
} asn_INTEGER_specifics_t;
asn_struct_print_f INTEGER_print;
diff --git a/skeletons/NativeEnumerated.c b/skeletons/NativeEnumerated.c
index b6b47e1..1554220 100644
--- a/skeletons/NativeEnumerated.c
+++ b/skeletons/NativeEnumerated.c
@@ -196,7 +196,7 @@
/*
* X.691, #10.6: normally small non-negative whole number;
*/
- ASN_DEBUG("value = %d, ext = %d, inext = %d, res = %d",
+ ASN_DEBUG("value = %ld, ext = %d, inext = %d, res = %ld",
value, specs->extension, inext,
value - (inext ? (specs->extension - 1) : 0));
if(uper_put_nsnnwn(po, value - (inext ? (specs->extension - 1) : 0)))
diff --git a/skeletons/NativeInteger.c b/skeletons/NativeInteger.c
index b251ee7..abdb71a 100644
--- a/skeletons/NativeInteger.c
+++ b/skeletons/NativeInteger.c
@@ -48,6 +48,7 @@
NativeInteger_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td,
void **nint_ptr, const void *buf_ptr, size_t size, int tag_mode) {
+ asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
long *native = (long *)*nint_ptr;
asn_dec_rval_t rval;
ber_tlv_len_t length;
@@ -105,7 +106,9 @@
tmp.buf = (uint8_t *)unconst_buf.nonconstbuf;
tmp.size = length;
- if(asn_INTEGER2long(&tmp, &l)) {
+ if((specs&&specs->field_unsigned)
+ ? asn_INTEGER2ulong(&tmp, &l)
+ : asn_INTEGER2long(&tmp, &l)) {
rval.code = RC_FAIL;
rval.consumed = 0;
return rval;
@@ -167,6 +170,7 @@
NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
const void *buf_ptr, size_t size) {
+ asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
asn_dec_rval_t rval;
INTEGER_t st;
void *st_ptr = (void *)&st;
@@ -182,7 +186,9 @@
opt_mname, buf_ptr, size);
if(rval.code == RC_OK) {
long l;
- if(asn_INTEGER2long(&st, &l)) {
+ if((specs&&specs->field_unsigned)
+ ? asn_INTEGER2ulong(&st, &l)
+ : asn_INTEGER2long(&st, &l)) {
rval.code = RC_FAIL;
rval.consumed = 0;
} else {
@@ -205,6 +211,7 @@
NativeInteger_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
+ asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
char scratch[32]; /* Enough for 64-bit int */
asn_enc_rval_t er;
const long *native = (const long *)sptr;
@@ -214,7 +221,9 @@
if(!native) _ASN_ENCODE_FAILED;
- er.encoded = snprintf(scratch, sizeof(scratch), "%ld", *native);
+ er.encoded = snprintf(scratch, sizeof(scratch),
+ (specs && specs->field_unsigned)
+ ? "%lu" : "%ld", *native);
if(er.encoded <= 0 || (size_t)er.encoded >= sizeof(scratch)
|| cb(scratch, er.encoded, app_key) < 0)
_ASN_ENCODE_FAILED;
@@ -227,6 +236,7 @@
asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+ asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
asn_dec_rval_t rval;
long *native = (long *)*sptr;
INTEGER_t tmpint;
@@ -244,7 +254,9 @@
rval = INTEGER_decode_uper(opt_codec_ctx, td, constraints,
&tmpintptr, pd);
if(rval.code == RC_OK) {
- if(asn_INTEGER2long(&tmpint, native))
+ if((specs&&specs->field_unsigned)
+ ? asn_INTEGER2ulong(&tmpint, native)
+ : asn_INTEGER2long(&tmpint, native))
rval.code = RC_FAIL;
else
ASN_DEBUG("NativeInteger %s got value %ld",
@@ -258,6 +270,7 @@
asn_enc_rval_t
NativeInteger_encode_uper(asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
+ asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
asn_enc_rval_t er;
long native;
INTEGER_t tmpint;
@@ -269,7 +282,9 @@
ASN_DEBUG("Encoding NativeInteger %s %ld (UPER)", td->name, native);
memset(&tmpint, 0, sizeof(tmpint));
- if(asn_long2INTEGER(&tmpint, native))
+ if((specs&&specs->field_unsigned)
+ ? asn_ulong2INTEGER(&tmpint, native)
+ : asn_long2INTEGER(&tmpint, native))
_ASN_ENCODE_FAILED;
er = INTEGER_encode_uper(td, constraints, &tmpint, po);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
@@ -282,6 +297,7 @@
int
NativeInteger_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) {
+ asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
const long *native = (const long *)sptr;
char scratch[32]; /* Enough for 64-bit int */
int ret;
@@ -290,7 +306,9 @@
(void)ilevel; /* Unused argument */
if(native) {
- ret = snprintf(scratch, sizeof(scratch), "%ld", *native);
+ ret = snprintf(scratch, sizeof(scratch),
+ (specs && specs->field_unsigned)
+ ? "%lu" : "%ld", *native);
assert(ret > 0 && (size_t)ret < sizeof(scratch));
return (cb(scratch, ret, app_key) < 0) ? -1 : 0;
} else {