2 * Copyright (c) 2005-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
5 #ifndef _UPER_SUPPORT_H_
6 #define _UPER_SUPPORT_H_
8 #include <asn_system.h> /* Platform-specific types */
9 #include <per_support.h>
16 * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
17 * Get the length "n" from the Unaligned PER stream.
19 ssize_t uper_get_length(asn_per_data_t *pd, int effective_bound_bits,
20 size_t lower_bound, int *repeat);
23 * Get the normally small length "n".
25 ssize_t uper_get_nslength(asn_per_data_t *pd);
28 * Get the normally small non-negative whole number.
30 ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
32 /* X.691-2008/11, #11.5.6 */
33 int uper_get_constrained_whole_number(asn_per_data_t *pd, uintmax_t *v, int nbits);
36 * Rebase the given value as an offset into the range specified by the
37 * lower bound (lb) and upper bound (ub).
39 * -1: Conversion failed due to range problems.
40 * 0: Conversion was successful.
42 int per_long_range_rebase(long, intmax_t lb, intmax_t ub, unsigned long *output);
43 int per_imax_range_rebase(intmax_t v, intmax_t lb, intmax_t ub, uintmax_t *output);
44 /* The inverse operation: restores the value by the offset and its bounds. */
45 int per_long_range_unrebase(unsigned long inp, intmax_t lb, intmax_t ub, long *outp);
46 int per_imax_range_unrebase(uintmax_t inp, intmax_t lb, intmax_t ub, intmax_t *outp);
48 /* X.691-2008/11, #11.5 */
49 int uper_put_constrained_whole_number_u(asn_per_outp_t *po, uintmax_t v, int nbits);
52 * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
53 * Put the length "whole_length" to the Unaligned PER stream.
54 * If (opt_need_eom) is given, it will be set to 1 if final 0-length is needed.
55 * In that case, invoke uper_put_length(po, 0, 0) after encoding the last block.
56 * This function returns the number of units which may be flushed
57 * in the next units saving iteration.
59 ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length,
63 * Put the normally small length "n" to the Unaligned PER stream.
66 int uper_put_nslength(asn_per_outp_t *po, size_t length);
69 * Put the normally small non-negative whole number.
71 int uper_put_nsnnwn(asn_per_outp_t *po, int n);
77 #endif /* _UPER_SUPPORT_H_ */