2 * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
5 #ifndef _BER_TLV_LENGTH_H_
6 #define _BER_TLV_LENGTH_H_
12 typedef ssize_t ber_tlv_len_t;
15 * This function tries to fetch the length of the BER TLV value and place it
18 * 0: More data expected than bufptr contains.
19 * -1: Fatal error deciphering length.
20 * >0: Number of bytes used from bufptr.
21 * On return with >0, len_r is constrained as -1..MAX, where -1 mean
22 * that the value is of indefinite length.
24 ssize_t ber_fetch_length(int _is_constructed, const void *bufptr, size_t size,
25 ber_tlv_len_t *len_r);
28 * This function expects bufptr to be positioned over L in TLV.
29 * It returns number of bytes occupied by L and V together, suitable
30 * for skipping. The function properly handles indefinite length.
32 * Standard {-1,0,>0} convention.
34 ssize_t ber_skip_length(
35 struct asn_codec_ctx_s *opt_codec_ctx, /* optional context */
36 int _is_constructed, const void *bufptr, size_t size);
39 * This function serializes the length (L from TLV) in DER format.
40 * It always returns number of bytes necessary to represent the length,
41 * it is a caller's responsibility to check the return value
42 * against the supplied buffer's size.
44 size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size);
50 #endif /* _BER_TLV_LENGTH_H_ */