vlm | 337167e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 1 | #include <asn_application.h> |
vlm | 4d2ca12 | 2005-12-07 05:46:03 +0000 | [diff] [blame] | 2 | #include <asn_internal.h> |
vlm | 337167e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 3 | #include <per_decoder.h> |
vlm | 4d2ca12 | 2005-12-07 05:46:03 +0000 | [diff] [blame] | 4 | |
| 5 | asn_dec_rval_t |
| 6 | uper_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 | |