blob: bc5f569c1e5bda15fa1913f4c00e08f63196082c [file] [log] [blame]
vlm337167e2005-11-26 11:25:14 +00001#include <asn_application.h>
vlm4d2ca122005-12-07 05:46:03 +00002#include <asn_internal.h>
vlm337167e2005-11-26 11:25:14 +00003#include <per_decoder.h>
vlm4d2ca122005-12-07 05:46:03 +00004
5asn_dec_rval_t
vlme7e9bd92006-09-17 11:02:53 +00006uper_decode(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, void **sptr, const void *buffer, size_t size, int skip_bits) {
vlm4d2ca122005-12-07 05:46:03 +00007 asn_codec_ctx_t s_codec_ctx;
8 asn_per_data_t pd;
9
vlme7e9bd92006-09-17 11:02:53 +000010 if(skip_bits < 0 || skip_bits > 7 || (skip_bits > 0 && !size))
11 _ASN_DECODE_FAILED;
12
vlm4d2ca122005-12-07 05:46:03 +000013 /*
14 * Stack checker requires that the codec context
15 * must be allocated on the stack.
16 */
17 if(opt_codec_ctx) {
18 if(opt_codec_ctx->max_stack_size) {
19 s_codec_ctx = *opt_codec_ctx;
20 opt_codec_ctx = &s_codec_ctx;
21 }
22 } else {
23 /* If context is not given, be security-conscious anyway */
24 memset(&s_codec_ctx, 0, sizeof(s_codec_ctx));
25 s_codec_ctx.max_stack_size = _ASN_DEFAULT_STACK_MAX;
26 opt_codec_ctx = &s_codec_ctx;
27 }
28
29 /* Fill in the position indicator */
30 pd.buffer = (const uint8_t *)buffer;
vlme7e9bd92006-09-17 11:02:53 +000031 pd.nboff = skip_bits;
vlm4d2ca122005-12-07 05:46:03 +000032 pd.nbits = 8 * size; /* 8 is CHAR_BIT from <limits.h> */
33
34 /*
35 * Invoke type-specific decoder.
36 */
37 if(!td->uper_decoder)
38 _ASN_DECODE_FAILED; /* PER is not compiled in */
39 return td->uper_decoder(opt_codec_ctx, td, 0, sptr, &pd);
40}
41