ITS
per_support.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005-2014 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #ifndef _PER_SUPPORT_H_
7 #define _PER_SUPPORT_H_
8 
9 #include <asn_system.h> /* Platform-specific types */
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /*
16  * Pre-computed PER constraints.
17  */
18 typedef struct asn_per_constraint_s {
20  APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */
21  APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */
22  APC_CONSTRAINED = 0x2, /* Fully constrained */
23  APC_EXTENSIBLE = 0x4 /* May have extension */
24  } flags;
25  int range_bits; /* Full number of bits in the range */
26  int effective_bits; /* Effective bits */
27  long lower_bound; /* "lb" value */
28  long upper_bound; /* "ub" value */
30 typedef struct asn_per_constraints_s {
33  int (*value2code)(unsigned int value);
34  int (*code2value)(unsigned int code);
36 
37 /*
38  * This structure describes a position inside an incoming PER bit stream.
39  */
40 typedef struct asn_per_data_s {
41  const uint8_t *buffer; /* Pointer to the octet stream */
42  size_t nboff; /* Bit offset to the meaningful bit */
43  size_t nbits; /* Number of bits in the stream */
44  size_t moved; /* Number of bits moved through this bit stream */
45  int (*refill)(struct asn_per_data_s *);
46  void *refill_key;
48 
49 /*
50  * Extract a small number of bits (<= 31) from the specified PER data pointer.
51  * This function returns -1 if the specified number of bits could not be
52  * extracted due to EOD or other conditions.
53  */
54 int32_t per_get_few_bits(asn_per_data_t *per_data, int get_nbits);
55 
56 /* Undo the immediately preceeding "get_few_bits" operation */
57 void per_get_undo(asn_per_data_t *per_data, int get_nbits);
58 
59 /*
60  * Extract a large number of bits from the specified PER data pointer.
61  * This function returns -1 if the specified number of bits could not be
62  * extracted due to EOD or other conditions.
63  */
64 int per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int right_align,
65  int get_nbits);
66 
67 /*
68  * Get the length "n" from the Unaligned PER stream.
69  */
71  int effective_bound_bits,
72  int *repeat);
73 
74 /*
75  * Get the normally small length "n".
76  */
78 
79 /*
80  * Get the normally small non-negative whole number.
81  */
82 ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
83 
84 /* X.691-2008/11, #11.5.6 */
85 int uper_get_constrained_whole_number(asn_per_data_t *pd, unsigned long *v, int nbits);
86 
87 /* Non-thread-safe debugging function, don't use it */
89 
90 /*
91  * This structure supports forming PER output.
92  */
93 typedef struct asn_per_outp_s {
94  uint8_t *buffer; /* Pointer into the (tmpspace) */
95  size_t nboff; /* Bit offset to the meaningful bit */
96  size_t nbits; /* Number of bits left in (tmpspace) */
97  uint8_t tmpspace[32]; /* Preliminary storage to hold data */
98  int (*outper)(const void *data, size_t size, void *op_key);
99  void *op_key; /* Key for (outper) data callback */
100  size_t flushed_bytes; /* Bytes already flushed through (outper) */
102 
103 /* Output a small number of bits (<= 31) */
104 int per_put_few_bits(asn_per_outp_t *per_data, uint32_t bits, int obits);
105 
106 /* Output a large number of bits */
107 int per_put_many_bits(asn_per_outp_t *po, const uint8_t *src, int put_nbits);
108 
109 /* X.691-2008/11, #11.5 */
110 int uper_put_constrained_whole_number_s(asn_per_outp_t *po, long v, int nbits);
111 int uper_put_constrained_whole_number_u(asn_per_outp_t *po, unsigned long v, int nbits);
112 
113 /*
114  * Put the length "n" to the Unaligned PER stream.
115  * This function returns the number of units which may be flushed
116  * in the next units saving iteration.
117  */
118 ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length);
119 
120 /*
121  * Put the normally small length "n" to the Unaligned PER stream.
122  * Returns 0 or -1.
123  */
124 int uper_put_nslength(asn_per_outp_t *po, size_t length);
125 
126 /*
127  * Put the normally small non-negative whole number.
128  */
129 int uper_put_nsnnwn(asn_per_outp_t *po, int n);
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif /* _PER_SUPPORT_H_ */
int(* value2code)(unsigned int value)
Definition: per_support.h:33
int(* outper)(const void *data, size_t size, void *op_key)
Definition: per_support.h:98
int per_put_many_bits(asn_per_outp_t *po, const uint8_t *src, int put_nbits)
Definition: per_support.c:413
int uper_put_constrained_whole_number_s(asn_per_outp_t *po, long v, int nbits)
Definition: per_support.c:294
asn_per_constraint_t size
Definition: per_support.h:32
enum asn_per_constraint_s::asn_per_constraint_flags flags
int per_put_few_bits(asn_per_outp_t *per_data, uint32_t bits, int obits)
Definition: per_support.c:323
uint8_t * buffer
Definition: per_support.h:94
ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length)
Definition: per_support.c:445
int uper_put_nsnnwn(asn_per_outp_t *po, int n)
Definition: per_support.c:245
asn_per_constraint_t value
Definition: per_support.h:31
struct asn_per_data_s asn_per_data_t
int per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int right_align, int get_nbits)
Definition: per_support.c:123
int uper_get_constrained_whole_number(asn_per_data_t *pd, unsigned long *v, int nbits)
Definition: per_support.c:268
int32_t per_get_few_bits(asn_per_data_t *per_data, int get_nbits)
Definition: per_support.c:38
int uper_put_nslength(asn_per_outp_t *po, size_t length)
Definition: per_support.c:468
struct asn_per_constraints_s asn_per_constraints_t
size_t flushed_bytes
Definition: per_support.h:100
ssize_t uper_get_length(asn_per_data_t *pd, int effective_bound_bits, int *repeat)
Definition: per_support.c:167
int(* refill)(struct asn_per_data_s *)
Definition: per_support.h:45
void per_get_undo(asn_per_data_t *per_data, int get_nbits)
Definition: per_support.c:25
void * refill_key
Definition: per_support.h:46
const uint8_t * buffer
Definition: per_support.h:41
struct asn_per_constraint_s asn_per_constraint_t
ssize_t uper_get_nsnnwn(asn_per_data_t *pd)
Definition: per_support.c:219
char * per_data_string(asn_per_data_t *pd)
Definition: per_support.c:11
int(* code2value)(unsigned int code)
Definition: per_support.h:34
uint8_t tmpspace[32]
Definition: per_support.h:97
struct asn_per_outp_s asn_per_outp_t
ssize_t uper_get_nslength(asn_per_data_t *pd)
Definition: per_support.c:196
int uper_put_constrained_whole_number_u(asn_per_outp_t *po, unsigned long v, int nbits)
Definition: per_support.c:308