sendme_cell.h (4545B)
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 7 8 #include <stdint.h> 9 #include "trunnel.h" 10 11 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SENDME_CELL) 12 struct sendme_cell_st { 13 uint8_t version; 14 uint16_t data_len; 15 TRUNNEL_DYNARRAY_HEAD(, uint8_t) data_v1_digest; 16 uint8_t trunnel_error_code_; 17 }; 18 #endif 19 typedef struct sendme_cell_st sendme_cell_t; 20 /** Return a newly allocated sendme_cell with all elements set to 21 * zero. 22 */ 23 sendme_cell_t *sendme_cell_new(void); 24 /** Release all storage held by the sendme_cell in 'victim'. (Do 25 * nothing if 'victim' is NULL.) 26 */ 27 void sendme_cell_free(sendme_cell_t *victim); 28 /** Try to parse a sendme_cell from the buffer in 'input', using up to 29 * 'len_in' bytes from the input buffer. On success, return the number 30 * of bytes consumed and set *output to the newly allocated 31 * sendme_cell_t. On failure, return -2 if the input appears 32 * truncated, and -1 if the input is otherwise invalid. 33 */ 34 ssize_t sendme_cell_parse(sendme_cell_t **output, const uint8_t *input, const size_t len_in); 35 /** Return the number of bytes we expect to need to encode the 36 * sendme_cell in 'obj'. On failure, return a negative value. Note 37 * that this value may be an overestimate, and can even be an 38 * underestimate for certain unencodeable objects. 39 */ 40 ssize_t sendme_cell_encoded_len(const sendme_cell_t *obj); 41 /** Try to encode the sendme_cell from 'input' into the buffer at 42 * 'output', using up to 'avail' bytes of the output buffer. On 43 * success, return the number of bytes used. On failure, return -2 if 44 * the buffer was not long enough, and -1 if the input was invalid. 45 */ 46 ssize_t sendme_cell_encode(uint8_t *output, size_t avail, const sendme_cell_t *input); 47 /** Check whether the internal state of the sendme_cell in 'obj' is 48 * consistent. Return NULL if it is, and a short message if it is not. 49 */ 50 const char *sendme_cell_check(const sendme_cell_t *obj); 51 /** Clear any errors that were set on the object 'obj' by its setter 52 * functions. Return true iff errors were cleared. 53 */ 54 int sendme_cell_clear_errors(sendme_cell_t *obj); 55 /** Return the value of the version field of the sendme_cell_t in 56 * 'inp' 57 */ 58 uint8_t sendme_cell_get_version(const sendme_cell_t *inp); 59 /** Set the value of the version field of the sendme_cell_t in 'inp' 60 * to 'val'. Return 0 on success; return -1 and set the error code on 61 * 'inp' on failure. 62 */ 63 int sendme_cell_set_version(sendme_cell_t *inp, uint8_t val); 64 /** Return the value of the data_len field of the sendme_cell_t in 65 * 'inp' 66 */ 67 uint16_t sendme_cell_get_data_len(const sendme_cell_t *inp); 68 /** Set the value of the data_len field of the sendme_cell_t in 'inp' 69 * to 'val'. Return 0 on success; return -1 and set the error code on 70 * 'inp' on failure. 71 */ 72 int sendme_cell_set_data_len(sendme_cell_t *inp, uint16_t val); 73 /** Return the length of the dynamic array holding the data_v1_digest 74 * field of the sendme_cell_t in 'inp'. 75 */ 76 size_t sendme_cell_getlen_data_v1_digest(const sendme_cell_t *inp); 77 /** Return the element at position 'idx' of the dynamic array field 78 * data_v1_digest of the sendme_cell_t in 'inp'. 79 */ 80 uint8_t sendme_cell_get_data_v1_digest(sendme_cell_t *inp, size_t idx); 81 /** As sendme_cell_get_data_v1_digest, but take and return a const 82 * pointer 83 */ 84 uint8_t sendme_cell_getconst_data_v1_digest(const sendme_cell_t *inp, size_t idx); 85 /** Change the element at position 'idx' of the dynamic array field 86 * data_v1_digest of the sendme_cell_t in 'inp', so that it will hold 87 * the value 'elt'. 88 */ 89 int sendme_cell_set_data_v1_digest(sendme_cell_t *inp, size_t idx, uint8_t elt); 90 /** Append a new element 'elt' to the dynamic array field 91 * data_v1_digest of the sendme_cell_t in 'inp'. 92 */ 93 int sendme_cell_add_data_v1_digest(sendme_cell_t *inp, uint8_t elt); 94 /** Return a pointer to the variable-length array field data_v1_digest 95 * of 'inp'. 96 */ 97 uint8_t * sendme_cell_getarray_data_v1_digest(sendme_cell_t *inp); 98 /** As sendme_cell_get_data_v1_digest, but take and return a const 99 * pointer 100 */ 101 const uint8_t * sendme_cell_getconstarray_data_v1_digest(const sendme_cell_t *inp); 102 /** Change the length of the variable-length array field 103 * data_v1_digest of 'inp' to 'newlen'.Fill extra elements with 0. 104 * Return 0 on success; return -1 and set the error code on 'inp' on 105 * failure. 106 */ 107 int sendme_cell_setlen_data_v1_digest(sendme_cell_t *inp, size_t newlen); 108 109 110 #endif