aboutsummaryrefslogtreecommitdiff
path: root/src/trunnel/extension.h
blob: eed89d140e17e393019ff60dbdde4db2d67fc377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* extension.h -- generated by Trunnel v1.5.3.
 * https://gitweb.torproject.org/trunnel.git
 * You probably shouldn't edit this file.
 */
#ifndef TRUNNEL_EXTENSION_H
#define TRUNNEL_EXTENSION_H

#include <stdint.h>
#include "trunnel.h"

#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_EXTENSION_FIELD)
struct trn_extension_field_st {
  uint8_t field_type;
  uint8_t field_len;
  TRUNNEL_DYNARRAY_HEAD(, uint8_t) field;
  uint8_t trunnel_error_code_;
};
#endif
typedef struct trn_extension_field_st trn_extension_field_t;
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_EXTENSION)
struct trn_extension_st {
  uint8_t num;
  TRUNNEL_DYNARRAY_HEAD(, struct trn_extension_field_st *) fields;
  uint8_t trunnel_error_code_;
};
#endif
typedef struct trn_extension_st trn_extension_t;
/** Return a newly allocated trn_extension_field with all elements set
 * to zero.
 */
trn_extension_field_t *trn_extension_field_new(void);
/** Release all storage held by the trn_extension_field in 'victim'.
 * (Do nothing if 'victim' is NULL.)
 */
void trn_extension_field_free(trn_extension_field_t *victim);
/** Try to parse a trn_extension_field from the buffer in 'input',
 * using up to 'len_in' bytes from the input buffer. On success,
 * return the number of bytes consumed and set *output to the newly
 * allocated trn_extension_field_t. On failure, return -2 if the input
 * appears truncated, and -1 if the input is otherwise invalid.
 */
ssize_t trn_extension_field_parse(trn_extension_field_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the
 * trn_extension_field in 'obj'. On failure, return a negative value.
 * Note that this value may be an overestimate, and can even be an
 * underestimate for certain unencodeable objects.
 */
ssize_t trn_extension_field_encoded_len(const trn_extension_field_t *obj);
/** Try to encode the trn_extension_field from 'input' into the buffer
 * at 'output', using up to 'avail' bytes of the output buffer. On
 * success, return the number of bytes used. On failure, return -2 if
 * the buffer was not long enough, and -1 if the input was invalid.
 */
ssize_t trn_extension_field_encode(uint8_t *output, size_t avail, const trn_extension_field_t *input);
/** Check whether the internal state of the trn_extension_field in
 * 'obj' is consistent. Return NULL if it is, and a short message if
 * it is not.
 */
const char *trn_extension_field_check(const trn_extension_field_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter
 * functions. Return true iff errors were cleared.
 */
int trn_extension_field_clear_errors(trn_extension_field_t *obj);
/** Return the value of the field_type field of the
 * trn_extension_field_t in 'inp'
 */
uint8_t trn_extension_field_get_field_type(const trn_extension_field_t *inp);
/** Set the value of the field_type field of the trn_extension_field_t
 * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
 * code on 'inp' on failure.
 */
int trn_extension_field_set_field_type(trn_extension_field_t *inp, uint8_t val);
/** Return the value of the field_len field of the
 * trn_extension_field_t in 'inp'
 */
uint8_t trn_extension_field_get_field_len(const trn_extension_field_t *inp);
/** Set the value of the field_len field of the trn_extension_field_t
 * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
 * code on 'inp' on failure.
 */
int trn_extension_field_set_field_len(trn_extension_field_t *inp, uint8_t val);
/** Return the length of the dynamic array holding the field field of
 * the trn_extension_field_t in 'inp'.
 */
size_t trn_extension_field_getlen_field(const trn_extension_field_t *inp);
/** Return the element at position 'idx' of the dynamic array field
 * field of the trn_extension_field_t in 'inp'.
 */
uint8_t trn_extension_field_get_field(trn_extension_field_t *inp, size_t idx);
/** As trn_extension_field_get_field, but take and return a const
 * pointer
 */
uint8_t trn_extension_field_getconst_field(const trn_extension_field_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field
 * field of the trn_extension_field_t in 'inp', so that it will hold
 * the value 'elt'.
 */
int trn_extension_field_set_field(trn_extension_field_t *inp, size_t idx, uint8_t elt);
/** Append a new element 'elt' to the dynamic array field field of the
 * trn_extension_field_t in 'inp'.
 */
int trn_extension_field_add_field(trn_extension_field_t *inp, uint8_t elt);
/** Return a pointer to the variable-length array field field of
 * 'inp'.
 */
uint8_t * trn_extension_field_getarray_field(trn_extension_field_t *inp);
/** As trn_extension_field_get_field, but take and return a const
 * pointer
 */
const uint8_t  * trn_extension_field_getconstarray_field(const trn_extension_field_t *inp);
/** Change the length of the variable-length array field field of
 * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
 * return -1 and set the error code on 'inp' on failure.
 */
int trn_extension_field_setlen_field(trn_extension_field_t *inp, size_t newlen);
/** Return a newly allocated trn_extension with all elements set to
 * zero.
 */
trn_extension_t *trn_extension_new(void);
/** Release all storage held by the trn_extension in 'victim'. (Do
 * nothing if 'victim' is NULL.)
 */
void trn_extension_free(trn_extension_t *victim);
/** Try to parse a trn_extension from the buffer in 'input', using up
 * to 'len_in' bytes from the input buffer. On success, return the
 * number of bytes consumed and set *output to the newly allocated
 * trn_extension_t. On failure, return -2 if the input appears
 * truncated, and -1 if the input is otherwise invalid.
 */
ssize_t trn_extension_parse(trn_extension_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the
 * trn_extension in 'obj'. On failure, return a negative value. Note
 * that this value may be an overestimate, and can even be an
 * underestimate for certain unencodeable objects.
 */
ssize_t trn_extension_encoded_len(const trn_extension_t *obj);
/** Try to encode the trn_extension from 'input' into the buffer at
 * 'output', using up to 'avail' bytes of the output buffer. On
 * success, return the number of bytes used. On failure, return -2 if
 * the buffer was not long enough, and -1 if the input was invalid.
 */
ssize_t trn_extension_encode(uint8_t *output, size_t avail, const trn_extension_t *input);
/** Check whether the internal state of the trn_extension in 'obj' is
 * consistent. Return NULL if it is, and a short message if it is not.
 */
const char *trn_extension_check(const trn_extension_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter
 * functions. Return true iff errors were cleared.
 */
int trn_extension_clear_errors(trn_extension_t *obj);
/** Return the value of the num field of the trn_extension_t in 'inp'
 */
uint8_t trn_extension_get_num(const trn_extension_t *inp);
/** Set the value of the num field of the trn_extension_t in 'inp' to
 * 'val'. Return 0 on success; return -1 and set the error code on
 * 'inp' on failure.
 */
int trn_extension_set_num(trn_extension_t *inp, uint8_t val);
/** Return the length of the dynamic array holding the fields field of
 * the trn_extension_t in 'inp'.
 */
size_t trn_extension_getlen_fields(const trn_extension_t *inp);
/** Return the element at position 'idx' of the dynamic array field
 * fields of the trn_extension_t in 'inp'.
 */
struct trn_extension_field_st * trn_extension_get_fields(trn_extension_t *inp, size_t idx);
/** As trn_extension_get_fields, but take and return a const pointer
 */
 const struct trn_extension_field_st * trn_extension_getconst_fields(const trn_extension_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field
 * fields of the trn_extension_t in 'inp', so that it will hold the
 * value 'elt'. Free the previous value, if any.
 */
int trn_extension_set_fields(trn_extension_t *inp, size_t idx, struct trn_extension_field_st * elt);
/** As trn_extension_set_fields, but does not free the previous value.
 */
int trn_extension_set0_fields(trn_extension_t *inp, size_t idx, struct trn_extension_field_st * elt);
/** Append a new element 'elt' to the dynamic array field fields of
 * the trn_extension_t in 'inp'.
 */
int trn_extension_add_fields(trn_extension_t *inp, struct trn_extension_field_st * elt);
/** Return a pointer to the variable-length array field fields of
 * 'inp'.
 */
struct trn_extension_field_st * * trn_extension_getarray_fields(trn_extension_t *inp);
/** As trn_extension_get_fields, but take and return a const pointer
 */
const struct trn_extension_field_st *  const  * trn_extension_getconstarray_fields(const trn_extension_t *inp);
/** Change the length of the variable-length array field fields of
 * 'inp' to 'newlen'.Fill extra elements with NULL; free removed
 * elements. Return 0 on success; return -1 and set the error code on
 * 'inp' on failure.
 */
int trn_extension_setlen_fields(trn_extension_t *inp, size_t newlen);


#endif