| 1 |
#include <asn_application.h> |
| 2 |
#include <asn_internal.h> |
| 3 |
#include <per_decoder.h> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
asn_dec_rval_t |
| 11 |
uper_decode_complete(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, void **sptr, const void *buffer, size_t size) { |
| 12 |
asn_dec_rval_t rval; |
| 13 |
|
| 14 |
rval = uper_decode(opt_codec_ctx, td, sptr, buffer, size, 0, 0); |
| 15 |
if(rval.consumed) { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
rval.consumed += 7; |
| 21 |
rval.consumed >>= 3; |
| 22 |
} else if(rval.code == RC_OK) { |
| 23 |
if(size) { |
| 24 |
if(((const uint8_t *)buffer)[0] == 0) { |
| 25 |
rval.consumed = 1; |
| 26 |
} else { |
| 27 |
ASN_DEBUG("Expecting single zeroed byte"); |
| 28 |
rval.code = RC_FAIL; |
| 29 |
} |
| 30 |
} else { |
| 31 |
|
| 32 |
rval.code = RC_WMORE; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
return rval; |
| 37 |
} |
| 38 |
|
| 39 |
asn_dec_rval_t |
| 40 |
uper_decode(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, void **sptr, const void *buffer, size_t size, int skip_bits, int unused_bits) { |
| 41 |
asn_codec_ctx_t s_codec_ctx; |
| 42 |
asn_dec_rval_t rval; |
| 43 |
asn_per_data_t pd; |
| 44 |
|
| 45 |
if(skip_bits < 0 || skip_bits > 7 |
| 46 |
|| unused_bits < 0 || unused_bits > 7 |
| 47 |
|| (unused_bits > 0 && !size)) |
| 48 |
ASN__DECODE_FAILED; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
if(opt_codec_ctx) { |
| 55 |
if(opt_codec_ctx->max_stack_size) { |
| 56 |
s_codec_ctx = *opt_codec_ctx; |
| 57 |
opt_codec_ctx = &s_codec_ctx; |
| 58 |
} |
| 59 |
} else { |
| 60 |
|
| 61 |
memset(&s_codec_ctx, 0, sizeof(s_codec_ctx)); |
| 62 |
s_codec_ctx.max_stack_size = ASN__DEFAULT_STACK_MAX; |
| 63 |
opt_codec_ctx = &s_codec_ctx; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
memset(&pd, 0, sizeof(pd)); |
| 68 |
pd.buffer = (const uint8_t *)buffer; |
| 69 |
pd.nboff = skip_bits; |
| 70 |
pd.nbits = 8 * size - unused_bits; |
| 71 |
if(pd.nboff > pd.nbits) |
| 72 |
ASN__DECODE_FAILED; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
if(!td->uper_decoder) |
| 78 |
ASN__DECODE_FAILED; |
| 79 |
rval = td->uper_decoder(opt_codec_ctx, td, 0, sptr, &pd); |
| 80 |
if(rval.code == RC_OK) { |
| 81 |
|
| 82 |
rval.consumed = ((pd.buffer - (const uint8_t *)buffer) << 3) |
| 83 |
+ pd.nboff - skip_bits; |
| 84 |
ASN_DEBUG("PER decoding consumed %ld, counted %ld", |
| 85 |
(long)rval.consumed, (long)pd.moved); |
| 86 |
assert(rval.consumed == pd.moved); |
| 87 |
} else { |
| 88 |
|
| 89 |
rval.consumed = 0; |
| 90 |
} |
| 91 |
return rval; |
| 92 |
} |
| 93 |
|