aboutsummaryrefslogtreecommitdiff
path: root/src/abd/abd_serialization.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/abd/abd_serialization.c')
-rw-r--r--src/abd/abd_serialization.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/abd/abd_serialization.c b/src/abd/abd_serialization.c
index d2bc15166..90a89886b 100644
--- a/src/abd/abd_serialization.c
+++ b/src/abd/abd_serialization.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -21,7 +21,7 @@
21 21
22/** 22/**
23 * @file abd/abd_serialization.c 23 * @file abd/abd_serialization.c
24 * @brief API to serialize and deserialize delegation chains 24 * @brief API to serialize and deserialize delegation chains
25 * and abds 25 * and abds
26 * @author Martin Schanzenbach 26 * @author Martin Schanzenbach
27 */ 27 */
@@ -58,6 +58,7 @@ GNUNET_ABD_delegation_set_get_size (
58 return ret; 58 return ret;
59} 59}
60 60
61
61/** 62/**
62 * Serizalize the given delegation chain entries and abd 63 * Serizalize the given delegation chain entries and abd
63 * 64 *
@@ -158,12 +159,15 @@ GNUNET_ABD_delegates_get_size (
158 159
159 for (i = 0; i < c_count; i++) 160 for (i = 0; i < c_count; i++)
160 { 161 {
161 GNUNET_assert ((ret + cd[i].issuer_attribute_len + cd[i].subject_attribute_len) >= ret); 162 GNUNET_assert ((ret + cd[i].issuer_attribute_len
163 + cd[i].subject_attribute_len) >= ret);
162 // subject_attribute_len should be 0 164 // subject_attribute_len should be 0
163 ret += cd[i].issuer_attribute_len + cd[i].subject_attribute_len; 165 ret += cd[i].issuer_attribute_len + cd[i].subject_attribute_len;
164 } 166 }
165 return ret; 167 return ret;
166} 168}
169
170
167/** 171/**
168 * Serizalize the given abds 172 * Serizalize the given abds
169 * 173 *
@@ -187,15 +191,15 @@ GNUNET_ABD_delegates_serialize (
187 off = 0; 191 off = 0;
188 for (i = 0; i < c_count; i++) 192 for (i = 0; i < c_count; i++)
189 { 193 {
190 //c_rec.subject_attribute_len = htonl ((uint32_t) cd[i].subject_attribute_len); 194 // c_rec.subject_attribute_len = htonl ((uint32_t) cd[i].subject_attribute_len);
191 c_rec.issuer_attribute_len = htonl ((uint32_t) cd[i].issuer_attribute_len); 195 c_rec.issuer_attribute_len = htonl ((uint32_t) cd[i].issuer_attribute_len);
192 c_rec.issuer_key = cd[i].issuer_key; 196 c_rec.issuer_key = cd[i].issuer_key;
193 c_rec.subject_key = cd[i].subject_key; 197 c_rec.subject_key = cd[i].subject_key;
194 c_rec.signature = cd[i].signature; 198 c_rec.signature = cd[i].signature;
195 c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); 199 c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE);
196 c_rec.purpose.size = 200 c_rec.purpose.size =
197 htonl ((sizeof (struct DelegateEntry) + cd[i].issuer_attribute_len) - 201 htonl ((sizeof (struct DelegateEntry) + cd[i].issuer_attribute_len)
198 sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); 202 - sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
199 c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us); 203 c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us);
200 if (off + sizeof (c_rec) > dest_size) 204 if (off + sizeof (c_rec) > dest_size)
201 return -1; 205 return -1;
@@ -224,9 +228,9 @@ GNUNET_ABD_delegates_serialize (
224 */ 228 */
225int 229int
226GNUNET_ABD_delegates_deserialize (size_t len, 230GNUNET_ABD_delegates_deserialize (size_t len,
227 const char *src, 231 const char *src,
228 unsigned int c_count, 232 unsigned int c_count,
229 struct GNUNET_ABD_Delegate *cd) 233 struct GNUNET_ABD_Delegate *cd)
230{ 234{
231 struct DelegateEntry c_rec; 235 struct DelegateEntry c_rec;
232 unsigned int i; 236 unsigned int i;
@@ -285,6 +289,7 @@ GNUNET_ABD_delegation_chain_get_size (
285 return ret + GNUNET_ABD_delegates_get_size (c_count, cd); 289 return ret + GNUNET_ABD_delegates_get_size (c_count, cd);
286} 290}
287 291
292
288/** 293/**
289 * Serizalize the given delegation chain entries and abd 294 * Serizalize the given delegation chain entries and abd
290 * 295 *
@@ -336,9 +341,9 @@ GNUNET_ABD_delegation_chain_serialize (
336 off += dd[i].subject_attribute_len; 341 off += dd[i].subject_attribute_len;
337 } 342 }
338 return off + GNUNET_ABD_delegates_serialize (c_count, 343 return off + GNUNET_ABD_delegates_serialize (c_count,
339 cd, 344 cd,
340 dest_size - off, 345 dest_size - off,
341 &dest[off]); 346 &dest[off]);
342} 347}
343 348
344 349
@@ -387,14 +392,15 @@ GNUNET_ABD_delegation_chain_deserialize (
387 off += dd[i].subject_attribute_len; 392 off += dd[i].subject_attribute_len;
388 } 393 }
389 return GNUNET_ABD_delegates_deserialize (len - off, 394 return GNUNET_ABD_delegates_deserialize (len - off,
390 &src[off], 395 &src[off],
391 c_count, 396 c_count,
392 cd); 397 cd);
393} 398}
394 399
400
395int 401int
396GNUNET_ABD_delegate_serialize (struct GNUNET_ABD_Delegate *dele, 402GNUNET_ABD_delegate_serialize (struct GNUNET_ABD_Delegate *dele,
397 char **data) 403 char **data)
398{ 404{
399 size_t size; 405 size_t size;
400 struct DelegateEntry *cdata; 406 struct DelegateEntry *cdata;
@@ -455,6 +461,7 @@ GNUNET_ABD_delegate_serialize (struct GNUNET_ABD_Delegate *dele,
455 return size; 461 return size;
456} 462}
457 463
464
458struct GNUNET_ABD_Delegate * 465struct GNUNET_ABD_Delegate *
459GNUNET_ABD_delegate_deserialize (const char *data, size_t data_size) 466GNUNET_ABD_delegate_deserialize (const char *data, size_t data_size)
460{ 467{
@@ -505,4 +512,5 @@ GNUNET_ABD_delegate_deserialize (const char *data, size_t data_size)
505 return dele; 512 return dele;
506} 513}
507 514
515
508/* end of abd_serialization.c */ 516/* end of abd_serialization.c */