diff options
Diffstat (limited to 'src/messenger/messenger_api_message.c')
-rw-r--r-- | src/messenger/messenger_api_message.c | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c index c7364d51c..05bf654fb 100644 --- a/src/messenger/messenger_api_message.c +++ b/src/messenger/messenger_api_message.c | |||
@@ -103,7 +103,8 @@ copy_message (const struct GNUNET_MESSENGER_Message *message) | |||
103 | } | 103 | } |
104 | 104 | ||
105 | static void | 105 | static void |
106 | destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body) | 106 | destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, |
107 | struct GNUNET_MESSENGER_MessageBody *body) | ||
107 | { | 108 | { |
108 | switch (kind) | 109 | switch (kind) |
109 | { | 110 | { |
@@ -150,7 +151,8 @@ is_message_session_bound (const struct GNUNET_MESSENGER_Message *message) | |||
150 | } | 151 | } |
151 | 152 | ||
152 | static void | 153 | static void |
153 | fold_short_message (const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened) | 154 | fold_short_message (const struct GNUNET_MESSENGER_Message *message, |
155 | struct GNUNET_MESSENGER_ShortMessage *shortened) | ||
154 | { | 156 | { |
155 | shortened->kind = message->header.kind; | 157 | shortened->kind = message->header.kind; |
156 | 158 | ||
@@ -158,7 +160,8 @@ fold_short_message (const struct GNUNET_MESSENGER_Message *message, struct GNUNE | |||
158 | } | 160 | } |
159 | 161 | ||
160 | static void | 162 | static void |
161 | unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message) | 163 | unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, |
164 | struct GNUNET_MESSENGER_Message *message) | ||
162 | { | 165 | { |
163 | destroy_message_body (message->header.kind, &(message->body)); | 166 | destroy_message_body (message->header.kind, &(message->body)); |
164 | 167 | ||
@@ -231,7 +234,8 @@ get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind) | |||
231 | } | 234 | } |
232 | 235 | ||
233 | static uint16_t | 236 | static uint16_t |
234 | get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body) | 237 | get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, |
238 | const struct GNUNET_MESSENGER_MessageBody *body) | ||
235 | { | 239 | { |
236 | uint16_t length = 0; | 240 | uint16_t length = 0; |
237 | 241 | ||
@@ -283,7 +287,8 @@ get_message_size (const struct GNUNET_MESSENGER_Message *message, | |||
283 | } | 287 | } |
284 | 288 | ||
285 | static uint16_t | 289 | static uint16_t |
286 | get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, int include_body) | 290 | get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, |
291 | int include_body) | ||
287 | { | 292 | { |
288 | const uint16_t minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t); | 293 | const uint16_t minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t); |
289 | 294 | ||
@@ -370,8 +375,11 @@ calc_padded_length (uint16_t length) | |||
370 | } while (0) | 375 | } while (0) |
371 | 376 | ||
372 | static void | 377 | static void |
373 | encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, | 378 | encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, |
374 | uint16_t length, char *buffer, uint16_t offset) | 379 | const struct GNUNET_MESSENGER_MessageBody *body, |
380 | uint16_t length, | ||
381 | char *buffer, | ||
382 | uint16_t offset) | ||
375 | { | 383 | { |
376 | uint32_t version; | 384 | uint32_t version; |
377 | switch (kind) | 385 | switch (kind) |
@@ -445,7 +453,9 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET | |||
445 | } | 453 | } |
446 | 454 | ||
447 | void | 455 | void |
448 | encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, | 456 | encode_message (const struct GNUNET_MESSENGER_Message *message, |
457 | uint16_t length, | ||
458 | char *buffer, | ||
449 | int include_signature) | 459 | int include_signature) |
450 | { | 460 | { |
451 | GNUNET_assert((message) && (buffer)); | 461 | GNUNET_assert((message) && (buffer)); |
@@ -466,7 +476,9 @@ encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, | |||
466 | } | 476 | } |
467 | 477 | ||
468 | static void | 478 | static void |
469 | encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer) | 479 | encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, |
480 | uint16_t length, | ||
481 | char *buffer) | ||
470 | { | 482 | { |
471 | struct GNUNET_HashCode hash; | 483 | struct GNUNET_HashCode hash; |
472 | uint16_t offset = sizeof(hash); | 484 | uint16_t offset = sizeof(hash); |
@@ -512,8 +524,11 @@ encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, uint1 | |||
512 | } while (0) | 524 | } while (0) |
513 | 525 | ||
514 | static uint16_t | 526 | static uint16_t |
515 | decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, | 527 | decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, |
516 | uint16_t length, const char *buffer, uint16_t offset) | 528 | struct GNUNET_MESSENGER_MessageBody *body, |
529 | uint16_t length, | ||
530 | const char *buffer, | ||
531 | uint16_t offset) | ||
517 | { | 532 | { |
518 | uint16_t padding = 0; | 533 | uint16_t padding = 0; |
519 | 534 | ||
@@ -593,8 +608,11 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESS | |||
593 | } | 608 | } |
594 | 609 | ||
595 | int | 610 | int |
596 | decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, | 611 | decode_message (struct GNUNET_MESSENGER_Message *message, |
597 | int include_signature, uint16_t *padding) | 612 | uint16_t length, |
613 | const char *buffer, | ||
614 | int include_signature, | ||
615 | uint16_t *padding) | ||
598 | { | 616 | { |
599 | GNUNET_assert((message) && (buffer) && (length >= get_message_kind_size(GNUNET_MESSENGER_KIND_UNKNOWN))); | 617 | GNUNET_assert((message) && (buffer) && (length >= get_message_kind_size(GNUNET_MESSENGER_KIND_UNKNOWN))); |
600 | 618 | ||
@@ -638,7 +656,9 @@ decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const | |||
638 | } | 656 | } |
639 | 657 | ||
640 | static int | 658 | static int |
641 | decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer) | 659 | decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, |
660 | uint16_t length, | ||
661 | const char *buffer) | ||
642 | { | 662 | { |
643 | struct GNUNET_HashCode expected, hash; | 663 | struct GNUNET_HashCode expected, hash; |
644 | uint16_t offset = sizeof(hash); | 664 | uint16_t offset = sizeof(hash); |
@@ -675,7 +695,9 @@ decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, uint16_t le | |||
675 | } | 695 | } |
676 | 696 | ||
677 | void | 697 | void |
678 | hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, | 698 | hash_message (const struct GNUNET_MESSENGER_Message *message, |
699 | uint16_t length, | ||
700 | const char *buffer, | ||
679 | struct GNUNET_HashCode *hash) | 701 | struct GNUNET_HashCode *hash) |
680 | { | 702 | { |
681 | GNUNET_assert((message) && (buffer) && (hash)); | 703 | GNUNET_assert((message) && (buffer) && (hash)); |
@@ -688,8 +710,11 @@ hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, c | |||
688 | } | 710 | } |
689 | 711 | ||
690 | void | 712 | void |
691 | sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, | 713 | sign_message (struct GNUNET_MESSENGER_Message *message, |
692 | const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego) | 714 | uint16_t length, |
715 | char *buffer, | ||
716 | const struct GNUNET_HashCode *hash, | ||
717 | const struct GNUNET_MESSENGER_Ego *ego) | ||
693 | { | 718 | { |
694 | GNUNET_assert((message) && (buffer) && (hash) && (ego)); | 719 | GNUNET_assert((message) && (buffer) && (hash) && (ego)); |
695 | 720 | ||
@@ -706,7 +731,8 @@ sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *b | |||
706 | } | 731 | } |
707 | 732 | ||
708 | int | 733 | int |
709 | verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, | 734 | verify_message (const struct GNUNET_MESSENGER_Message *message, |
735 | const struct GNUNET_HashCode *hash, | ||
710 | const struct GNUNET_IDENTITY_PublicKey *key) | 736 | const struct GNUNET_IDENTITY_PublicKey *key) |
711 | { | 737 | { |
712 | GNUNET_assert((message) && (hash) && (key)); | 738 | GNUNET_assert((message) && (hash) && (key)); |
@@ -726,7 +752,8 @@ verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNU | |||
726 | } | 752 | } |
727 | 753 | ||
728 | int | 754 | int |
729 | encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key) | 755 | encrypt_message (struct GNUNET_MESSENGER_Message *message, |
756 | const struct GNUNET_IDENTITY_PublicKey *key) | ||
730 | { | 757 | { |
731 | GNUNET_assert((message) && (key)); | 758 | GNUNET_assert((message) && (key)); |
732 | 759 | ||
@@ -760,7 +787,8 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_I | |||
760 | } | 787 | } |
761 | 788 | ||
762 | int | 789 | int |
763 | decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key) | 790 | decrypt_message (struct GNUNET_MESSENGER_Message *message, |
791 | const struct GNUNET_IDENTITY_PrivateKey *key) | ||
764 | { | 792 | { |
765 | GNUNET_assert((message) && (key)); | 793 | GNUNET_assert((message) && (key)); |
766 | 794 | ||
@@ -788,8 +816,10 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_I | |||
788 | } | 816 | } |
789 | 817 | ||
790 | struct GNUNET_MQ_Envelope* | 818 | struct GNUNET_MQ_Envelope* |
791 | pack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, | 819 | pack_message (struct GNUNET_MESSENGER_Message *message, |
792 | const struct GNUNET_MESSENGER_Ego *ego, int mode) | 820 | struct GNUNET_HashCode *hash, |
821 | const struct GNUNET_MESSENGER_Ego *ego, | ||
822 | int mode) | ||
793 | { | 823 | { |
794 | GNUNET_assert(message); | 824 | GNUNET_assert(message); |
795 | 825 | ||