10 #define RETURN(_code) \
12 asn_dec_rval_t tmprval; \
13 tmprval.code = _code; \
14 tmprval.consumed = consumed_myself; \
19 APC_SEMI_CONSTRAINED, -1, -1, 0, 0};
34 ssize_t consumed_myself = 0;
45 if(specs->subvariant != ASN_OSUBV_BIT) {
46 ASN_DEBUG(
"Subvariant %d is not BIT OSUBV_BIT", specs->subvariant);
59 csiz->flags & APC_EXTENSIBLE ?
"extensible" :
"non-extensible",
60 csiz->lower_bound, csiz->upper_bound, csiz->effective_bits);
62 if(csiz->flags & APC_EXTENSIBLE) {
70 if(csiz->effective_bits >= 0) {
72 st->
size = (csiz->upper_bound + 7) >> 3;
80 if(csiz->effective_bits == 0) {
82 ASN_DEBUG(
"Encoding BIT STRING size %"ASN_PRIdMAX"", csiz->upper_bound);
85 consumed_myself += csiz->upper_bound;
87 st->
bits_unused = (8 - (csiz->upper_bound & 0x7)) & 0x7;
103 if(raw_len == 0 && st->
buf)
break;
105 if (csiz->effective_bits >= 0 && csiz->effective_bits <= 16 && raw_len > csiz->upper_bound && !(csiz->flags & APC_EXTENSIBLE)) {
109 ASN_DEBUG(
"Got PER length eb %ld, len %ld, %s (%s)",
110 (
long)csiz->effective_bits, (
long)raw_len,
111 repeat ?
"repeat" :
"once", td->name);
113 len_bytes = (len_bits + 7) >> 3;
114 if(len_bits & 0x7) st->
bits_unused = 8 - (len_bits & 0x7);
118 st->
buf = (uint8_t *)p;
122 st->
size += len_bytes;
140 #if defined(UPER_REMOVE_TRAILING_BITS)
150 if(!st || (!st->
buf && st->
size))
165 ct_extensible = csiz->
flags & APC_EXTENSIBLE;
167 #if defined(UPER_REMOVE_TRAILING_BITS)
181 td->
name, size_in_bits, csiz->lower_bound, csiz->upper_bound,
182 csiz->effective_bits, ct_extensible ?
" EXT" :
"");
186 if(csiz->effective_bits >= 0) {
187 if((ssize_t)size_in_bits > csiz->upper_bound) {
205 if(csiz->effective_bits >= 0 && !inext) {
206 int add_trailer = (ssize_t)size_in_bits < csiz->lower_bound;
210 st->
size, size_in_bits - csiz->lower_bound, csiz->effective_bits,
212 add_trailer ? 0 : (ssize_t)size_in_bits - (ssize_t)csiz->lower_bound);
214 po, add_trailer ? 0 : (ssize_t)size_in_bits - csiz->lower_bound,
215 csiz->effective_bits);
220 static const uint8_t zeros[16];
221 size_t trailing_zero_bits = csiz->lower_bound - size_in_bits;
222 while(trailing_zero_bits > 0) {
223 if(trailing_zero_bits > 8 *
sizeof(zeros)) {
225 trailing_zero_bits -= 8 *
sizeof(zeros);
228 trailing_zero_bits = 0;
250 size_in_bits -= maySave;
251 assert(!(maySave & 0x07) || !size_in_bits);
254 }
while(size_in_bits);