GNUnet  0.11.x
messenger_api_message.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2020 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  */
26 #ifndef GNUNET_MESSENGER_API_MESSAGE_H
27 #define GNUNET_MESSENGER_API_MESSAGE_H
28 
29 #include "platform.h"
30 #include "gnunet_crypto_lib.h"
32 #include "gnunet_mq_lib.h"
33 #include "gnunet_signatures.h"
34 
36 
37 #include "messenger_api_ego.h"
38 
47 
55 copy_message (const struct GNUNET_MESSENGER_Message *message);
56 
62 void
64 
71 uint16_t
73 
80 uint16_t
81 get_message_size (const struct GNUNET_MESSENGER_Message *message);
82 
90 void
91 encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer);
92 
106 int
107 decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer);
108 
116 void
117 hash_message (uint16_t length, const char *buffer, struct GNUNET_HashCode *hash);
118 
129 void
130 sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer,
131  const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego);
132 
143 int
144 verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash,
145  const struct GNUNET_IDENTITY_PublicKey *key);
146 
156 int
158 
168 int
170 
171 #define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1
172 #define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0
173 
186 struct GNUNET_MQ_Envelope*
187 pack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash,
188  const struct GNUNET_MESSENGER_Ego *ego, int mode);
189 
190 #endif //GNUNET_MESSENGER_API_MESSAGE_H
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
Returns the minimal size in bytes to encode a message of a specific kind.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
Encodes a given message into a buffer of a maximal length in bytes.
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
int encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
A private key for an identity as per LSD0001.
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
int verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_IDENTITY_PublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
cryptographic primitives for GNUnet
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message)
Returns the exact size in bytes to encode a given message.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
int decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
A 512-bit hashcode.
GNUnet MESSENGER service.
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer)
Decodes a message from a given buffer of a maximal length in bytes.
struct GNUNET_HashCode key
The key used in the DHT.
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego)
Signs the hash of a message with a given ego and writes the signature into the buffer as well...
An identity key as per LSD0001.
void hash_message(uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer of a length in bytes.
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego, int mode)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...