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 |
vlm | e7e9bd9 | 2006-09-17 11:02:53 +0000 | [diff] [blame^] | 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) { |
vlm | 4d2ca12 | 2005-12-07 05:46:03 +0000 | [diff] [blame] | 7 | asn_codec_ctx_t s_codec_ctx; |
| 8 | asn_per_data_t pd; |
| 9 | |
vlm | e7e9bd9 | 2006-09-17 11:02:53 +0000 | [diff] [blame^] | 10 | if(skip_bits < 0 || skip_bits > 7 || (skip_bits > 0 && !size)) |
| 11 | _ASN_DECODE_FAILED; |
| 12 | |
vlm | 4d2ca12 | 2005-12-07 05:46:03 +0000 | [diff] [blame] | 13 | /* |
| 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; |
vlm | e7e9bd9 | 2006-09-17 11:02:53 +0000 | [diff] [blame^] | 31 | pd.nboff = skip_bits; |
vlm | 4d2ca12 | 2005-12-07 05:46:03 +0000 | [diff] [blame] | 32 | 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 | |