1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
5 # Licensed under the Apache License, Version 2.0 (the "License"); *
6 # you may not use this file except in compliance with the License. *
7 # You may obtain a copy of the License at *
9 # http://www.apache.org/licenses/LICENSE-2.0 *
11 # Unless required by applicable law or agreed to in writing, software *
12 # distributed under the License is distributed on an "AS IS" BASIS, *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 # See the License for the specific language governing permissions and *
15 # limitations under the License. *
17 ******************************************************************************/
20 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
23 #ifndef _BER_DECODER_H_
24 #define _BER_DECODER_H_
26 #include <asn_application.h>
32 struct asn_TYPE_descriptor_s; /* Forward declaration */
33 struct asn_codec_ctx_s; /* Forward declaration */
36 * The BER decoder of any type.
37 * This function may be invoked directly from the application.
38 * Decodes BER, DER and CER data (DER and CER are different subsets of BER).
40 * NOTE: Use the der_encode() function (der_encoder.h) to produce encoding
41 * which is compliant with ber_decode().
43 asn_dec_rval_t ber_decode(
44 const struct asn_codec_ctx_s *opt_codec_ctx,
45 const struct asn_TYPE_descriptor_s *type_descriptor,
46 void **struct_ptr, /* Pointer to a target structure's pointer */
47 const void *buffer, /* Data to be decoded */
48 size_t size /* Size of that buffer */
52 * Type of generic function which decodes the byte stream into the structure.
54 typedef asn_dec_rval_t(ber_type_decoder_f)(
55 const struct asn_codec_ctx_s *opt_codec_ctx,
56 const struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr,
57 const void *buf_ptr, size_t size, int tag_mode);
59 /*******************************
60 * INTERNALLY USEFUL FUNCTIONS *
61 *******************************/
64 * Check that all tags correspond to the type definition (as given in head).
65 * On return, last_length would contain either a non-negative length of the
66 * value part of the last TLV, or the negative number of expected
67 * "end of content" sequences. The number may only be negative if the
68 * head->last_tag_form is non-zero.
70 asn_dec_rval_t ber_check_tags(
71 const struct asn_codec_ctx_s *opt_codec_ctx, /* codec options */
72 const struct asn_TYPE_descriptor_s *type_descriptor,
73 asn_struct_ctx_t *opt_ctx, /* saved decoding context */
74 const void *ptr, size_t size,
75 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
76 int last_tag_form, /* {-1,0:1}: any, primitive, constr */
77 ber_tlv_len_t *last_length, int *opt_tlv_form /* optional tag form */
84 #endif /* _BER_DECODER_H_ */