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