sjana | 464f907 | 2020-11-13 10:19:53 -0800 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2003-2017 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 | |
| 8 | #include <asn_application.h> |
| 9 | |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
| 14 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
| 15 | struct asn_codec_ctx_s; /* Forward declaration */ |
| 16 | |
| 17 | /* |
| 18 | * The BER decoder of any type. |
| 19 | * This function may be invoked directly from the application. |
| 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(). |
| 24 | */ |
| 25 | asn_dec_rval_t ber_decode( |
| 26 | const struct asn_codec_ctx_s *opt_codec_ctx, |
| 27 | const struct asn_TYPE_descriptor_s *type_descriptor, |
| 28 | void **struct_ptr, /* Pointer to a target structure's pointer */ |
| 29 | const void *buffer, /* Data to be decoded */ |
| 30 | size_t size /* Size of that buffer */ |
| 31 | ); |
| 32 | |
| 33 | /* |
| 34 | * Type of generic function which decodes the byte stream into the structure. |
| 35 | */ |
| 36 | typedef asn_dec_rval_t(ber_type_decoder_f)( |
| 37 | const struct asn_codec_ctx_s *opt_codec_ctx, |
| 38 | const struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr, |
| 39 | const void *buf_ptr, size_t size, 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 | */ |
| 52 | asn_dec_rval_t ber_check_tags( |
| 53 | const struct asn_codec_ctx_s *opt_codec_ctx, /* codec options */ |
| 54 | const struct asn_TYPE_descriptor_s *type_descriptor, |
| 55 | asn_struct_ctx_t *opt_ctx, /* saved decoding context */ |
| 56 | const void *ptr, size_t size, |
| 57 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
| 58 | int last_tag_form, /* {-1,0:1}: any, primitive, constr */ |
| 59 | ber_tlv_len_t *last_length, int *opt_tlv_form /* optional tag form */ |
| 60 | ); |
| 61 | |
| 62 | #ifdef __cplusplus |
| 63 | } |
| 64 | #endif |
| 65 | |
| 66 | #endif /* _BER_DECODER_H_ */ |