blob: 7e5d5f8aaade9ffd2883eda95eba606e1f95bd3b [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 */
30ssize_t ber_skip_length(int _is_constructed, void *bufptr, size_t size);
31
32/*
33 * This function serializes the length (L from TLV) in DER format.
34 * It always return number of bytes necessary to represent the length,
35 * it is a caller's responsibility to check the return value
36 * against the supplied buffer's size.
37 */
38ssize_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size);
39
40#endif /* _BER_TLV_LENGTH_H_ */