ed25519_cert.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /* ed25519_cert.h -- generated by by Trunnel v1.5.
  2. * https://gitweb.torproject.org/trunnel.git
  3. * You probably shouldn't edit this file.
  4. */
  5. #ifndef TRUNNEL_ED25519_CERT_H
  6. #define TRUNNEL_ED25519_CERT_H
  7. #include <stdint.h>
  8. #include "trunnel.h"
  9. #define CERTEXT_SIGNED_WITH_KEY 4
  10. #define CERTEXT_FLAG_AFFECTS_VALIDATION 1
  11. #define LS_IPV4 0
  12. #define LS_IPV6 1
  13. #define LS_LEGACY_ID 2
  14. #define LS_ED25519_ID 3
  15. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_ED25519_CERT_EXTENSION)
  16. struct ed25519_cert_extension_st {
  17. uint16_t ext_length;
  18. uint8_t ext_type;
  19. uint8_t ext_flags;
  20. uint8_t un_signing_key[32];
  21. TRUNNEL_DYNARRAY_HEAD(, uint8_t) un_unparsed;
  22. uint8_t trunnel_error_code_;
  23. };
  24. #endif
  25. typedef struct ed25519_cert_extension_st ed25519_cert_extension_t;
  26. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_LINK_SPECIFIER)
  27. struct link_specifier_st {
  28. uint8_t ls_type;
  29. uint8_t ls_len;
  30. uint32_t un_ipv4_addr;
  31. uint16_t un_ipv4_port;
  32. uint8_t un_ipv6_addr[16];
  33. uint16_t un_ipv6_port;
  34. uint8_t un_legacy_id[20];
  35. uint8_t un_ed25519_id[32];
  36. TRUNNEL_DYNARRAY_HEAD(, uint8_t) un_unrecognized;
  37. uint8_t trunnel_error_code_;
  38. };
  39. #endif
  40. typedef struct link_specifier_st link_specifier_t;
  41. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_ED25519_CERT)
  42. struct ed25519_cert_st {
  43. uint8_t version;
  44. uint8_t cert_type;
  45. uint32_t exp_field;
  46. uint8_t cert_key_type;
  47. uint8_t certified_key[32];
  48. uint8_t n_extensions;
  49. TRUNNEL_DYNARRAY_HEAD(, struct ed25519_cert_extension_st *) ext;
  50. uint8_t signature[64];
  51. uint8_t trunnel_error_code_;
  52. };
  53. #endif
  54. typedef struct ed25519_cert_st ed25519_cert_t;
  55. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_LINK_SPECIFIER_LIST)
  56. struct link_specifier_list_st {
  57. uint8_t n_spec;
  58. TRUNNEL_DYNARRAY_HEAD(, struct link_specifier_st *) spec;
  59. uint8_t trunnel_error_code_;
  60. };
  61. #endif
  62. typedef struct link_specifier_list_st link_specifier_list_t;
  63. /** Return a newly allocated ed25519_cert_extension with all elements
  64. * set to zero.
  65. */
  66. ed25519_cert_extension_t *ed25519_cert_extension_new(void);
  67. /** Release all storage held by the ed25519_cert_extension in
  68. * 'victim'. (Do nothing if 'victim' is NULL.)
  69. */
  70. void ed25519_cert_extension_free(ed25519_cert_extension_t *victim);
  71. /** Try to parse a ed25519_cert_extension from the buffer in 'input',
  72. * using up to 'len_in' bytes from the input buffer. On success,
  73. * return the number of bytes consumed and set *output to the newly
  74. * allocated ed25519_cert_extension_t. On failure, return -2 if the
  75. * input appears truncated, and -1 if the input is otherwise invalid.
  76. */
  77. ssize_t ed25519_cert_extension_parse(ed25519_cert_extension_t **output, const uint8_t *input, const size_t len_in);
  78. /** Return the number of bytes we expect to need to encode the
  79. * ed25519_cert_extension in 'obj'. On failure, return a negative
  80. * value. Note that this value may be an overestimate, and can even be
  81. * an underestimate for certain unencodeable objects.
  82. */
  83. ssize_t ed25519_cert_extension_encoded_len(const ed25519_cert_extension_t *obj);
  84. /** Try to encode the ed25519_cert_extension from 'input' into the
  85. * buffer at 'output', using up to 'avail' bytes of the output buffer.
  86. * On success, return the number of bytes used. On failure, return -2
  87. * if the buffer was not long enough, and -1 if the input was invalid.
  88. */
  89. ssize_t ed25519_cert_extension_encode(uint8_t *output, size_t avail, const ed25519_cert_extension_t *input);
  90. /** Check whether the internal state of the ed25519_cert_extension in
  91. * 'obj' is consistent. Return NULL if it is, and a short message if
  92. * it is not.
  93. */
  94. const char *ed25519_cert_extension_check(const ed25519_cert_extension_t *obj);
  95. /** Clear any errors that were set on the object 'obj' by its setter
  96. * functions. Return true iff errors were cleared.
  97. */
  98. int ed25519_cert_extension_clear_errors(ed25519_cert_extension_t *obj);
  99. /** Return the value of the ext_length field of the
  100. * ed25519_cert_extension_t in 'inp'
  101. */
  102. uint16_t ed25519_cert_extension_get_ext_length(ed25519_cert_extension_t *inp);
  103. /** Set the value of the ext_length field of the
  104. * ed25519_cert_extension_t in 'inp' to 'val'. Return 0 on success;
  105. * return -1 and set the error code on 'inp' on failure.
  106. */
  107. int ed25519_cert_extension_set_ext_length(ed25519_cert_extension_t *inp, uint16_t val);
  108. /** Return the value of the ext_type field of the
  109. * ed25519_cert_extension_t in 'inp'
  110. */
  111. uint8_t ed25519_cert_extension_get_ext_type(ed25519_cert_extension_t *inp);
  112. /** Set the value of the ext_type field of the
  113. * ed25519_cert_extension_t in 'inp' to 'val'. Return 0 on success;
  114. * return -1 and set the error code on 'inp' on failure.
  115. */
  116. int ed25519_cert_extension_set_ext_type(ed25519_cert_extension_t *inp, uint8_t val);
  117. /** Return the value of the ext_flags field of the
  118. * ed25519_cert_extension_t in 'inp'
  119. */
  120. uint8_t ed25519_cert_extension_get_ext_flags(ed25519_cert_extension_t *inp);
  121. /** Set the value of the ext_flags field of the
  122. * ed25519_cert_extension_t in 'inp' to 'val'. Return 0 on success;
  123. * return -1 and set the error code on 'inp' on failure.
  124. */
  125. int ed25519_cert_extension_set_ext_flags(ed25519_cert_extension_t *inp, uint8_t val);
  126. /** Return the (constant) length of the array holding the
  127. * un_signing_key field of the ed25519_cert_extension_t in 'inp'.
  128. */
  129. size_t ed25519_cert_extension_getlen_un_signing_key(const ed25519_cert_extension_t *inp);
  130. /** Return the element at position 'idx' of the fixed array field
  131. * un_signing_key of the ed25519_cert_extension_t in 'inp'.
  132. */
  133. uint8_t ed25519_cert_extension_get_un_signing_key(ed25519_cert_extension_t *inp, size_t idx);
  134. /** As ed25519_cert_extension_get_un_signing_key, but take and return
  135. * a const pointer
  136. */
  137. uint8_t ed25519_cert_extension_getconst_un_signing_key(const ed25519_cert_extension_t *inp, size_t idx);
  138. /** Change the element at position 'idx' of the fixed array field
  139. * un_signing_key of the ed25519_cert_extension_t in 'inp', so that it
  140. * will hold the value 'elt'.
  141. */
  142. int ed25519_cert_extension_set_un_signing_key(ed25519_cert_extension_t *inp, size_t idx, uint8_t elt);
  143. /** Return a pointer to the 32-element array field un_signing_key of
  144. * 'inp'.
  145. */
  146. uint8_t * ed25519_cert_extension_getarray_un_signing_key(ed25519_cert_extension_t *inp);
  147. /** As ed25519_cert_extension_get_un_signing_key, but take and return
  148. * a const pointer
  149. */
  150. const uint8_t * ed25519_cert_extension_getconstarray_un_signing_key(const ed25519_cert_extension_t *inp);
  151. /** Return the length of the dynamic array holding the un_unparsed
  152. * field of the ed25519_cert_extension_t in 'inp'.
  153. */
  154. size_t ed25519_cert_extension_getlen_un_unparsed(const ed25519_cert_extension_t *inp);
  155. /** Return the element at position 'idx' of the dynamic array field
  156. * un_unparsed of the ed25519_cert_extension_t in 'inp'.
  157. */
  158. uint8_t ed25519_cert_extension_get_un_unparsed(ed25519_cert_extension_t *inp, size_t idx);
  159. /** As ed25519_cert_extension_get_un_unparsed, but take and return a
  160. * const pointer
  161. */
  162. uint8_t ed25519_cert_extension_getconst_un_unparsed(const ed25519_cert_extension_t *inp, size_t idx);
  163. /** Change the element at position 'idx' of the dynamic array field
  164. * un_unparsed of the ed25519_cert_extension_t in 'inp', so that it
  165. * will hold the value 'elt'.
  166. */
  167. int ed25519_cert_extension_set_un_unparsed(ed25519_cert_extension_t *inp, size_t idx, uint8_t elt);
  168. /** Append a new element 'elt' to the dynamic array field un_unparsed
  169. * of the ed25519_cert_extension_t in 'inp'.
  170. */
  171. int ed25519_cert_extension_add_un_unparsed(ed25519_cert_extension_t *inp, uint8_t elt);
  172. /** Return a pointer to the variable-length array field un_unparsed of
  173. * 'inp'.
  174. */
  175. uint8_t * ed25519_cert_extension_getarray_un_unparsed(ed25519_cert_extension_t *inp);
  176. /** As ed25519_cert_extension_get_un_unparsed, but take and return a
  177. * const pointer
  178. */
  179. const uint8_t * ed25519_cert_extension_getconstarray_un_unparsed(const ed25519_cert_extension_t *inp);
  180. /** Change the length of the variable-length array field un_unparsed
  181. * of 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on
  182. * success; return -1 and set the error code on 'inp' on failure.
  183. */
  184. int ed25519_cert_extension_setlen_un_unparsed(ed25519_cert_extension_t *inp, size_t newlen);
  185. /** Return a newly allocated link_specifier with all elements set to
  186. * zero.
  187. */
  188. link_specifier_t *link_specifier_new(void);
  189. /** Release all storage held by the link_specifier in 'victim'. (Do
  190. * nothing if 'victim' is NULL.)
  191. */
  192. void link_specifier_free(link_specifier_t *victim);
  193. /** Try to parse a link_specifier from the buffer in 'input', using up
  194. * to 'len_in' bytes from the input buffer. On success, return the
  195. * number of bytes consumed and set *output to the newly allocated
  196. * link_specifier_t. On failure, return -2 if the input appears
  197. * truncated, and -1 if the input is otherwise invalid.
  198. */
  199. ssize_t link_specifier_parse(link_specifier_t **output, const uint8_t *input, const size_t len_in);
  200. /** Return the number of bytes we expect to need to encode the
  201. * link_specifier in 'obj'. On failure, return a negative value. Note
  202. * that this value may be an overestimate, and can even be an
  203. * underestimate for certain unencodeable objects.
  204. */
  205. ssize_t link_specifier_encoded_len(const link_specifier_t *obj);
  206. /** Try to encode the link_specifier from 'input' into the buffer at
  207. * 'output', using up to 'avail' bytes of the output buffer. On
  208. * success, return the number of bytes used. On failure, return -2 if
  209. * the buffer was not long enough, and -1 if the input was invalid.
  210. */
  211. ssize_t link_specifier_encode(uint8_t *output, size_t avail, const link_specifier_t *input);
  212. /** Check whether the internal state of the link_specifier in 'obj' is
  213. * consistent. Return NULL if it is, and a short message if it is not.
  214. */
  215. const char *link_specifier_check(const link_specifier_t *obj);
  216. /** Clear any errors that were set on the object 'obj' by its setter
  217. * functions. Return true iff errors were cleared.
  218. */
  219. int link_specifier_clear_errors(link_specifier_t *obj);
  220. /** Return the value of the ls_type field of the link_specifier_t in
  221. * 'inp'
  222. */
  223. uint8_t link_specifier_get_ls_type(link_specifier_t *inp);
  224. /** Set the value of the ls_type field of the link_specifier_t in
  225. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  226. * code on 'inp' on failure.
  227. */
  228. int link_specifier_set_ls_type(link_specifier_t *inp, uint8_t val);
  229. /** Return the value of the ls_len field of the link_specifier_t in
  230. * 'inp'
  231. */
  232. uint8_t link_specifier_get_ls_len(link_specifier_t *inp);
  233. /** Set the value of the ls_len field of the link_specifier_t in 'inp'
  234. * to 'val'. Return 0 on success; return -1 and set the error code on
  235. * 'inp' on failure.
  236. */
  237. int link_specifier_set_ls_len(link_specifier_t *inp, uint8_t val);
  238. /** Return the value of the un_ipv4_addr field of the link_specifier_t
  239. * in 'inp'
  240. */
  241. uint32_t link_specifier_get_un_ipv4_addr(link_specifier_t *inp);
  242. /** Set the value of the un_ipv4_addr field of the link_specifier_t in
  243. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  244. * code on 'inp' on failure.
  245. */
  246. int link_specifier_set_un_ipv4_addr(link_specifier_t *inp, uint32_t val);
  247. /** Return the value of the un_ipv4_port field of the link_specifier_t
  248. * in 'inp'
  249. */
  250. uint16_t link_specifier_get_un_ipv4_port(link_specifier_t *inp);
  251. /** Set the value of the un_ipv4_port field of the link_specifier_t in
  252. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  253. * code on 'inp' on failure.
  254. */
  255. int link_specifier_set_un_ipv4_port(link_specifier_t *inp, uint16_t val);
  256. /** Return the (constant) length of the array holding the un_ipv6_addr
  257. * field of the link_specifier_t in 'inp'.
  258. */
  259. size_t link_specifier_getlen_un_ipv6_addr(const link_specifier_t *inp);
  260. /** Return the element at position 'idx' of the fixed array field
  261. * un_ipv6_addr of the link_specifier_t in 'inp'.
  262. */
  263. uint8_t link_specifier_get_un_ipv6_addr(link_specifier_t *inp, size_t idx);
  264. /** As link_specifier_get_un_ipv6_addr, but take and return a const
  265. * pointer
  266. */
  267. uint8_t link_specifier_getconst_un_ipv6_addr(const link_specifier_t *inp, size_t idx);
  268. /** Change the element at position 'idx' of the fixed array field
  269. * un_ipv6_addr of the link_specifier_t in 'inp', so that it will hold
  270. * the value 'elt'.
  271. */
  272. int link_specifier_set_un_ipv6_addr(link_specifier_t *inp, size_t idx, uint8_t elt);
  273. /** Return a pointer to the 16-element array field un_ipv6_addr of
  274. * 'inp'.
  275. */
  276. uint8_t * link_specifier_getarray_un_ipv6_addr(link_specifier_t *inp);
  277. /** As link_specifier_get_un_ipv6_addr, but take and return a const
  278. * pointer
  279. */
  280. const uint8_t * link_specifier_getconstarray_un_ipv6_addr(const link_specifier_t *inp);
  281. /** Return the value of the un_ipv6_port field of the link_specifier_t
  282. * in 'inp'
  283. */
  284. uint16_t link_specifier_get_un_ipv6_port(link_specifier_t *inp);
  285. /** Set the value of the un_ipv6_port field of the link_specifier_t in
  286. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  287. * code on 'inp' on failure.
  288. */
  289. int link_specifier_set_un_ipv6_port(link_specifier_t *inp, uint16_t val);
  290. /** Return the (constant) length of the array holding the un_legacy_id
  291. * field of the link_specifier_t in 'inp'.
  292. */
  293. size_t link_specifier_getlen_un_legacy_id(const link_specifier_t *inp);
  294. /** Return the element at position 'idx' of the fixed array field
  295. * un_legacy_id of the link_specifier_t in 'inp'.
  296. */
  297. uint8_t link_specifier_get_un_legacy_id(link_specifier_t *inp, size_t idx);
  298. /** As link_specifier_get_un_legacy_id, but take and return a const
  299. * pointer
  300. */
  301. uint8_t link_specifier_getconst_un_legacy_id(const link_specifier_t *inp, size_t idx);
  302. /** Change the element at position 'idx' of the fixed array field
  303. * un_legacy_id of the link_specifier_t in 'inp', so that it will hold
  304. * the value 'elt'.
  305. */
  306. int link_specifier_set_un_legacy_id(link_specifier_t *inp, size_t idx, uint8_t elt);
  307. /** Return a pointer to the 20-element array field un_legacy_id of
  308. * 'inp'.
  309. */
  310. uint8_t * link_specifier_getarray_un_legacy_id(link_specifier_t *inp);
  311. /** As link_specifier_get_un_legacy_id, but take and return a const
  312. * pointer
  313. */
  314. const uint8_t * link_specifier_getconstarray_un_legacy_id(const link_specifier_t *inp);
  315. /** Return the (constant) length of the array holding the
  316. * un_ed25519_id field of the link_specifier_t in 'inp'.
  317. */
  318. size_t link_specifier_getlen_un_ed25519_id(const link_specifier_t *inp);
  319. /** Return the element at position 'idx' of the fixed array field
  320. * un_ed25519_id of the link_specifier_t in 'inp'.
  321. */
  322. uint8_t link_specifier_get_un_ed25519_id(link_specifier_t *inp, size_t idx);
  323. /** As link_specifier_get_un_ed25519_id, but take and return a const
  324. * pointer
  325. */
  326. uint8_t link_specifier_getconst_un_ed25519_id(const link_specifier_t *inp, size_t idx);
  327. /** Change the element at position 'idx' of the fixed array field
  328. * un_ed25519_id of the link_specifier_t in 'inp', so that it will
  329. * hold the value 'elt'.
  330. */
  331. int link_specifier_set_un_ed25519_id(link_specifier_t *inp, size_t idx, uint8_t elt);
  332. /** Return a pointer to the 32-element array field un_ed25519_id of
  333. * 'inp'.
  334. */
  335. uint8_t * link_specifier_getarray_un_ed25519_id(link_specifier_t *inp);
  336. /** As link_specifier_get_un_ed25519_id, but take and return a const
  337. * pointer
  338. */
  339. const uint8_t * link_specifier_getconstarray_un_ed25519_id(const link_specifier_t *inp);
  340. /** Return the length of the dynamic array holding the un_unrecognized
  341. * field of the link_specifier_t in 'inp'.
  342. */
  343. size_t link_specifier_getlen_un_unrecognized(const link_specifier_t *inp);
  344. /** Return the element at position 'idx' of the dynamic array field
  345. * un_unrecognized of the link_specifier_t in 'inp'.
  346. */
  347. uint8_t link_specifier_get_un_unrecognized(link_specifier_t *inp, size_t idx);
  348. /** As link_specifier_get_un_unrecognized, but take and return a const
  349. * pointer
  350. */
  351. uint8_t link_specifier_getconst_un_unrecognized(const link_specifier_t *inp, size_t idx);
  352. /** Change the element at position 'idx' of the dynamic array field
  353. * un_unrecognized of the link_specifier_t in 'inp', so that it will
  354. * hold the value 'elt'.
  355. */
  356. int link_specifier_set_un_unrecognized(link_specifier_t *inp, size_t idx, uint8_t elt);
  357. /** Append a new element 'elt' to the dynamic array field
  358. * un_unrecognized of the link_specifier_t in 'inp'.
  359. */
  360. int link_specifier_add_un_unrecognized(link_specifier_t *inp, uint8_t elt);
  361. /** Return a pointer to the variable-length array field
  362. * un_unrecognized of 'inp'.
  363. */
  364. uint8_t * link_specifier_getarray_un_unrecognized(link_specifier_t *inp);
  365. /** As link_specifier_get_un_unrecognized, but take and return a const
  366. * pointer
  367. */
  368. const uint8_t * link_specifier_getconstarray_un_unrecognized(const link_specifier_t *inp);
  369. /** Change the length of the variable-length array field
  370. * un_unrecognized of 'inp' to 'newlen'.Fill extra elements with 0.
  371. * Return 0 on success; return -1 and set the error code on 'inp' on
  372. * failure.
  373. */
  374. int link_specifier_setlen_un_unrecognized(link_specifier_t *inp, size_t newlen);
  375. /** Return a newly allocated ed25519_cert with all elements set to
  376. * zero.
  377. */
  378. ed25519_cert_t *ed25519_cert_new(void);
  379. /** Release all storage held by the ed25519_cert in 'victim'. (Do
  380. * nothing if 'victim' is NULL.)
  381. */
  382. void ed25519_cert_free(ed25519_cert_t *victim);
  383. /** Try to parse a ed25519_cert from the buffer in 'input', using up
  384. * to 'len_in' bytes from the input buffer. On success, return the
  385. * number of bytes consumed and set *output to the newly allocated
  386. * ed25519_cert_t. On failure, return -2 if the input appears
  387. * truncated, and -1 if the input is otherwise invalid.
  388. */
  389. ssize_t ed25519_cert_parse(ed25519_cert_t **output, const uint8_t *input, const size_t len_in);
  390. /** Return the number of bytes we expect to need to encode the
  391. * ed25519_cert in 'obj'. On failure, return a negative value. Note
  392. * that this value may be an overestimate, and can even be an
  393. * underestimate for certain unencodeable objects.
  394. */
  395. ssize_t ed25519_cert_encoded_len(const ed25519_cert_t *obj);
  396. /** Try to encode the ed25519_cert from 'input' into the buffer at
  397. * 'output', using up to 'avail' bytes of the output buffer. On
  398. * success, return the number of bytes used. On failure, return -2 if
  399. * the buffer was not long enough, and -1 if the input was invalid.
  400. */
  401. ssize_t ed25519_cert_encode(uint8_t *output, size_t avail, const ed25519_cert_t *input);
  402. /** Check whether the internal state of the ed25519_cert in 'obj' is
  403. * consistent. Return NULL if it is, and a short message if it is not.
  404. */
  405. const char *ed25519_cert_check(const ed25519_cert_t *obj);
  406. /** Clear any errors that were set on the object 'obj' by its setter
  407. * functions. Return true iff errors were cleared.
  408. */
  409. int ed25519_cert_clear_errors(ed25519_cert_t *obj);
  410. /** Return the value of the version field of the ed25519_cert_t in
  411. * 'inp'
  412. */
  413. uint8_t ed25519_cert_get_version(ed25519_cert_t *inp);
  414. /** Set the value of the version field of the ed25519_cert_t in 'inp'
  415. * to 'val'. Return 0 on success; return -1 and set the error code on
  416. * 'inp' on failure.
  417. */
  418. int ed25519_cert_set_version(ed25519_cert_t *inp, uint8_t val);
  419. /** Return the value of the cert_type field of the ed25519_cert_t in
  420. * 'inp'
  421. */
  422. uint8_t ed25519_cert_get_cert_type(ed25519_cert_t *inp);
  423. /** Set the value of the cert_type field of the ed25519_cert_t in
  424. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  425. * code on 'inp' on failure.
  426. */
  427. int ed25519_cert_set_cert_type(ed25519_cert_t *inp, uint8_t val);
  428. /** Return the value of the exp_field field of the ed25519_cert_t in
  429. * 'inp'
  430. */
  431. uint32_t ed25519_cert_get_exp_field(ed25519_cert_t *inp);
  432. /** Set the value of the exp_field field of the ed25519_cert_t in
  433. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  434. * code on 'inp' on failure.
  435. */
  436. int ed25519_cert_set_exp_field(ed25519_cert_t *inp, uint32_t val);
  437. /** Return the value of the cert_key_type field of the ed25519_cert_t
  438. * in 'inp'
  439. */
  440. uint8_t ed25519_cert_get_cert_key_type(ed25519_cert_t *inp);
  441. /** Set the value of the cert_key_type field of the ed25519_cert_t in
  442. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  443. * code on 'inp' on failure.
  444. */
  445. int ed25519_cert_set_cert_key_type(ed25519_cert_t *inp, uint8_t val);
  446. /** Return the (constant) length of the array holding the
  447. * certified_key field of the ed25519_cert_t in 'inp'.
  448. */
  449. size_t ed25519_cert_getlen_certified_key(const ed25519_cert_t *inp);
  450. /** Return the element at position 'idx' of the fixed array field
  451. * certified_key of the ed25519_cert_t in 'inp'.
  452. */
  453. uint8_t ed25519_cert_get_certified_key(ed25519_cert_t *inp, size_t idx);
  454. /** As ed25519_cert_get_certified_key, but take and return a const
  455. * pointer
  456. */
  457. uint8_t ed25519_cert_getconst_certified_key(const ed25519_cert_t *inp, size_t idx);
  458. /** Change the element at position 'idx' of the fixed array field
  459. * certified_key of the ed25519_cert_t in 'inp', so that it will hold
  460. * the value 'elt'.
  461. */
  462. int ed25519_cert_set_certified_key(ed25519_cert_t *inp, size_t idx, uint8_t elt);
  463. /** Return a pointer to the 32-element array field certified_key of
  464. * 'inp'.
  465. */
  466. uint8_t * ed25519_cert_getarray_certified_key(ed25519_cert_t *inp);
  467. /** As ed25519_cert_get_certified_key, but take and return a const
  468. * pointer
  469. */
  470. const uint8_t * ed25519_cert_getconstarray_certified_key(const ed25519_cert_t *inp);
  471. /** Return the value of the n_extensions field of the ed25519_cert_t
  472. * in 'inp'
  473. */
  474. uint8_t ed25519_cert_get_n_extensions(ed25519_cert_t *inp);
  475. /** Set the value of the n_extensions field of the ed25519_cert_t in
  476. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  477. * code on 'inp' on failure.
  478. */
  479. int ed25519_cert_set_n_extensions(ed25519_cert_t *inp, uint8_t val);
  480. /** Return the length of the dynamic array holding the ext field of
  481. * the ed25519_cert_t in 'inp'.
  482. */
  483. size_t ed25519_cert_getlen_ext(const ed25519_cert_t *inp);
  484. /** Return the element at position 'idx' of the dynamic array field
  485. * ext of the ed25519_cert_t in 'inp'.
  486. */
  487. struct ed25519_cert_extension_st * ed25519_cert_get_ext(ed25519_cert_t *inp, size_t idx);
  488. /** As ed25519_cert_get_ext, but take and return a const pointer
  489. */
  490. const struct ed25519_cert_extension_st * ed25519_cert_getconst_ext(const ed25519_cert_t *inp, size_t idx);
  491. /** Change the element at position 'idx' of the dynamic array field
  492. * ext of the ed25519_cert_t in 'inp', so that it will hold the value
  493. * 'elt'. Free the previous value, if any.
  494. */
  495. int ed25519_cert_set_ext(ed25519_cert_t *inp, size_t idx, struct ed25519_cert_extension_st * elt);
  496. /** As ed25519_cert_set_ext, but does not free the previous value.
  497. */
  498. int ed25519_cert_set0_ext(ed25519_cert_t *inp, size_t idx, struct ed25519_cert_extension_st * elt);
  499. /** Append a new element 'elt' to the dynamic array field ext of the
  500. * ed25519_cert_t in 'inp'.
  501. */
  502. int ed25519_cert_add_ext(ed25519_cert_t *inp, struct ed25519_cert_extension_st * elt);
  503. /** Return a pointer to the variable-length array field ext of 'inp'.
  504. */
  505. struct ed25519_cert_extension_st * * ed25519_cert_getarray_ext(ed25519_cert_t *inp);
  506. /** As ed25519_cert_get_ext, but take and return a const pointer
  507. */
  508. const struct ed25519_cert_extension_st * const * ed25519_cert_getconstarray_ext(const ed25519_cert_t *inp);
  509. /** Change the length of the variable-length array field ext of 'inp'
  510. * to 'newlen'.Fill extra elements with NULL; free removed elements.
  511. * Return 0 on success; return -1 and set the error code on 'inp' on
  512. * failure.
  513. */
  514. int ed25519_cert_setlen_ext(ed25519_cert_t *inp, size_t newlen);
  515. /** Return the (constant) length of the array holding the signature
  516. * field of the ed25519_cert_t in 'inp'.
  517. */
  518. size_t ed25519_cert_getlen_signature(const ed25519_cert_t *inp);
  519. /** Return the element at position 'idx' of the fixed array field
  520. * signature of the ed25519_cert_t in 'inp'.
  521. */
  522. uint8_t ed25519_cert_get_signature(ed25519_cert_t *inp, size_t idx);
  523. /** As ed25519_cert_get_signature, but take and return a const pointer
  524. */
  525. uint8_t ed25519_cert_getconst_signature(const ed25519_cert_t *inp, size_t idx);
  526. /** Change the element at position 'idx' of the fixed array field
  527. * signature of the ed25519_cert_t in 'inp', so that it will hold the
  528. * value 'elt'.
  529. */
  530. int ed25519_cert_set_signature(ed25519_cert_t *inp, size_t idx, uint8_t elt);
  531. /** Return a pointer to the 64-element array field signature of 'inp'.
  532. */
  533. uint8_t * ed25519_cert_getarray_signature(ed25519_cert_t *inp);
  534. /** As ed25519_cert_get_signature, but take and return a const pointer
  535. */
  536. const uint8_t * ed25519_cert_getconstarray_signature(const ed25519_cert_t *inp);
  537. /** Return a newly allocated link_specifier_list with all elements set
  538. * to zero.
  539. */
  540. link_specifier_list_t *link_specifier_list_new(void);
  541. /** Release all storage held by the link_specifier_list in 'victim'.
  542. * (Do nothing if 'victim' is NULL.)
  543. */
  544. void link_specifier_list_free(link_specifier_list_t *victim);
  545. /** Try to parse a link_specifier_list from the buffer in 'input',
  546. * using up to 'len_in' bytes from the input buffer. On success,
  547. * return the number of bytes consumed and set *output to the newly
  548. * allocated link_specifier_list_t. On failure, return -2 if the input
  549. * appears truncated, and -1 if the input is otherwise invalid.
  550. */
  551. ssize_t link_specifier_list_parse(link_specifier_list_t **output, const uint8_t *input, const size_t len_in);
  552. /** Return the number of bytes we expect to need to encode the
  553. * link_specifier_list in 'obj'. On failure, return a negative value.
  554. * Note that this value may be an overestimate, and can even be an
  555. * underestimate for certain unencodeable objects.
  556. */
  557. ssize_t link_specifier_list_encoded_len(const link_specifier_list_t *obj);
  558. /** Try to encode the link_specifier_list from 'input' into the buffer
  559. * at 'output', using up to 'avail' bytes of the output buffer. On
  560. * success, return the number of bytes used. On failure, return -2 if
  561. * the buffer was not long enough, and -1 if the input was invalid.
  562. */
  563. ssize_t link_specifier_list_encode(uint8_t *output, size_t avail, const link_specifier_list_t *input);
  564. /** Check whether the internal state of the link_specifier_list in
  565. * 'obj' is consistent. Return NULL if it is, and a short message if
  566. * it is not.
  567. */
  568. const char *link_specifier_list_check(const link_specifier_list_t *obj);
  569. /** Clear any errors that were set on the object 'obj' by its setter
  570. * functions. Return true iff errors were cleared.
  571. */
  572. int link_specifier_list_clear_errors(link_specifier_list_t *obj);
  573. /** Return the value of the n_spec field of the link_specifier_list_t
  574. * in 'inp'
  575. */
  576. uint8_t link_specifier_list_get_n_spec(link_specifier_list_t *inp);
  577. /** Set the value of the n_spec field of the link_specifier_list_t in
  578. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  579. * code on 'inp' on failure.
  580. */
  581. int link_specifier_list_set_n_spec(link_specifier_list_t *inp, uint8_t val);
  582. /** Return the length of the dynamic array holding the spec field of
  583. * the link_specifier_list_t in 'inp'.
  584. */
  585. size_t link_specifier_list_getlen_spec(const link_specifier_list_t *inp);
  586. /** Return the element at position 'idx' of the dynamic array field
  587. * spec of the link_specifier_list_t in 'inp'.
  588. */
  589. struct link_specifier_st * link_specifier_list_get_spec(link_specifier_list_t *inp, size_t idx);
  590. /** As link_specifier_list_get_spec, but take and return a const
  591. * pointer
  592. */
  593. const struct link_specifier_st * link_specifier_list_getconst_spec(const link_specifier_list_t *inp, size_t idx);
  594. /** Change the element at position 'idx' of the dynamic array field
  595. * spec of the link_specifier_list_t in 'inp', so that it will hold
  596. * the value 'elt'. Free the previous value, if any.
  597. */
  598. int link_specifier_list_set_spec(link_specifier_list_t *inp, size_t idx, struct link_specifier_st * elt);
  599. /** As link_specifier_list_set_spec, but does not free the previous
  600. * value.
  601. */
  602. int link_specifier_list_set0_spec(link_specifier_list_t *inp, size_t idx, struct link_specifier_st * elt);
  603. /** Append a new element 'elt' to the dynamic array field spec of the
  604. * link_specifier_list_t in 'inp'.
  605. */
  606. int link_specifier_list_add_spec(link_specifier_list_t *inp, struct link_specifier_st * elt);
  607. /** Return a pointer to the variable-length array field spec of 'inp'.
  608. */
  609. struct link_specifier_st * * link_specifier_list_getarray_spec(link_specifier_list_t *inp);
  610. /** As link_specifier_list_get_spec, but take and return a const
  611. * pointer
  612. */
  613. const struct link_specifier_st * const * link_specifier_list_getconstarray_spec(const link_specifier_list_t *inp);
  614. /** Change the length of the variable-length array field spec of 'inp'
  615. * to 'newlen'.Fill extra elements with NULL; free removed elements.
  616. * Return 0 on success; return -1 and set the error code on 'inp' on
  617. * failure.
  618. */
  619. int link_specifier_list_setlen_spec(link_specifier_list_t *inp, size_t newlen);
  620. #endif