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
|
/* sendme.h -- generated by Trunnel v1.5.2.
* https://gitweb.torproject.org/trunnel.git
* You probably shouldn't edit this file.
*/
#ifndef TRUNNEL_SENDME_H
#define TRUNNEL_SENDME_H
#include <stdint.h>
#include "trunnel.h"
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SENDME_CELL)
struct sendme_cell_st {
uint8_t version;
uint16_t data_len;
TRUNNEL_DYNARRAY_HEAD(, uint8_t) data;
uint8_t trunnel_error_code_;
};
#endif
typedef struct sendme_cell_st sendme_cell_t;
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SENDME_DATA_V1)
struct sendme_data_v1_st {
uint8_t digest[4];
uint8_t trunnel_error_code_;
};
#endif
typedef struct sendme_data_v1_st sendme_data_v1_t;
/** Return a newly allocated sendme_cell with all elements set to
* zero.
*/
sendme_cell_t *sendme_cell_new(void);
/** Release all storage held by the sendme_cell in 'victim'. (Do
* nothing if 'victim' is NULL.)
*/
void sendme_cell_free(sendme_cell_t *victim);
/** Try to parse a sendme_cell 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
* sendme_cell_t. On failure, return -2 if the input appears
* truncated, and -1 if the input is otherwise invalid.
*/
ssize_t sendme_cell_parse(sendme_cell_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the
* sendme_cell 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 sendme_cell_encoded_len(const sendme_cell_t *obj);
/** Try to encode the sendme_cell 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 sendme_cell_encode(uint8_t *output, size_t avail, const sendme_cell_t *input);
/** Check whether the internal state of the sendme_cell in 'obj' is
* consistent. Return NULL if it is, and a short message if it is not.
*/
const char *sendme_cell_check(const sendme_cell_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter
* functions. Return true iff errors were cleared.
*/
int sendme_cell_clear_errors(sendme_cell_t *obj);
/** Return the value of the version field of the sendme_cell_t in
* 'inp'
*/
uint8_t sendme_cell_get_version(const sendme_cell_t *inp);
/** Set the value of the version field of the sendme_cell_t in 'inp'
* to 'val'. Return 0 on success; return -1 and set the error code on
* 'inp' on failure.
*/
int sendme_cell_set_version(sendme_cell_t *inp, uint8_t val);
/** Return the value of the data_len field of the sendme_cell_t in
* 'inp'
*/
uint16_t sendme_cell_get_data_len(const sendme_cell_t *inp);
/** Set the value of the data_len field of the sendme_cell_t in 'inp'
* to 'val'. Return 0 on success; return -1 and set the error code on
* 'inp' on failure.
*/
int sendme_cell_set_data_len(sendme_cell_t *inp, uint16_t val);
/** Return the length of the dynamic array holding the data field of
* the sendme_cell_t in 'inp'.
*/
size_t sendme_cell_getlen_data(const sendme_cell_t *inp);
/** Return the element at position 'idx' of the dynamic array field
* data of the sendme_cell_t in 'inp'.
*/
uint8_t sendme_cell_get_data(sendme_cell_t *inp, size_t idx);
/** As sendme_cell_get_data, but take and return a const pointer
*/
uint8_t sendme_cell_getconst_data(const sendme_cell_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field
* data of the sendme_cell_t in 'inp', so that it will hold the value
* 'elt'.
*/
int sendme_cell_set_data(sendme_cell_t *inp, size_t idx, uint8_t elt);
/** Append a new element 'elt' to the dynamic array field data of the
* sendme_cell_t in 'inp'.
*/
int sendme_cell_add_data(sendme_cell_t *inp, uint8_t elt);
/** Return a pointer to the variable-length array field data of 'inp'.
*/
uint8_t * sendme_cell_getarray_data(sendme_cell_t *inp);
/** As sendme_cell_get_data, but take and return a const pointer
*/
const uint8_t * sendme_cell_getconstarray_data(const sendme_cell_t *inp);
/** Change the length of the variable-length array field data 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 sendme_cell_setlen_data(sendme_cell_t *inp, size_t newlen);
/** Return a newly allocated sendme_data_v1 with all elements set to
* zero.
*/
sendme_data_v1_t *sendme_data_v1_new(void);
/** Release all storage held by the sendme_data_v1 in 'victim'. (Do
* nothing if 'victim' is NULL.)
*/
void sendme_data_v1_free(sendme_data_v1_t *victim);
/** Try to parse a sendme_data_v1 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
* sendme_data_v1_t. On failure, return -2 if the input appears
* truncated, and -1 if the input is otherwise invalid.
*/
ssize_t sendme_data_v1_parse(sendme_data_v1_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the
* sendme_data_v1 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 sendme_data_v1_encoded_len(const sendme_data_v1_t *obj);
/** Try to encode the sendme_data_v1 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 sendme_data_v1_encode(uint8_t *output, size_t avail, const sendme_data_v1_t *input);
/** Check whether the internal state of the sendme_data_v1 in 'obj' is
* consistent. Return NULL if it is, and a short message if it is not.
*/
const char *sendme_data_v1_check(const sendme_data_v1_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter
* functions. Return true iff errors were cleared.
*/
int sendme_data_v1_clear_errors(sendme_data_v1_t *obj);
/** Return the (constant) length of the array holding the digest field
* of the sendme_data_v1_t in 'inp'.
*/
size_t sendme_data_v1_getlen_digest(const sendme_data_v1_t *inp);
/** Return the element at position 'idx' of the fixed array field
* digest of the sendme_data_v1_t in 'inp'.
*/
uint8_t sendme_data_v1_get_digest(sendme_data_v1_t *inp, size_t idx);
/** As sendme_data_v1_get_digest, but take and return a const pointer
*/
uint8_t sendme_data_v1_getconst_digest(const sendme_data_v1_t *inp, size_t idx);
/** Change the element at position 'idx' of the fixed array field
* digest of the sendme_data_v1_t in 'inp', so that it will hold the
* value 'elt'.
*/
int sendme_data_v1_set_digest(sendme_data_v1_t *inp, size_t idx, uint8_t elt);
/** Return a pointer to the 4-element array field digest of 'inp'.
*/
uint8_t * sendme_data_v1_getarray_digest(sendme_data_v1_t *inp);
/** As sendme_data_v1_get_digest, but take and return a const pointer
*/
const uint8_t * sendme_data_v1_getconstarray_digest(const sendme_data_v1_t *inp);
#endif
|