e2fd62511927ca00a12a38e2024b9841303f0a85
[ric-plt/resource-status-manager.git] / RSM / asn1codec / e2ap_engine / ber_tlv_length.h
1
2 /*-
3  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #ifndef _BER_TLV_LENGTH_H_
7 #define _BER_TLV_LENGTH_H_
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 typedef ssize_t ber_tlv_len_t;
14
15 /*
16  * This function tries to fetch the length of the BER TLV value and place it
17  * in *len_r.
18  * RETURN VALUES:
19  *       0:     More data expected than bufptr contains.
20  *      -1:     Fatal error deciphering length.
21  *      >0:     Number of bytes used from bufptr.
22  * On return with >0, len_r is constrained as -1..MAX, where -1 mean
23  * that the value is of indefinite length.
24  */
25 ssize_t ber_fetch_length(int _is_constructed, const void *bufptr, size_t size,
26         ber_tlv_len_t *len_r);
27
28 /*
29  * This function expects bufptr to be positioned over L in TLV.
30  * It returns number of bytes occupied by L and V together, suitable
31  * for skipping. The function properly handles indefinite length.
32  * RETURN VALUES:
33  *      Standard {-1,0,>0} convention.
34  */
35 ssize_t ber_skip_length(
36         const struct asn_codec_ctx_s *opt_codec_ctx,    /* optional context */
37         int _is_constructed, const void *bufptr, size_t size);
38
39 /*
40  * This function serializes the length (L from TLV) in DER format.
41  * It always returns number of bytes necessary to represent the length,
42  * it is a caller's responsibility to check the return value
43  * against the supplied buffer's size.
44  */
45 size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size);
46
47 #ifdef __cplusplus
48 }
49 #endif
50
51 #endif  /* _BER_TLV_LENGTH_H_ */