sendme_cell.h 4.0 KB

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