Merge branch 'maint-0.4.5' into release-0.4.5
[tor.git] / src / trunnel / sendme_cell.h
blob45efb9f10dc206d758316e459ef77baf5dff5f6f
1 /* sendme_cell.h -- generated by Trunnel v1.5.3.
2 * https://gitweb.torproject.org/trunnel.git
3 * You probably shouldn't edit this file.
4 */
5 #ifndef TRUNNEL_SENDME_CELL_H
6 #define TRUNNEL_SENDME_CELL_H
8 #include <stdint.h>
9 #include "trunnel.h"
11 #define TRUNNEL_SENDME_V1_DIGEST_LEN 20
12 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SENDME_CELL)
13 struct sendme_cell_st {
14 uint8_t version;
15 uint16_t data_len;
16 uint8_t data_v1_digest[TRUNNEL_SENDME_V1_DIGEST_LEN];
17 uint8_t trunnel_error_code_;
19 #endif
20 typedef struct sendme_cell_st sendme_cell_t;
21 /** Return a newly allocated sendme_cell with all elements set to
22 * zero.
24 sendme_cell_t *sendme_cell_new(void);
25 /** Release all storage held by the sendme_cell in 'victim'. (Do
26 * nothing if 'victim' is NULL.)
28 void sendme_cell_free(sendme_cell_t *victim);
29 /** Try to parse a sendme_cell from the buffer in 'input', using up to
30 * 'len_in' bytes from the input buffer. On success, return the number
31 * of bytes consumed and set *output to the newly allocated
32 * sendme_cell_t. On failure, return -2 if the input appears
33 * truncated, and -1 if the input is otherwise invalid.
35 ssize_t sendme_cell_parse(sendme_cell_t **output, const uint8_t *input, const size_t len_in);
36 /** Return the number of bytes we expect to need to encode the
37 * sendme_cell in 'obj'. On failure, return a negative value. Note
38 * that this value may be an overestimate, and can even be an
39 * underestimate for certain unencodeable objects.
41 ssize_t sendme_cell_encoded_len(const sendme_cell_t *obj);
42 /** Try to encode the sendme_cell from 'input' into the buffer at
43 * 'output', using up to 'avail' bytes of the output buffer. On
44 * success, return the number of bytes used. On failure, return -2 if
45 * the buffer was not long enough, and -1 if the input was invalid.
47 ssize_t sendme_cell_encode(uint8_t *output, size_t avail, const sendme_cell_t *input);
48 /** Check whether the internal state of the sendme_cell in 'obj' is
49 * consistent. Return NULL if it is, and a short message if it is not.
51 const char *sendme_cell_check(const sendme_cell_t *obj);
52 /** Clear any errors that were set on the object 'obj' by its setter
53 * functions. Return true iff errors were cleared.
55 int sendme_cell_clear_errors(sendme_cell_t *obj);
56 /** Return the value of the version field of the sendme_cell_t in
57 * 'inp'
59 uint8_t sendme_cell_get_version(const sendme_cell_t *inp);
60 /** Set the value of the version field of the sendme_cell_t in 'inp'
61 * to 'val'. Return 0 on success; return -1 and set the error code on
62 * 'inp' on failure.
64 int sendme_cell_set_version(sendme_cell_t *inp, uint8_t val);
65 /** Return the value of the data_len field of the sendme_cell_t in
66 * 'inp'
68 uint16_t sendme_cell_get_data_len(const sendme_cell_t *inp);
69 /** Set the value of the data_len field of the sendme_cell_t in 'inp'
70 * to 'val'. Return 0 on success; return -1 and set the error code on
71 * 'inp' on failure.
73 int sendme_cell_set_data_len(sendme_cell_t *inp, uint16_t val);
74 /** Return the (constant) length of the array holding the
75 * data_v1_digest field of the sendme_cell_t in 'inp'.
77 size_t sendme_cell_getlen_data_v1_digest(const sendme_cell_t *inp);
78 /** Return the element at position 'idx' of the fixed array field
79 * data_v1_digest of the sendme_cell_t in 'inp'.
81 uint8_t sendme_cell_get_data_v1_digest(sendme_cell_t *inp, size_t idx);
82 /** As sendme_cell_get_data_v1_digest, but take and return a const
83 * pointer
85 uint8_t sendme_cell_getconst_data_v1_digest(const sendme_cell_t *inp, size_t idx);
86 /** Change the element at position 'idx' of the fixed array field
87 * data_v1_digest of the sendme_cell_t in 'inp', so that it will hold
88 * the value 'elt'.
90 int sendme_cell_set_data_v1_digest(sendme_cell_t *inp, size_t idx, uint8_t elt);
91 /** Return a pointer to the TRUNNEL_SENDME_V1_DIGEST_LEN-element array
92 * field data_v1_digest of 'inp'.
94 uint8_t * sendme_cell_getarray_data_v1_digest(sendme_cell_t *inp);
95 /** As sendme_cell_get_data_v1_digest, but take and return a const
96 * pointer
98 const uint8_t * sendme_cell_getconstarray_data_v1_digest(const sendme_cell_t *inp);
101 #endif