blob: 6c41bf8c6ec0634f8fdde3b5c0eb8ee76e7efd2b [file] [log] [blame]
Harry Tran1f1098a2020-03-10 10:40:10 -04001/*****************************************************************************
2# *
3# Copyright 2019 AT&T Intellectual Property *
4# *
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 *
8# *
9# http://www.apache.org/licenses/LICENSE-2.0 *
10# *
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. *
16# *
17******************************************************************************/
18
19/*-
20 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
22 */
23#ifndef _BER_DECODER_H_
24#define _BER_DECODER_H_
25
26#include <asn_application.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32struct asn_TYPE_descriptor_s; /* Forward declaration */
33struct asn_codec_ctx_s; /* Forward declaration */
34
35/*
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).
39 *
40 * NOTE: Use the der_encode() function (der_encoder.h) to produce encoding
41 * which is compliant with ber_decode().
42 */
43asn_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 */
49);
50
51/*
52 * Type of generic function which decodes the byte stream into the structure.
53 */
54typedef 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);
58
59/*******************************
60 * INTERNALLY USEFUL FUNCTIONS *
61 *******************************/
62
63/*
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.
69 */
70asn_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 */
78);
79
80#ifdef __cplusplus
81}
82#endif
83
84#endif /* _BER_DECODER_H_ */