Skip to content

Commit

Permalink
sbcap: Update asn1c skeleton files
Browse files Browse the repository at this point in the history
Update skeleton files using newest asn1c with APER support [1],
commit 24247e2813a7510ebabe6a9b6b6b29fffa0eb27b.

This contains some APER decoding and encoding fixes for length
determinants. See [2] for more information.

[1] https://github.com/mouse07410/asn1c/tree/vlm_master/
[2] mouse07410/asn1c#94

Change-Id: I581fc53b124a443e150508811df4cca4593038c4
  • Loading branch information
pespin committed Jul 18, 2022
1 parent ca432ad commit 3c846a7
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 134 deletions.
6 changes: 3 additions & 3 deletions src/sbcap/gen/ANY_aper.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ANY_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
int ret;

/* Get the PER length */
raw_len = aper_get_length(pd, -1, 0, &repeat);
raw_len = aper_get_length(pd, -1, -1, 0, &repeat);
if(raw_len < 0) RETURN(RC_WMORE);
if(raw_len == 0 && st->buf) break;

Expand Down Expand Up @@ -173,7 +173,7 @@ ANY_encode_aper(const asn_TYPE_descriptor_t *td,
size = st->size;
do {
int need_eom = 0;
ssize_t may_save = aper_put_length(po, -1, size, &need_eom);
ssize_t may_save = aper_put_length(po, -1, -1, size, &need_eom);
if(may_save < 0) ASN__ENCODE_FAILED;

ret = per_put_many_bits(po, buf, may_save * 8);
Expand All @@ -182,7 +182,7 @@ ANY_encode_aper(const asn_TYPE_descriptor_t *td,
buf += may_save;
size -= may_save;
assert(!(may_save & 0x07) || !size);
if(need_eom && aper_put_length(po, -1, 0, 0))
if(need_eom && aper_put_length(po, -1, -1, 0, NULL))
ASN__ENCODE_FAILED; /* End of Message length */
} while(size);

Expand Down
7 changes: 4 additions & 3 deletions src/sbcap/gen/INTEGER_aper.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ INTEGER_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
int ret;

/* Get the PER length */
len = aper_get_length(pd, -1, -1, &repeat);
len = aper_get_length(pd, -1, -1, -1, &repeat);
if(len < 0) ASN__DECODE_STARVED;

p = REALLOC(st->buf, st->size + len + 1);
Expand Down Expand Up @@ -291,13 +291,14 @@ INTEGER_encode_aper(const asn_TYPE_descriptor_t *td,

for(buf = st->buf, end = st->buf + st->size; buf < end;) {
int need_eom = 0;
ssize_t mayEncode = aper_put_length(po, -1, end - buf, &need_eom);
ssize_t mayEncode = aper_put_length(po, -1, -1, end - buf, &need_eom);
if(mayEncode < 0)
ASN__ENCODE_FAILED;
if(per_put_many_bits(po, buf, 8 * mayEncode))
ASN__ENCODE_FAILED;
buf += mayEncode;
if(need_eom && (aper_put_length(po, -1, 0, 0) < 0)) ASN__ENCODE_FAILED;
if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0))
ASN__ENCODE_FAILED;
}

ASN__ENCODED_OK(er);
Expand Down
16 changes: 8 additions & 8 deletions src/sbcap/gen/OCTET_STRING_aper.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ OCTET_STRING_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
/* Get the PER length */
if (csiz->upper_bound - csiz->lower_bound == 0)
/* Indefinite length case */
raw_len = aper_get_length(pd, -1, csiz->effective_bits, &repeat);
raw_len = aper_get_length(pd, -1, -1, csiz->effective_bits, &repeat);
else
raw_len = aper_get_length(pd, csiz->upper_bound - csiz->lower_bound + 1, csiz->effective_bits, &repeat);
raw_len = aper_get_length(pd, csiz->lower_bound, csiz->upper_bound,
csiz->effective_bits, &repeat);
if(raw_len < 0) RETURN(RC_WMORE);
raw_len += csiz->lower_bound;

Expand Down Expand Up @@ -342,9 +343,8 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td,
st->size, sizeinunits - csiz->lower_bound,
csiz->effective_bits);
if (csiz->effective_bits > 0) {
ret = aper_put_length(po,
csiz->upper_bound - csiz->lower_bound + 1,
sizeinunits - csiz->lower_bound, 0);
ret = aper_put_length(po, csiz->lower_bound, csiz->upper_bound,
sizeinunits - csiz->lower_bound, NULL);
if(ret < 0) ASN__ENCODE_FAILED;
}
if (csiz->effective_bits > 0 || (st->size > 2)
Expand Down Expand Up @@ -372,15 +372,15 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td,
ASN_DEBUG("Encoding %lu bytes", st->size);

if(sizeinunits == 0) {
if(aper_put_length(po, -1, 0, 0) < 0)
if(aper_put_length(po, -1, -1, 0, NULL) < 0)
ASN__ENCODE_FAILED;
ASN__ENCODED_OK(er);
}

buf = st->buf;
while(sizeinunits) {
int need_eom = 0;
ssize_t maySave = aper_put_length(po, -1, sizeinunits, &need_eom);
ssize_t maySave = aper_put_length(po, -1, -1, sizeinunits, &need_eom);

if(maySave < 0) ASN__ENCODE_FAILED;

Expand All @@ -404,7 +404,7 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td,
buf += maySave >> 3;
sizeinunits -= maySave;
assert(!(maySave & 0x07) || !sizeinunits);
if(need_eom && (aper_put_length(po, -1, 0, 0) < 0))
if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0))
ASN__ENCODE_FAILED; /* End of Message length */
}

Expand Down
3 changes: 1 addition & 2 deletions src/sbcap/gen/OPEN_TYPE_aper.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ OPEN_TYPE_aper_unknown_type_discard_bytes (asn_per_data_t *pd) {
rv.code = RC_FAIL;

do {
bytes = aper_get_length(pd, -1, -1, &repeat);
bytes = aper_get_length(pd, -1, -1, -1, &repeat);
if (bytes > 10 * ASN_DUMMY_BYTES)
{
return rv;
Expand All @@ -171,4 +171,3 @@ OPEN_TYPE_aper_unknown_type_discard_bytes (asn_per_data_t *pd) {
return rv;
#undef ASN_DUMMY_BYTES
}

6 changes: 3 additions & 3 deletions src/sbcap/gen/aper_opentype.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ aper_open_type_get_simple(const asn_codec_ctx_t *ctx,
ASN_DEBUG("Getting open type %s...", td->name);

do {
chunk_bytes = aper_get_length(pd, -1, -1, &repeat);
chunk_bytes = aper_get_length(pd, -1, -1, -1, &repeat);
if(chunk_bytes < 0) {
FREEMEM(buf);
ASN__DECODE_STARVED;
Expand Down Expand Up @@ -101,12 +101,12 @@ aper_open_type_put(const asn_TYPE_descriptor_t *td,

for(bptr = buf, toGo = size; toGo;) {
int need_eom = 0;
ssize_t maySave = aper_put_length(po, -1, toGo, &need_eom);
ssize_t maySave = aper_put_length(po, -1, -1, toGo, &need_eom);
if(maySave < 0) break;
if(per_put_many_bits(po, bptr, maySave * 8)) break;
bptr = (char *)bptr + maySave;
toGo -= maySave;
if(need_eom && (aper_put_length(po, -1, 0, 0) < 0)) {
if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0)) {
FREEMEM(buf);
return -1;
}
Expand Down
160 changes: 58 additions & 102 deletions src/sbcap/gen/aper_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ aper_get_align(asn_per_data_t *pd) {
}

ssize_t
aper_get_length(asn_per_data_t *pd, int range, int ebits, int *repeat) {
aper_get_length(asn_per_data_t *pd, ssize_t lb, ssize_t ub,
int ebits, int *repeat) {
int constrained = (lb >= 0) && (ub >= 0);
ssize_t value;

*repeat = 0;

if (range <= 65536 && range >= 0)
if (constrained && ub < 65536) {
int range = ub - lb + 1;
return aper_get_nsnnwn(pd, range);
}

if (aper_get_align(pd) < 0)
return -1;
Expand All @@ -32,14 +36,14 @@ aper_get_length(asn_per_data_t *pd, int range, int ebits, int *repeat) {

value = per_get_few_bits(pd, 8);
if(value < 0) return -1;
if((value & 128) == 0) /* #10.9.3.6 */
if((value & 128) == 0) /* #11.9.3.6 */
return (value & 0x7F);
if((value & 64) == 0) { /* #10.9.3.7 */
if((value & 64) == 0) { /* #11.9.3.7 */
value = ((value & 63) << 8) | per_get_few_bits(pd, 8);
if(value < 0) return -1;
return value;
}
value &= 63; /* this is "m" from X.691, #10.9.3.8 */
value &= 63; /* this is "m" from X.691, #11.9.3.8 */
if(value < 1 || value > 4)
return -1;
*repeat = 1;
Expand All @@ -59,13 +63,12 @@ aper_get_nslength(asn_per_data_t *pd) {
return length;
} else {
int repeat;
length = aper_get_length(pd, -1, -1, &repeat);
length = aper_get_length(pd, -1, -1, -1, &repeat);
if(length >= 0 && !repeat) return length;
return -1; /* Error, or do not support >16K extensions */
}
}

#if !defined(USE_OLDER_APER_NSNNWN)
ssize_t
aper_get_nsnnwn(asn_per_data_t *pd, int range) {
ssize_t value;
Expand Down Expand Up @@ -95,53 +98,28 @@ aper_get_nsnnwn(asn_per_data_t *pd, int range) {
//return -1;
int length;

/* handle indefinite range */
length = per_get_few_bits(pd, 1);
if (length == 0)
return per_get_few_bits(pd, 6);

if (aper_get_align(pd) < 0)
return -1;

length = per_get_few_bits(pd, 8);
/* the length is not likely to be that big */
if (length > 4)
return -1;
value = 0;
if (per_get_many_bits(pd, (uint8_t *)&value, 0, length * 8) < 0)
return -1;
return value;
/* handle indefinite range */
length = per_get_few_bits(pd, 1);
if (length == 0)
return per_get_few_bits(pd, 6);

if (aper_get_align(pd) < 0)
return -1;

length = per_get_few_bits(pd, 8);
/* the length is not likely to be that big */
if (length > 4)
return -1;
value = 0;
if (per_get_many_bits(pd, (uint8_t *)&value, 0, length * 8) < 0)
return -1;
return value;
}
if (aper_get_align(pd) < 0)
return -1;
value = per_get_few_bits(pd, 8 * bytes);
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) {

Expand All @@ -154,50 +132,54 @@ int aper_put_align(asn_per_outp_t *po) {
}

ssize_t
aper_put_length(asn_per_outp_t *po, int range, size_t length, int *need_eom) {
int dummy = 0;
if(!need_eom) need_eom = &dummy;
aper_put_length(asn_per_outp_t *po, ssize_t lb, ssize_t ub, size_t n, int *need_eom) {
int constrained = (lb >= 0) && (ub >= 0);
int dummy = 0;
if(!need_eom) need_eom = &dummy;

*need_eom = 0;

*need_eom = 0;

ASN_DEBUG("APER put length %zu with range %d", length, range);
ASN_DEBUG("APER put length %zu with range (%zd..%zd)", n, lb, ub);

/* 10.9 X.691 Note 2 */
if (range <= 65536 && range >= 0)
return aper_put_nsnnwn(po, range, length) ? -1 : (ssize_t)length;
/* 11.9 X.691 Note 2 */
if (constrained && ub < 65536) {
int range = ub - lb + 1;
return aper_put_nsnnwn(po, range, n) ? -1 : (ssize_t)n;
}

if (aper_put_align(po) < 0)
return -1;

if(length <= 127) /* #10.9.3.6 */{
return per_put_few_bits(po, length, 8)
? -1 : (ssize_t)length;
if(n <= 127) { /* #11.9.3.6 */
return per_put_few_bits(po, n, 8)
? -1 : (ssize_t)n;
}
else if(n < 16384) /* #11.9.3.7 */
return per_put_few_bits(po, n|0x8000, 16)
? -1 : (ssize_t)n;

*need_eom = 0 == (n & 16383);
n >>= 14;
if(n > 4) {
*need_eom = 0;
n = 4;
}
else if(length < 16384) /* #10.9.3.7 */
return per_put_few_bits(po, length|0x8000, 16)
? -1 : (ssize_t)length;

*need_eom = 0 == (length & 16383);
length >>= 14;
if(length > 4) {
*need_eom = 0;
length = 4;
}

return per_put_few_bits(po, 0xC0 | length, 8)
? -1 : (ssize_t)(length << 14);

return per_put_few_bits(po, 0xC0 | n, 8)
? -1 : (ssize_t)(n << 14);
}


int
aper_put_nslength(asn_per_outp_t *po, size_t length) {

if(length <= 64) {
/* #10.9.3.4 */
/* #11.9.3.4 */
if(length == 0) return -1;
return per_put_few_bits(po, length-1, 7) ? -1 : 0;
} else {
if(aper_put_length(po, -1, length, 0) != (ssize_t)length) {
if(aper_put_length(po, -1, -1, length, NULL) != (ssize_t)length) {
/* This might happen in case of >16K extensions */
return -1;
}
Expand All @@ -206,12 +188,11 @@ aper_put_nslength(asn_per_outp_t *po, size_t length) {
return 0;
}

#if !defined(USE_OLDER_APER_NSNNWN)
int
aper_put_nsnnwn(asn_per_outp_t *po, int range, int number) {
int bytes;

ASN_DEBUG("aper put nsnnwn %d with range %d", number, range);
ASN_DEBUG("aper put nsnnwn %d with range %d", number, range);
/* 10.5.7.1 X.691 */
if(range < 0) {
int i;
Expand Down Expand Up @@ -254,30 +235,5 @@ aper_put_nsnnwn(asn_per_outp_t *po, int range, int number) {
/* if(per_put_few_bits(po, bytes, 8))
return -1;
*/
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);
return per_put_few_bits(po, number, 8 * bytes);
}
#endif /* which aper_put_nsnnwn() */
Loading

0 comments on commit 3c846a7

Please sign in to comment.