Moving in e2sim originally from it/test/simulators
[sim/e2-interface.git] / e2sim / ASN1c / ber_tlv_length.h
1 /*****************************************************************************
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_TLV_LENGTH_H_
24 #define _BER_TLV_LENGTH_H_
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 typedef ssize_t ber_tlv_len_t;
31
32 /*
33  * This function tries to fetch the length of the BER TLV value and place it
34  * in *len_r.
35  * RETURN VALUES:
36  *       0:     More data expected than bufptr contains.
37  *      -1:     Fatal error deciphering length.
38  *      >0:     Number of bytes used from bufptr.
39  * On return with >0, len_r is constrained as -1..MAX, where -1 mean
40  * that the value is of indefinite length.
41  */
42 ssize_t ber_fetch_length(int _is_constructed, const void *bufptr, size_t size,
43         ber_tlv_len_t *len_r);
44
45 /*
46  * This function expects bufptr to be positioned over L in TLV.
47  * It returns number of bytes occupied by L and V together, suitable
48  * for skipping. The function properly handles indefinite length.
49  * RETURN VALUES:
50  *      Standard {-1,0,>0} convention.
51  */
52 ssize_t ber_skip_length(
53         const struct asn_codec_ctx_s *opt_codec_ctx,    /* optional context */
54         int _is_constructed, const void *bufptr, size_t size);
55
56 /*
57  * This function serializes the length (L from TLV) in DER format.
58  * It always returns number of bytes necessary to represent the length,
59  * it is a caller's responsibility to check the return value
60  * against the supplied buffer's size.
61  */
62 size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size);
63
64 #ifdef __cplusplus
65 }
66 #endif
67
68 #endif  /* _BER_TLV_LENGTH_H_ */