Commit f2e1d207 authored by Pau Espin Pedrol's avatar Pau Espin Pedrol Committed by Mouse

aper: Fix encoding OCTET_STRING with constrained size

parent 798a79fb
...@@ -345,7 +345,7 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td, ...@@ -345,7 +345,7 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td,
ret = aper_put_length(po, ret = aper_put_length(po,
csiz->upper_bound - csiz->lower_bound + 1, csiz->upper_bound - csiz->lower_bound + 1,
sizeinunits - csiz->lower_bound, 0); sizeinunits - csiz->lower_bound, 0);
if(ret) ASN__ENCODE_FAILED; if(ret < 0) ASN__ENCODE_FAILED;
} }
if (csiz->effective_bits > 0 || (st->size > 2) if (csiz->effective_bits > 0 || (st->size > 2)
|| (csiz->upper_bound > (2 * 8 / unit_bits)) || (csiz->upper_bound > (2 * 8 / unit_bits))
...@@ -372,7 +372,7 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td, ...@@ -372,7 +372,7 @@ OCTET_STRING_encode_aper(const asn_TYPE_descriptor_t *td,
ASN_DEBUG("Encoding %lu bytes", st->size); ASN_DEBUG("Encoding %lu bytes", st->size);
if(sizeinunits == 0) { if(sizeinunits == 0) {
if(aper_put_length(po, -1, 0, 0)) if(aper_put_length(po, -1, 0, 0) < 0)
ASN__ENCODE_FAILED; ASN__ENCODE_FAILED;
ASN__ENCODED_OK(er); ASN__ENCODED_OK(er);
} }
......
...@@ -32,9 +32,8 @@ encode_constrained_size(char *orig, char *encoded, long lbound, unsigned long ub ...@@ -32,9 +32,8 @@ encode_constrained_size(char *orig, char *encoded, long lbound, unsigned long ub
asn_enc_rval_t er; asn_enc_rval_t er;
struct asn_per_constraints_s cts; struct asn_per_constraints_s cts;
asn_per_outp_t po; asn_per_outp_t po;
#if 0
char *out_str; char *out_str;
#endif
memset(&os, 0, sizeof(os)); memset(&os, 0, sizeof(os));
OCTET_STRING_fromString(&os, orig); OCTET_STRING_fromString(&os, orig);
...@@ -60,8 +59,7 @@ encode_constrained_size(char *orig, char *encoded, long lbound, unsigned long ub ...@@ -60,8 +59,7 @@ encode_constrained_size(char *orig, char *encoded, long lbound, unsigned long ub
er = OCTET_STRING_encode_aper(&asn_DEF_OCTET_STRING, &cts, &os, &po); er = OCTET_STRING_encode_aper(&asn_DEF_OCTET_STRING, &cts, &os, &po);
assert(er.encoded < 0); /* BUG! it should be >= 0 */ assert(er.encoded >= 0);
#if 0
unsigned l = (po.buffer - po.tmpspace) + (po.nboff + 7)/8; unsigned l = (po.buffer - po.tmpspace) + (po.nboff + 7)/8;
memcpy(&buf[er.encoded], po.tmpspace, l); memcpy(&buf[er.encoded], po.tmpspace, l);
er.encoded += l; er.encoded += l;
...@@ -72,7 +70,6 @@ encode_constrained_size(char *orig, char *encoded, long lbound, unsigned long ub ...@@ -72,7 +70,6 @@ encode_constrained_size(char *orig, char *encoded, long lbound, unsigned long ub
printf("Orig: [%s], encoded: [%s], check [%s]\n", printf("Orig: [%s], encoded: [%s], check [%s]\n",
orig, out_str, encoded); orig, out_str, encoded);
assert(strcmp(out_str, encoded) == 0); assert(strcmp(out_str, encoded) == 0);
#endif
ASN_STRUCT_RESET(asn_DEF_OCTET_STRING, &os); ASN_STRUCT_RESET(asn_DEF_OCTET_STRING, &os);
} }
......
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