diff options
Diffstat (limited to 'src/reclaim/reclaim_attribute.c')
-rw-r--r-- | src/reclaim/reclaim_attribute.c | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/src/reclaim/reclaim_attribute.c b/src/reclaim/reclaim_attribute.c index 05bdc1ac6..2217987ac 100644 --- a/src/reclaim/reclaim_attribute.c +++ b/src/reclaim/reclaim_attribute.c | |||
@@ -222,7 +222,7 @@ GNUNET_RECLAIM_attribute_value_to_string (uint32_t type, | |||
222 | * Create a new attribute. | 222 | * Create a new attribute. |
223 | * | 223 | * |
224 | * @param attr_name the attribute name | 224 | * @param attr_name the attribute name |
225 | * @param attestation attestation ID of the attribute (maybe NULL) | 225 | * @param credential credential ID of the attribute (maybe NULL) |
226 | * @param type the attribute type | 226 | * @param type the attribute type |
227 | * @param data the attribute value | 227 | * @param data the attribute value |
228 | * @param data_size the attribute value size | 228 | * @param data_size the attribute value size |
@@ -231,7 +231,7 @@ GNUNET_RECLAIM_attribute_value_to_string (uint32_t type, | |||
231 | struct GNUNET_RECLAIM_Attribute * | 231 | struct GNUNET_RECLAIM_Attribute * |
232 | GNUNET_RECLAIM_attribute_new (const char *attr_name, | 232 | GNUNET_RECLAIM_attribute_new (const char *attr_name, |
233 | const struct | 233 | const struct |
234 | GNUNET_RECLAIM_Identifier *attestation, | 234 | GNUNET_RECLAIM_Identifier *credential, |
235 | uint32_t type, | 235 | uint32_t type, |
236 | const void *data, | 236 | const void *data, |
237 | size_t data_size) | 237 | size_t data_size) |
@@ -244,8 +244,8 @@ GNUNET_RECLAIM_attribute_new (const char *attr_name, | |||
244 | 244 | ||
245 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) | 245 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) |
246 | + strlen (attr_name_tmp) + 1 + data_size); | 246 | + strlen (attr_name_tmp) + 1 + data_size); |
247 | if (NULL != attestation) | 247 | if (NULL != credential) |
248 | attr->attestation = *attestation; | 248 | attr->credential = *credential; |
249 | attr->type = type; | 249 | attr->type = type; |
250 | attr->data_size = data_size; | 250 | attr->data_size = data_size; |
251 | attr->flag = 0; | 251 | attr->flag = 0; |
@@ -272,7 +272,7 @@ void | |||
272 | GNUNET_RECLAIM_attribute_list_add ( | 272 | GNUNET_RECLAIM_attribute_list_add ( |
273 | struct GNUNET_RECLAIM_AttributeList *al, | 273 | struct GNUNET_RECLAIM_AttributeList *al, |
274 | const char *attr_name, | 274 | const char *attr_name, |
275 | const struct GNUNET_RECLAIM_Identifier *attestation, | 275 | const struct GNUNET_RECLAIM_Identifier *credential, |
276 | uint32_t type, | 276 | uint32_t type, |
277 | const void *data, | 277 | const void *data, |
278 | size_t data_size) | 278 | size_t data_size) |
@@ -281,7 +281,7 @@ GNUNET_RECLAIM_attribute_list_add ( | |||
281 | 281 | ||
282 | ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); | 282 | ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); |
283 | ale->attribute = | 283 | ale->attribute = |
284 | GNUNET_RECLAIM_attribute_new (attr_name, attestation, | 284 | GNUNET_RECLAIM_attribute_new (attr_name, credential, |
285 | type, data, data_size); | 285 | type, data, data_size); |
286 | GNUNET_CONTAINER_DLL_insert (al->list_head, | 286 | GNUNET_CONTAINER_DLL_insert (al->list_head, |
287 | al->list_tail, | 287 | al->list_tail, |
@@ -306,7 +306,6 @@ GNUNET_RECLAIM_attribute_list_serialize_get_size ( | |||
306 | { | 306 | { |
307 | GNUNET_assert (NULL != ale->attribute); | 307 | GNUNET_assert (NULL != ale->attribute); |
308 | len += GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute); | 308 | len += GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute); |
309 | len += sizeof(struct GNUNET_RECLAIM_AttributeListEntry); | ||
310 | } | 309 | } |
311 | return len; | 310 | return len; |
312 | } | 311 | } |
@@ -355,27 +354,28 @@ GNUNET_RECLAIM_attribute_list_deserialize (const char *data, size_t data_size) | |||
355 | struct GNUNET_RECLAIM_AttributeListEntry *ale; | 354 | struct GNUNET_RECLAIM_AttributeListEntry *ale; |
356 | size_t attr_len; | 355 | size_t attr_len; |
357 | const char *read_ptr; | 356 | const char *read_ptr; |
357 | size_t left = data_size; | ||
358 | 358 | ||
359 | al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); | 359 | al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
360 | if (data_size < sizeof(struct Attribute) + sizeof(struct | 360 | if (data_size < sizeof(struct Attribute)) |
361 | GNUNET_RECLAIM_AttributeListEntry)) | ||
362 | return al; | 361 | return al; |
363 | read_ptr = data; | 362 | read_ptr = data; |
364 | while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) | 363 | while (left >= sizeof(struct Attribute)) |
365 | { | 364 | { |
366 | ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); | 365 | ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); |
367 | ale->attribute = | 366 | attr_len = |
368 | GNUNET_RECLAIM_attribute_deserialize (read_ptr, | 367 | GNUNET_RECLAIM_attribute_deserialize (read_ptr, |
369 | data_size - (read_ptr - data)); | 368 | left, |
370 | if (NULL == ale->attribute) | 369 | &ale->attribute); |
370 | if (-1 == attr_len) | ||
371 | { | 371 | { |
372 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 372 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
373 | "Failed to deserialize malformed attribute.\n"); | 373 | "Failed to deserialize malformed attribute.\n"); |
374 | GNUNET_free (ale); | 374 | GNUNET_free (ale); |
375 | return al; | 375 | return al; |
376 | } | 376 | } |
377 | left -= attr_len; | ||
377 | GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale); | 378 | GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale); |
378 | attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute); | ||
379 | read_ptr += attr_len; | 379 | read_ptr += attr_len; |
380 | } | 380 | } |
381 | return al; | 381 | return al; |
@@ -403,7 +403,7 @@ GNUNET_RECLAIM_attribute_list_dup ( | |||
403 | { | 403 | { |
404 | result_ale->attribute = | 404 | result_ale->attribute = |
405 | GNUNET_RECLAIM_attribute_new (ale->attribute->name, | 405 | GNUNET_RECLAIM_attribute_new (ale->attribute->name, |
406 | &ale->attribute->attestation, | 406 | &ale->attribute->credential, |
407 | ale->attribute->type, | 407 | ale->attribute->type, |
408 | ale->attribute->data, | 408 | ale->attribute->data, |
409 | ale->attribute->data_size); | 409 | ale->attribute->data_size); |
@@ -478,7 +478,7 @@ GNUNET_RECLAIM_attribute_serialize ( | |||
478 | attr_ser->attribute_type = htons (attr->type); | 478 | attr_ser->attribute_type = htons (attr->type); |
479 | attr_ser->attribute_flag = htonl (attr->flag); | 479 | attr_ser->attribute_flag = htonl (attr->flag); |
480 | attr_ser->attribute_id = attr->id; | 480 | attr_ser->attribute_id = attr->id; |
481 | attr_ser->attestation_id = attr->attestation; | 481 | attr_ser->credential_id = attr->credential; |
482 | name_len = strlen (attr->name); | 482 | name_len = strlen (attr->name); |
483 | attr_ser->name_len = htons (name_len); | 483 | attr_ser->name_len = htons (name_len); |
484 | write_ptr = (char *) &attr_ser[1]; | 484 | write_ptr = (char *) &attr_ser[1]; |
@@ -503,17 +503,18 @@ GNUNET_RECLAIM_attribute_serialize ( | |||
503 | * | 503 | * |
504 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | 504 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller |
505 | */ | 505 | */ |
506 | struct GNUNET_RECLAIM_Attribute * | 506 | ssize_t |
507 | GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size) | 507 | GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size, |
508 | struct GNUNET_RECLAIM_Attribute **attr) | ||
508 | { | 509 | { |
509 | struct GNUNET_RECLAIM_Attribute *attr; | ||
510 | struct Attribute *attr_ser; | 510 | struct Attribute *attr_ser; |
511 | struct GNUNET_RECLAIM_Attribute *attribute; | ||
511 | size_t data_len; | 512 | size_t data_len; |
512 | size_t name_len; | 513 | size_t name_len; |
513 | char *write_ptr; | 514 | char *write_ptr; |
514 | 515 | ||
515 | if (data_size < sizeof(struct Attribute)) | 516 | if (data_size < sizeof(struct Attribute)) |
516 | return NULL; | 517 | return -1; |
517 | 518 | ||
518 | attr_ser = (struct Attribute *) data; | 519 | attr_ser = (struct Attribute *) data; |
519 | data_len = ntohs (attr_ser->data_size); | 520 | data_len = ntohs (attr_ser->data_size); |
@@ -522,25 +523,27 @@ GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size) | |||
522 | { | 523 | { |
523 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 524 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
524 | "Buffer too small to deserialize\n"); | 525 | "Buffer too small to deserialize\n"); |
525 | return NULL; | 526 | return -1; |
526 | } | 527 | } |
527 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) | 528 | attribute = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) |
528 | + data_len + name_len + 1); | 529 | + data_len + name_len + 1); |
529 | attr->type = ntohs (attr_ser->attribute_type); | 530 | attribute->type = ntohs (attr_ser->attribute_type); |
530 | attr->flag = ntohl (attr_ser->attribute_flag); | 531 | attribute->flag = ntohl (attr_ser->attribute_flag); |
531 | attr->id = attr_ser->attribute_id; | 532 | attribute->id = attr_ser->attribute_id; |
532 | attr->attestation = attr_ser->attestation_id; | 533 | attribute->credential = attr_ser->credential_id; |
533 | attr->data_size = data_len; | 534 | attribute->data_size = data_len; |
534 | 535 | ||
535 | write_ptr = (char *) &attr[1]; | 536 | write_ptr = (char *) &attribute[1]; |
536 | GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); | 537 | GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); |
537 | write_ptr[name_len] = '\0'; | 538 | write_ptr[name_len] = '\0'; |
538 | attr->name = write_ptr; | 539 | attribute->name = write_ptr; |
539 | 540 | ||
540 | write_ptr += name_len + 1; | 541 | write_ptr += name_len + 1; |
541 | GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, attr->data_size); | 542 | GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, |
542 | attr->data = write_ptr; | 543 | attribute->data_size); |
543 | return attr; | 544 | *attr = attribute; |
545 | attribute->data = write_ptr; | ||
546 | return sizeof(struct Attribute) + data_len + name_len; | ||
544 | } | 547 | } |
545 | 548 | ||
546 | 549 | ||