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_TLV_LENGTH_H_
24 #define _BER_TLV_LENGTH_H_
30 typedef ssize_t ber_tlv_len_t;
33 * This function tries to fetch the length of the BER TLV value and place it
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.
42 ssize_t ber_fetch_length(int _is_constructed, const void *bufptr, size_t size,
43 ber_tlv_len_t *len_r);
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.
50 * Standard {-1,0,>0} convention.
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);
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.
62 size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size);
68 #endif /* _BER_TLV_LENGTH_H_ */