1 #include <asn_application.h>
2 #include <asn_internal.h>
3 #include <per_decoder.h>
6 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) {
7 asn_codec_ctx_t s_codec_ctx;
11 if(skip_bits < 0 || skip_bits > 7
12 || unused_bits < 0 || unused_bits > 7
13 || (unused_bits > 0 && !size))
17 * Stack checker requires that the codec context
18 * must be allocated on the stack.
21 if(opt_codec_ctx->max_stack_size) {
22 s_codec_ctx = *opt_codec_ctx;
23 opt_codec_ctx = &s_codec_ctx;
26 /* If context is not given, be security-conscious anyway */
27 memset(&s_codec_ctx, 0, sizeof(s_codec_ctx));
28 s_codec_ctx.max_stack_size = _ASN_DEFAULT_STACK_MAX;
29 opt_codec_ctx = &s_codec_ctx;
32 /* Fill in the position indicator */
33 pd.buffer = (const uint8_t *)buffer;
35 pd.nbits = 8 * size - unused_bits; /* 8 is CHAR_BIT from <limits.h> */
36 if(pd.nboff > pd.nbits)
40 * Invoke type-specific decoder.
43 _ASN_DECODE_FAILED; /* PER is not compiled in */
44 rval = td->uper_decoder(opt_codec_ctx, td, 0, sptr, &pd);
45 if(rval.code == RC_OK) {
46 /* Return the number of consumed bits */
47 rval.consumed = ((pd.buffer - (const uint8_t *)buffer) << 3)
48 + pd.nboff - skip_bits;
50 /* PER codec is not a restartable */