blob: d1e4d48dd73fecb6d5d1b3cfe5529df7e2975363 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin20696a42017-10-17 21:27:33 -07002 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _BER_TLV_LENGTH_H_
6#define _BER_TLV_LENGTH_H_
7
Lev Walkin21b41ac2005-07-24 09:03:44 +00008#ifdef __cplusplus
9extern "C" {
10#endif
11
Lev Walkinf15320b2004-06-03 03:38:44 +000012typedef ssize_t ber_tlv_len_t;
13
14/*
15 * This function tries to fetch the length of the BER TLV value and place it
16 * in *len_r.
17 * RETURN VALUES:
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.
23 */
Lev Walkin8c3b8542005-03-10 18:52:02 +000024ssize_t ber_fetch_length(int _is_constructed, const void *bufptr, size_t size,
Lev Walkinf15320b2004-06-03 03:38:44 +000025 ber_tlv_len_t *len_r);
26
27/*
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.
31 * RETURN VALUES:
32 * Standard {-1,0,>0} convention.
33 */
Lev Walkinbaaa24f2004-09-29 14:19:14 +000034ssize_t ber_skip_length(
Lev Walkinafbf2a92017-09-12 23:30:27 -070035 const struct asn_codec_ctx_s *opt_codec_ctx, /* optional context */
Lev Walkin8c3b8542005-03-10 18:52:02 +000036 int _is_constructed, const void *bufptr, size_t size);
Lev Walkinf15320b2004-06-03 03:38:44 +000037
38/*
39 * This function serializes the length (L from TLV) in DER format.
Lev Walkin91b29c52004-09-24 20:59:13 +000040 * It always returns number of bytes necessary to represent the length,
Lev Walkinf15320b2004-06-03 03:38:44 +000041 * it is a caller's responsibility to check the return value
42 * against the supplied buffer's size.
43 */
Lev Walkin91b29c52004-09-24 20:59:13 +000044size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size);
Lev Walkinf15320b2004-06-03 03:38:44 +000045
Lev Walkin21b41ac2005-07-24 09:03:44 +000046#ifdef __cplusplus
47}
48#endif
49
Lev Walkinf15320b2004-06-03 03:38:44 +000050#endif /* _BER_TLV_LENGTH_H_ */