abd_serialization.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009-2013, 2016 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file abd/abd_serialization.h
  18. * @brief API to serialize and deserialize delegation chains
  19. * and abds
  20. * @author Martin Schanzenbach
  21. */
  22. #ifndef ABD_SERIALIZATION_H
  23. #define ABD_SERIALIZATION_H
  24. #include "platform.h"
  25. #include "gnunet_util_lib.h"
  26. #include "gnunet_constants.h"
  27. #include "gnunet_abd_service.h"
  28. /**
  29. * Calculate how many bytes we will need to serialize
  30. * the given delegation record
  31. *
  32. * @param ds_count number of delegation chain entries
  33. * @param dsr array of #GNUNET_ABD_Delegation
  34. * @return the required size to serialize
  35. */
  36. size_t
  37. GNUNET_ABD_delegation_set_get_size (
  38. unsigned int ds_count,
  39. const struct GNUNET_ABD_DelegationSet *dsr);
  40. /**
  41. * Serizalize the given delegation record entries
  42. *
  43. * @param d_count number of delegation chain entries
  44. * @param dsr array of #GNUNET_ABD_Delegation
  45. * @param dest_size size of the destination
  46. * @param dest where to store the result
  47. * @return the size of the data, -1 on failure
  48. */
  49. ssize_t
  50. GNUNET_ABD_delegation_set_serialize (
  51. unsigned int d_count,
  52. const struct GNUNET_ABD_DelegationSet *dsr,
  53. size_t dest_size,
  54. char *dest);
  55. /**
  56. * Deserialize the given destination
  57. *
  58. * @param len size of the serialized delegation recird
  59. * @param src the serialized data
  60. * @param d_count the number of delegation chain entries
  61. * @param dsr where to put the delegation chain entries
  62. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  63. */
  64. int
  65. GNUNET_ABD_delegation_set_deserialize (
  66. size_t len,
  67. const char *src,
  68. unsigned int d_count,
  69. struct GNUNET_ABD_DelegationSet *dsr);
  70. /**
  71. * Calculate how many bytes we will need to serialize
  72. * the given delegation chain and abd
  73. *
  74. * @param d_count number of delegation chain entries
  75. * @param dd array of #GNUNET_ABD_Delegation
  76. * @param c_count number of abd entries
  77. * @param cd a #GNUNET_ABD_Delegate
  78. * @return the required size to serialize
  79. */
  80. size_t
  81. GNUNET_ABD_delegation_chain_get_size (
  82. unsigned int d_count,
  83. const struct GNUNET_ABD_Delegation *dd,
  84. unsigned int c_count,
  85. const struct GNUNET_ABD_Delegate *cd);
  86. /**
  87. * Serizalize the given delegation chain entries and abd
  88. *
  89. * @param d_count number of delegation chain entries
  90. * @param dd array of #GNUNET_ABD_Delegation
  91. * @param c_count number of abd entries
  92. * @param cd a #GNUNET_ABD_Delegate
  93. * @param dest_size size of the destination
  94. * @param dest where to store the result
  95. * @return the size of the data, -1 on failure
  96. */
  97. ssize_t
  98. GNUNET_ABD_delegation_chain_serialize (
  99. unsigned int d_count,
  100. const struct GNUNET_ABD_Delegation *dd,
  101. unsigned int c_count,
  102. const struct GNUNET_ABD_Delegate *cd,
  103. size_t dest_size,
  104. char *dest);
  105. /**
  106. * Deserialize the given destination
  107. *
  108. * @param len size of the serialized delegation chain and cred
  109. * @param src the serialized data
  110. * @param d_count the number of delegation chain entries
  111. * @param dd where to put the delegation chain entries
  112. * @param c_count number of abd entries
  113. * @param cd where to put the abd data
  114. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  115. */
  116. int
  117. GNUNET_ABD_delegation_chain_deserialize (
  118. size_t len,
  119. const char *src,
  120. unsigned int d_count,
  121. struct GNUNET_ABD_Delegation *dd,
  122. unsigned int c_count,
  123. struct GNUNET_ABD_Delegate *cd);
  124. size_t
  125. GNUNET_ABD_delegates_get_size (
  126. unsigned int c_count,
  127. const struct GNUNET_ABD_Delegate *cd);
  128. ssize_t
  129. GNUNET_ABD_delegates_serialize (
  130. unsigned int c_count,
  131. const struct GNUNET_ABD_Delegate *cd,
  132. size_t dest_size,
  133. char *dest);
  134. int
  135. GNUNET_ABD_delegates_deserialize (size_t len,
  136. const char *src,
  137. unsigned int c_count,
  138. struct GNUNET_ABD_Delegate *cd);
  139. int
  140. GNUNET_ABD_delegate_serialize (struct GNUNET_ABD_Delegate *cred,
  141. char **data);
  142. struct GNUNET_ABD_Delegate *
  143. GNUNET_ABD_delegate_deserialize (const char *data, size_t data_size);
  144. #endif
  145. /* end of abd_serialization.h */