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