blob: 9d99e663fc60575cc580ab33d38f14589691b3d3 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _BER_TLV_LENGTH_H_
6#define _BER_TLV_LENGTH_H_
7
8typedef ssize_t ber_tlv_len_t;
9
10/*
11 * This function tries to fetch the length of the BER TLV value and place it
12 * in *len_r.
13 * RETURN VALUES:
14 * 0: More data expected than bufptr contains.
15 * -1: Fatal error deciphering length.
16 * >0: Number of bytes used from bufptr.
17 * On return with >0, len_r is constrained as -1..MAX, where -1 mean
18 * that the value is of indefinite length.
19 */
20ssize_t ber_fetch_length(int _is_constructed, void *bufptr, size_t size,
21 ber_tlv_len_t *len_r);
22
23/*
24 * This function expects bufptr to be positioned over L in TLV.
25 * It returns number of bytes occupied by L and V together, suitable
26 * for skipping. The function properly handles indefinite length.
27 * RETURN VALUES:
28 * Standard {-1,0,>0} convention.
29 */
Lev Walkinbaaa24f2004-09-29 14:19:14 +000030struct asn_codec_ctx_s; /* Forward declaration */
31ssize_t ber_skip_length(
32 struct asn_codec_ctx_s *opt_codec_ctx, /* optional context */
33 int _is_constructed, void *bufptr, size_t size);
Lev Walkinf15320b2004-06-03 03:38:44 +000034
35/*
36 * This function serializes the length (L from TLV) in DER format.
Lev Walkin91b29c52004-09-24 20:59:13 +000037 * It always returns number of bytes necessary to represent the length,
Lev Walkinf15320b2004-06-03 03:38:44 +000038 * it is a caller's responsibility to check the return value
39 * against the supplied buffer's size.
40 */
Lev Walkin91b29c52004-09-24 20:59:13 +000041size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size);
Lev Walkinf15320b2004-06-03 03:38:44 +000042
43#endif /* _BER_TLV_LENGTH_H_ */