Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | #ifndef _BER_DECODER_H_ |
| 6 | #define _BER_DECODER_H_ |
| 7 | |
Lev Walkin | 11c3e17 | 2004-09-24 21:00:50 +0000 | [diff] [blame] | 8 | #include <asn_application.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
Lev Walkin | 1cbd222 | 2004-09-29 13:24:10 +0000 | [diff] [blame] | 14 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
| 15 | struct asn_codec_ctx_s; /* Forward declaration */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 16 | |
| 17 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 18 | * The BER decoder of any type. |
| 19 | * This function may be invoked directly from the application. |
Lev Walkin | 2864774 | 2017-09-12 11:07:06 -0700 | [diff] [blame] | 20 | * Decodes BER, DER and CER data (DER and CER are different subsets of BER). |
| 21 | * |
| 22 | * NOTE: Use the der_encode() function (der_encoder.h) to produce encoding |
| 23 | * which is compliant with ber_decode(). |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 24 | */ |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 25 | asn_dec_rval_t ber_decode(const struct asn_codec_ctx_s *opt_codec_ctx, |
Lev Walkin | 1cbd222 | 2004-09-29 13:24:10 +0000 | [diff] [blame] | 26 | struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 27 | void **struct_ptr, /* Pointer to a target structure's pointer */ |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 28 | const void *buffer, /* Data to be decoded */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 29 | size_t size /* Size of that buffer */ |
| 30 | ); |
| 31 | |
| 32 | /* |
| 33 | * Type of generic function which decodes the byte stream into the structure. |
| 34 | */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 35 | typedef asn_dec_rval_t (ber_type_decoder_f)( |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 36 | const struct asn_codec_ctx_s *opt_codec_ctx, |
Lev Walkin | 1cbd222 | 2004-09-29 13:24:10 +0000 | [diff] [blame] | 37 | struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 38 | void **struct_ptr, const void *buf_ptr, size_t size, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 39 | int tag_mode); |
| 40 | |
| 41 | /******************************* |
| 42 | * INTERNALLY USEFUL FUNCTIONS * |
| 43 | *******************************/ |
| 44 | |
| 45 | /* |
| 46 | * Check that all tags correspond to the type definition (as given in head). |
| 47 | * On return, last_length would contain either a non-negative length of the |
| 48 | * value part of the last TLV, or the negative number of expected |
| 49 | * "end of content" sequences. The number may only be negative if the |
| 50 | * head->last_tag_form is non-zero. |
| 51 | */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 52 | asn_dec_rval_t ber_check_tags( |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 53 | const struct asn_codec_ctx_s *opt_codec_ctx, /* codec options */ |
Lev Walkin | 1d9e8dd | 2005-12-07 05:46:03 +0000 | [diff] [blame] | 54 | struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | 1cbd222 | 2004-09-29 13:24:10 +0000 | [diff] [blame] | 55 | asn_struct_ctx_t *opt_ctx, /* saved decoding context */ |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 56 | const void *ptr, size_t size, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 57 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 58 | int last_tag_form, /* {-1,0:1}: any, primitive, constr */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 59 | ber_tlv_len_t *last_length, |
Lev Walkin | 1cbd222 | 2004-09-29 13:24:10 +0000 | [diff] [blame] | 60 | int *opt_tlv_form /* optional tag form */ |
| 61 | ); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 62 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 63 | #ifdef __cplusplus |
| 64 | } |
| 65 | #endif |
| 66 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 67 | #endif /* _BER_DECODER_H_ */ |