Commit 4118ccf9 authored by Lev Walkin's avatar Lev Walkin

simplify numeric constraints checking in runtime

parent 5861e8a0
...@@ -41,6 +41,8 @@ static int expr_break_recursion(arg_t *arg, asn1p_expr_t *expr); ...@@ -41,6 +41,8 @@ static int expr_break_recursion(arg_t *arg, asn1p_expr_t *expr);
static int expr_as_xmlvaluelist(arg_t *arg, asn1p_expr_t *expr); static int expr_as_xmlvaluelist(arg_t *arg, asn1p_expr_t *expr);
static int expr_elements_count(arg_t *arg, asn1p_expr_t *expr); static int expr_elements_count(arg_t *arg, asn1p_expr_t *expr);
static int emit_single_member_OER_constraint(arg_t *arg, asn1cnst_range_t *range, char *type); static int emit_single_member_OER_constraint(arg_t *arg, asn1cnst_range_t *range, char *type);
static int emit_single_member_OER_constraint_value(arg_t *arg, asn1cnst_range_t *range, char *type);
static int emit_single_member_OER_constraint_size(arg_t *arg, asn1cnst_range_t *range, char *type);
static int emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int juscountvalues, char *type); static int emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int juscountvalues, char *type);
static int emit_member_OER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx); static int emit_member_OER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx);
static int emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx); static int emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx);
...@@ -1954,17 +1956,117 @@ PER_FROM_alphabet_characters(asn1cnst_range_t *range) { ...@@ -1954,17 +1956,117 @@ PER_FROM_alphabet_characters(asn1cnst_range_t *range) {
return numchars; return numchars;
} }
static void
emit_single_member_OER_constraint_comment(arg_t *arg, asn1cnst_range_t *range, char *type) {
/*
* Print some courtesy debug information.
*/
if(range
&& (range->left.type == ARE_VALUE || range->right.type == ARE_VALUE)) {
OUT("\t/* ");
if(type) OUT("(%s", type);
OUT("(");
if(range->left.type == ARE_VALUE)
OUT("%" PRIdASN, range->left.value);
else
OUT("MIN");
OUT("..");
if(range->right.type == ARE_VALUE)
OUT("%" PRIdASN, range->right.value);
else
OUT("MAX");
if(range->extensible) OUT(",...");
if(type) OUT(")");
OUT(") */");
}
}
static int static int
emit_single_member_OER_constraint(arg_t *arg, asn1cnst_range_t *range, char *type) { emit_single_member_OER_constraint_value(arg_t *arg, asn1cnst_range_t *range, char *type) {
if(!range) { if(!range) {
/* oer_support.h: asn_oer_constraint_s */ /* oer_support.h: asn_oer_constraint_s */
OUT("{ 0, 0, 0 }"); OUT("{ 0, 0 }");
return 0; return 0;
} }
if(range->incompatible || range->not_OER_visible) { if(range->incompatible || range->not_OER_visible) {
OUT("{ 0, 0, 0 }"); OUT("{ 0, 0 }");
} else { } else if(range->left.type == ARE_VALUE &&
range->right.type == ARE_VALUE) {
asn1c_integer_t lb = range->left.value;
asn1c_integer_t ub = range->right.value;
unsigned width = 0;
unsigned positive = 0;
if(lb >= 0) {
/* X.969 08/2015 10.2(a) */
if(ub <= 255) {
width = 1;
} else if(ub <= 65535) {
width = 2;
} else if(ub <= 4294967295UL) {
width = 4;
} else if(ub <= 18446744073709551615ULL) {
width = 8;
}
positive = 1;
} else {
positive = 0;
/* X.969 08/2015 10.2(b) - no lower bound or negative lower bound */
if(lb >= -128 && ub <= 127) {
width = 1;
} else if(lb >= -32768 && ub <= 32767) {
width = 2;
} else if(lb >= -2147483648L && ub <= 2147483647L) {
width = 4;
} else if(lb >= -9223372036854775808LL
&& ub <= 9223372036854775807LL) {
width = 8;
}
}
OUT("{ %u, %u }", width, positive);
} else {
OUT("{ 0, 0 }");
}
return 0;
}
static int
emit_single_member_OER_constraint_size(arg_t *arg, asn1cnst_range_t *range, char *type) {
if(!range) {
/* oer_support.h: asn_oer_constraint_s */
OUT("-1");
return 0;
}
if(range->incompatible || range->not_OER_visible) {
OUT("-1");
} else {
if(range->left.type == ARE_VALUE && range->right.type == ARE_VALUE
&& range->left.value == range->right.value
&& range->left.value >= 0) {
OUT("%" PRIdMAX "", range->left.value);
} else {
OUT("-1");
}
}
return 0;
}
static int
emit_single_member_OER_constraint(arg_t *arg, asn1cnst_range_t *range, char *type) {
if(!range) {
/* oer_support.h: asn_oer_constraint_s */
OUT("{ 0, 0, 0 }");
return 0;
}
if(range->incompatible || range->not_OER_visible) {
OUT("{ 0, 0, 0 }");
} else {
if(range->left.type == ARE_VALUE) { if(range->left.type == ARE_VALUE) {
if(range->right.type == ARE_VALUE) { if(range->right.type == ARE_VALUE) {
OUT("{ AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND, %" PRIdMAX OUT("{ AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND, %" PRIdMAX
...@@ -1985,39 +2087,17 @@ emit_single_member_OER_constraint(arg_t *arg, asn1cnst_range_t *range, char *typ ...@@ -1985,39 +2087,17 @@ emit_single_member_OER_constraint(arg_t *arg, asn1cnst_range_t *range, char *typ
} }
} }
/*
* Print some courtesy debug information.
*/
if(range->left.type == ARE_VALUE
|| range->right.type == ARE_VALUE) {
OUT("\t/* ");
if(type) OUT("(%s", type);
OUT("(");
if(range->left.type == ARE_VALUE)
OUT("%" PRIdASN, range->left.value);
else
OUT("MIN");
OUT("..");
if(range->right.type == ARE_VALUE)
OUT("%" PRIdASN, range->right.value);
else
OUT("MAX");
if(range->extensible) OUT(",...");
if(type) OUT(")");
OUT(") */");
}
return 0; return 0;
} }
static int static int
emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int alphabetsize, char *type) { emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int alphabetsize, char *type) {
if(!range || range->incompatible || range->not_PER_visible) { if(!range || range->incompatible || range->not_PER_visible) {
OUT("{ APC_UNCONSTRAINED,\t-1, -1, 0, 0 }"); OUT("{ APC_UNCONSTRAINED,\t-1, -1, 0, 0 }");
return 0; return 0;
} }
if(range->left.type == ARE_VALUE) { if(range->left.type == ARE_VALUE) {
if(range->right.type == ARE_VALUE) { if(range->right.type == ARE_VALUE) {
asn1c_integer_t cover = 1; asn1c_integer_t cover = 1;
asn1c_integer_t r = 1 + range->right.value asn1c_integer_t r = 1 + range->right.value
...@@ -2151,22 +2231,26 @@ emit_member_OER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) { ...@@ -2151,22 +2231,26 @@ emit_member_OER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
INDENT(+1); INDENT(+1);
/* .value{.width,.positive} */
range = asn1constraint_compute_OER_range(expr->Identifier, etype, range = asn1constraint_compute_OER_range(expr->Identifier, etype,
expr->combined_constraints, expr->combined_constraints,
ACT_EL_RANGE, 0, 0, 0); ACT_EL_RANGE, 0, 0, 0);
if(emit_single_member_OER_constraint(arg, range, 0)) { if(emit_single_member_OER_constraint_value(arg, range, 0)) {
return -1; return -1;
} }
emit_single_member_OER_constraint_comment(arg, range, 0);
asn1constraint_range_free(range); asn1constraint_range_free(range);
OUT(",\n"); OUT(",\n");
/* .size */
range = asn1constraint_compute_OER_range(expr->Identifier, etype, range = asn1constraint_compute_OER_range(expr->Identifier, etype,
expr->combined_constraints, expr->combined_constraints,
ACT_CT_SIZE, 0, 0, 0); ACT_CT_SIZE, 0, 0, 0);
if(emit_single_member_OER_constraint(arg, range, "SIZE")) { if(emit_single_member_OER_constraint_size(arg, range, "SIZE")) {
return -1; return -1;
} }
emit_single_member_OER_constraint_comment(arg, range, "SIZE");
asn1constraint_range_free(range); asn1constraint_range_free(range);
INDENT(-1); INDENT(-1);
......
...@@ -16,8 +16,8 @@ INTEGER_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -16,8 +16,8 @@ INTEGER_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics; asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
asn_dec_rval_t rval = {RC_OK, 0}; asn_dec_rval_t rval = {RC_OK, 0};
INTEGER_t *st = (INTEGER_t *)*sptr; INTEGER_t *st = (INTEGER_t *)*sptr;
asn_oer_constraint_t *ct; struct asn_oer_constraint_number_s ct = {0, 0};
size_t req_bytes = 0; /* 0 = length determinant is required */ size_t req_bytes;
(void)opt_codec_ctx; (void)opt_codec_ctx;
(void)specs; (void)specs;
...@@ -32,41 +32,32 @@ INTEGER_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -32,41 +32,32 @@ INTEGER_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
st->size = 0; st->size = 0;
if(!constraints) constraints = td->oer_constraints; if(!constraints) constraints = td->oer_constraints;
ct = constraints ? &constraints->value : 0; if(constraints) ct = constraints->value;
if(ct && (ct->flags & AOC_HAS_LOWER_BOUND) && ct->lower_bound >= 0) { if(ct.width) {
/* X.969 08/2015 10.2(a) */ req_bytes = ct.width;
unsigned msb; /* Most significant bit */ } else {
size_t useful_size; /* No lower bound and no upper bound, effectively */
intmax_t ub = ct->upper_bound; ssize_t consumed = oer_fetch_length(ptr, size, &req_bytes);
if(ct->flags & AOC_HAS_UPPER_BOUND) { if(consumed == 0) {
if(ub <= 255) { ASN__DECODE_STARVED;
req_bytes = 1; } else if(consumed == -1) {
} else if(ub <= 65535) { ASN__DECODE_FAILED;
req_bytes = 2;
} else if(ub <= 4294967295UL) {
req_bytes = 4;
} else if(ub <= 18446744073709551615ULL) {
req_bytes = 8;
}
} }
rval.consumed += consumed;
ptr = (const char *)ptr + consumed;
size -= consumed;
}
if(req_bytes == 0) { /* #8.6, using length determinant */ if(req_bytes > size) {
ssize_t consumed = oer_fetch_length(ptr, size, &req_bytes); ASN__DECODE_STARVED;
if(consumed == 0) { }
ASN__DECODE_STARVED;
} else if(consumed == -1) {
ASN__DECODE_FAILED;
}
rval.consumed += consumed;
ptr = (const char *)ptr + consumed;
size -= consumed;
}
if(req_bytes > size) { if(ct.positive) {
ASN__DECODE_STARVED; /* X.969 08/2015 10.2(a) */
} unsigned msb; /* Most significant bit */
size_t useful_size;
/* Check most significant bit */ /* Check most significant bit */
msb = *(const uint8_t *)ptr >> 7; /* yields 0 or 1 */ msb = *(const uint8_t *)ptr >> 7; /* yields 0 or 1 */
...@@ -87,55 +78,20 @@ INTEGER_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -87,55 +78,20 @@ INTEGER_decode_oer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
rval.consumed += req_bytes; rval.consumed += req_bytes;
return rval; return rval;
} else if(ct } else {
&& ((ct->flags /* X.969 08/2015 10.2(b) */
& (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND)) st->buf = (uint8_t *)MALLOC(req_bytes + 1);
== (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))) { if(!st->buf) {
/* X.969 08/2015 10.2(b) - no lower bound or negative lower bound */
intmax_t lb = ct->lower_bound;
intmax_t ub = ct->upper_bound;
if(lb >= -128 && ub <= 127) {
req_bytes = 1;
} else if(lb >= -32768 && ub <= 32767) {
req_bytes = 2;
} else if(lb >= -2147483648L && ub <= 2147483647L) {
req_bytes = 4;
} else if(lb >= -9223372036854775808LL && ub <= 9223372036854775807LL) {
req_bytes = 8;
}
}
/* No lower bound and no upper bound, effectively */
if(req_bytes == 0) { /* #8.6, using length determinant */
ssize_t consumed = oer_fetch_length(ptr, size, &req_bytes);
if(consumed == 0) {
ASN__DECODE_STARVED;
} else if(consumed == -1) {
ASN__DECODE_FAILED; ASN__DECODE_FAILED;
} }
rval.consumed += consumed;
ptr = (const char *)ptr + consumed;
size -= consumed;
}
if(req_bytes > size) { memcpy(st->buf, ptr, req_bytes);
ASN__DECODE_STARVED; st->buf[req_bytes] = '\0'; /* Just in case, 0-terminate */
} st->size = req_bytes;
st->buf = (uint8_t *)MALLOC(req_bytes + 1); rval.consumed += req_bytes;
if(!st->buf) { return rval;
ASN__DECODE_FAILED;
} }
memcpy(st->buf, ptr, req_bytes);
st->buf[req_bytes] = '\0'; /* Just in case, 0-terminate */
st->size = req_bytes;
rval.consumed += req_bytes;
return rval;
} }
/* /*
...@@ -147,31 +103,27 @@ INTEGER_encode_oer(asn_TYPE_descriptor_t *td, ...@@ -147,31 +103,27 @@ INTEGER_encode_oer(asn_TYPE_descriptor_t *td,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
const INTEGER_t *st = sptr; const INTEGER_t *st = sptr;
asn_enc_rval_t er; asn_enc_rval_t er;
asn_oer_constraint_t *ct; struct asn_oer_constraint_number_s ct = {0, 0};
const uint8_t *buf; const uint8_t *buf;
const uint8_t *end; const uint8_t *end;
size_t useful_bytes; size_t useful_bytes;
size_t req_bytes = 0; size_t req_bytes = 0;
int encode_as_unsigned;
int sign = 0; int sign = 0;
if(!st || st->size == 0) ASN__ENCODE_FAILED; if(!st || st->size == 0) ASN__ENCODE_FAILED;
if(!constraints) constraints = td->oer_constraints; if(!constraints) constraints = td->oer_constraints;
ct = constraints ? &constraints->value : 0; if(constraints) ct = constraints->value;
er.encoded = 0; er.encoded = 0;
buf = st->buf; buf = st->buf;
end = buf + st->size; end = buf + st->size;
encode_as_unsigned =
ct && (ct->flags & AOC_HAS_LOWER_BOUND) && ct->lower_bound >= 0;
sign = (buf && buf < end) ? buf[0] & 0x80 : 0; sign = (buf && buf < end) ? buf[0] & 0x80 : 0;
/* Ignore 9 leading zeroes or ones */ /* Ignore 9 leading zeroes or ones */
if(encode_as_unsigned) { if(ct.positive) {
if(sign) { if(sign) {
/* The value given is a signed value. Can't proceed. */ /* The value given is a signed value. Can't proceed. */
ASN__ENCODE_FAILED; ASN__ENCODE_FAILED;
...@@ -192,46 +144,18 @@ INTEGER_encode_oer(asn_TYPE_descriptor_t *td, ...@@ -192,46 +144,18 @@ INTEGER_encode_oer(asn_TYPE_descriptor_t *td,
} }
useful_bytes = end - buf; useful_bytes = end - buf;
if(encode_as_unsigned) { if(ct.width) {
intmax_t ub = ct->upper_bound; req_bytes = ct.width;
} else {
if(ub <= 255) {
req_bytes = 1;
} else if(ub <= 65535) {
req_bytes = 2;
} else if(ub <= 4294967295UL) {
req_bytes = 4;
} else if(ub <= 18446744073709551615ULL) {
req_bytes = 8;
}
} else if(ct
&& ((ct->flags
& (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))
== (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))) {
/* X.969 08/2015 10.2(b) - no lower bound or negative lower bound */
intmax_t lb = ct->lower_bound;
intmax_t ub = ct->upper_bound;
if(lb >= -128 && ub <= 127) {
req_bytes = 1;
} else if(lb >= -32768 && ub <= 32767) {
req_bytes = 2;
} else if(lb >= -2147483648L && ub <= 2147483647L) {
req_bytes = 4;
} else if(lb >= -9223372036854775808LL && ub <= 9223372036854775807LL) {
req_bytes = 8;
}
}
if(req_bytes == 0) {
ssize_t r = oer_serialize_length(useful_bytes, cb, app_key); ssize_t r = oer_serialize_length(useful_bytes, cb, app_key);
if(r < 0) { if(r < 0) {
ASN__ENCODE_FAILED; ASN__ENCODE_FAILED;
} }
er.encoded += r; er.encoded += r;
req_bytes = useful_bytes; req_bytes = useful_bytes;
} else if(req_bytes < useful_bytes) { }
if(req_bytes < useful_bytes) {
ASN__ENCODE_FAILED; ASN__ENCODE_FAILED;
} }
......
...@@ -17,22 +17,16 @@ NativeInteger_decode_oer(asn_codec_ctx_t *opt_codec_ctx, ...@@ -17,22 +17,16 @@ NativeInteger_decode_oer(asn_codec_ctx_t *opt_codec_ctx,
asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics; asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
asn_dec_rval_t rval = {RC_OK, 0}; asn_dec_rval_t rval = {RC_OK, 0};
long *native = (long *)*nint_ptr; long *native = (long *)*nint_ptr;
asn_oer_constraint_t *ct;
INTEGER_t tmpint; INTEGER_t tmpint;
INTEGER_t *tmpintptr = &tmpint; INTEGER_t *tmpintptr = &tmpint;
memset(&tmpint, 0, sizeof(tmpint)); memset(&tmpint, 0, sizeof(tmpint));
(void)opt_codec_ctx;
if(!native) { if(!native) {
native = (long *)(*nint_ptr = CALLOC(1, sizeof(*native))); native = (long *)(*nint_ptr = CALLOC(1, sizeof(*native)));
if(!native) ASN__DECODE_FAILED; if(!native) ASN__DECODE_FAILED;
} }
if(!constraints) constraints = td->oer_constraints;
ct = constraints ? &constraints->value : 0;
/* /*
* OPTIMIZATION: Encode directly rather than passing through INTEGER. * OPTIMIZATION: Encode directly rather than passing through INTEGER.
* Saves a memory allocation. * Saves a memory allocation.
......
...@@ -9,11 +9,6 @@ ...@@ -9,11 +9,6 @@
#include <OCTET_STRING.h> #include <OCTET_STRING.h>
#include <errno.h> #include <errno.h>
static asn_oer_constraints_t asn_DEF_OCTET_STRING_oer_constraints = {
{ 0, 0, 0 },
{ AOC_HAS_LOWER_BOUND, 0, 0 }
};
asn_dec_rval_t asn_dec_rval_t
OCTET_STRING_decode_oer(asn_codec_ctx_t *opt_codec_ctx, OCTET_STRING_decode_oer(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td, asn_TYPE_descriptor_t *td,
...@@ -26,8 +21,7 @@ OCTET_STRING_decode_oer(asn_codec_ctx_t *opt_codec_ctx, ...@@ -26,8 +21,7 @@ OCTET_STRING_decode_oer(asn_codec_ctx_t *opt_codec_ctx,
OCTET_STRING_t *st = (OCTET_STRING_t *)*sptr; OCTET_STRING_t *st = (OCTET_STRING_t *)*sptr;
asn_oer_constraints_t *cts = asn_oer_constraints_t *cts =
constraints ? constraints : td->oer_constraints; constraints ? constraints : td->oer_constraints;
asn_oer_constraint_t *csiz = ssize_t ct_size = cts ? cts->size : -1;
cts ? &cts->size : &asn_DEF_OCTET_STRING_oer_constraints.size;
asn_dec_rval_t rval = {RC_OK, 0}; asn_dec_rval_t rval = {RC_OK, 0};
size_t expected_length = 0; size_t expected_length = 0;
...@@ -57,11 +51,8 @@ OCTET_STRING_decode_oer(asn_codec_ctx_t *opt_codec_ctx, ...@@ -57,11 +51,8 @@ OCTET_STRING_decode_oer(asn_codec_ctx_t *opt_codec_ctx,
if(!st) ASN__DECODE_FAILED; if(!st) ASN__DECODE_FAILED;
} }
if((csiz->flags if(ct_size >= 0) {
& (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND)) expected_length = unit_bytes * ct_size;
== (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND)
&& csiz->lower_bound == csiz->upper_bound) {
expected_length = unit_bytes * csiz->lower_bound;
} else { } else {
/* /*
* X.696 (08/2015) #27.2 * X.696 (08/2015) #27.2
...@@ -120,18 +111,14 @@ OCTET_STRING_encode_oer(asn_TYPE_descriptor_t *td, ...@@ -120,18 +111,14 @@ OCTET_STRING_encode_oer(asn_TYPE_descriptor_t *td,
OCTET_STRING_t *st = (OCTET_STRING_t *)sptr; OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
asn_oer_constraints_t *cts = asn_oer_constraints_t *cts =
constraints ? constraints : td->oer_constraints; constraints ? constraints : td->oer_constraints;
asn_oer_constraint_t *csiz = ssize_t ct_size = cts ? cts->size : -1;
cts ? &cts->size : &asn_DEF_OCTET_STRING_oer_constraints.size;
asn_enc_rval_t er = {0, 0, 0}; asn_enc_rval_t er = {0, 0, 0};
if(!st) ASN__ENCODE_FAILED; if(!st) ASN__ENCODE_FAILED;
ASN_DEBUG("Encoding %s %d as OCTET STRING", td ? td->name : "", st->size); ASN_DEBUG("Encoding %s %d as OCTET STRING", td ? td->name : "", st->size);
if((csiz->flags if(ct_size >= 0) {
& (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND))
== (AOC_HAS_LOWER_BOUND | AOC_HAS_UPPER_BOUND)
&& csiz->lower_bound == csiz->upper_bound) {
/* /*
* Check that available data matches the constraint * Check that available data matches the constraint
*/ */
...@@ -154,11 +141,11 @@ OCTET_STRING_encode_oer(asn_TYPE_descriptor_t *td, ...@@ -154,11 +141,11 @@ OCTET_STRING_encode_oer(asn_TYPE_descriptor_t *td,
break; break;
} }
if(st->size != unit_bytes * csiz->lower_bound) { if(st->size != unit_bytes * ct_size) {
ASN_DEBUG( ASN_DEBUG(
"Trying to encode %s (%zu bytes) which doesn't fit SIZE " "Trying to encode %s (%zu bytes) which doesn't fit SIZE "
"constraint (%d)", "constraint (%d)",
td->name, st->size, csiz->lower_bound); td->name, st->size, ct_size);
ASN__ENCODE_FAILED; ASN__ENCODE_FAILED;
} }
} else { } else {
......
...@@ -15,17 +15,13 @@ extern "C" { ...@@ -15,17 +15,13 @@ extern "C" {
/* /*
* Pre-computed OER constraints. * Pre-computed OER constraints.
*/ */
typedef const struct asn_oer_constraint_s { typedef const struct asn_oer_constraint_number_s {
enum asn_oer_constraint_flags { unsigned width; /* ±8,4,2,1 fixed bytes */
AOC_HAS_LOWER_BOUND = 0x01, unsigned positive; /* 1 for unsigned number, 0 for signed */
AOC_HAS_UPPER_BOUND = 0x02 } asn_oer_constraint_number_t;
} flags;
intmax_t lower_bound;
intmax_t upper_bound;
} asn_oer_constraint_t;
typedef const struct asn_oer_constraints_s { typedef const struct asn_oer_constraints_s {
struct asn_oer_constraint_s value; asn_oer_constraint_number_t value;
struct asn_oer_constraint_s size; ssize_t size; /* -1 (no constraint) or >= 0 */
} asn_oer_constraints_t; } asn_oer_constraints_t;
......
This diff is collapsed.
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