Encrypted messages

#include <frontg8/protocol/message/encrypted.h>

Typedefs

typedef fg8_protocol_message_encrypted_t
typedef fg8_protocol_message_encrypted_const_t

Functions

fg8_protocol_message_encrypted_t fg8_protocol_message_encrypted_create(char const *const content, size_t const length, fg8_error_t *const error)

Create an encrypted message.

Author
Felix Morgner
Since
0.1.0
Return
An encrypted message if construction succeedes. Otherwise, NULL is returned and if error is not NULL, it will be set to a new error object.
Parameters
  • content -

    The content of new message. Might be NULL.

  • length -

    The length of the data pointed to by content. Passing in 0 will result in an empty message.

  • error -

    A pointer to an error object. Might be NULL.

fg8_protocol_message_encrypted_t fg8_protocol_message_encrypted_copy(fg8_protocol_message_encrypted_const_t other, fg8_error_t *const error)

Create an encrypted message by copying an existing one.

Author
Felix Morgner
Since
0.1.0
Note
Passing an NULL object for other will result in an error.
Return
An encrypted message if copy construction succeedes. Otherwise, NULL is returned and if error is not NULL, it will be set to a new error object.
Parameters
  • other -

    The source of the copy.

  • error -

    A pointer to an error object. Might be NULL.

void fg8_protocol_message_encrypted_destroy(fg8_protocol_message_encrypted_t const instance)

Cleanup and destroy an encrypted message.

Author
Felix Morgner
Since
0.1.0
Note
You must use this function to cleanup messages you no longer need. Accessing an encrypted message object after destruction might lead to undefined behaviour.
Parameters
  • instance -

    An existing encrypted message. Might be NULL.

fg8_protocol_message_encrypted_t fg8_protocol_message_encrypted_deserialize(char const *const data, size_t length, fg8_error_t *const error)

Create an encrypted message from serialized data.

Author
Felix Morgner
Since
0.1.0
Note
Passing in NULL for content will result in a default constructed encrypted message being returned.
Return
An encrypted message if deserialization succeedes. Otherwise, NULL is returned and if error is not NULL, it will be set to a new error object.
Parameters
  • data -

    A string pointing to serialized data. Might be NULL.

  • length -

    The length of the data pointed to by data

  • error -

    A pointer to an error object. Might be NULL.

char* fg8_protocol_message_encrypted_serialize(fg8_protocol_message_encrypted_const_t const instance, size_t * length, fg8_error_t *const error)

Serialize an encrypted message into a byte array.

Author
Felix Morgner
Since
0.1.0
Return
A pointer to the first byte of the serialized data. The memory is owned by the client and must be freed appropriately. If serialization fails, a NULL pointer is returned and error is set accordingly if a non NULL value was passed in.
Parameters
  • instance -

    The message to be serialized. Must not be NULL.

  • length -

    A pointer to a variable in which the size of the returned array will be stored. Might be NULL.

  • error -

    A pointer to an error object. Might be NULL.

char const* fg8_protocol_message_encrypted_get_content(fg8_protocol_message_encrypted_const_t const instance, size_t *const length, fg8_error_t *const error)

Get the content of an encrypted message.

Author
Felix Morgner
Since
0.1.0
Return
A string containing the content data of instance or NULL if the encrypted message has no content (e.g is default-initialized). The memory is managed by the instance and must not be freed. If error is not NULL and an error occurs, it will be set to point to a new error object.
Parameters
  • instance -

    An encrypted message. Must not be NULL.

  • length -

    A pointer to a variable in which the size of the returned array will be stored. Might be NULL.

  • error -

    A pointer to an error object. Might be NULL.

void fg8_protocol_message_encrypted_set_content(fg8_protocol_message_encrypted_t const instance, char const *const content, size_t const length, fg8_error_t *const error)

Set the content of an encrypted message.

Author
Felix Morgner
Since
0.1.0
Note
If an error occurs, instance will remain unchanged and error will be set accordingly if a non NULL value was passed in
Parameters
  • instance -

    An encrypted message. Must not be NULL.

  • content -

    The new content of the message. Passing in NULL will clear the message content.

  • length -

    The length of the data pointed to by content.

  • error -

    A pointer to an error object. Might be NULL.

bool fg8_protocol_message_encrypted_is_valid(fg8_protocol_message_encrypted_const_t const instance)

Check if an encrypted message is in a valid state (e.g has content)

Author
Felix Morgner
Since
0.1.0
Return
true if the message is valid, false otherwise
Parameters
  • instance -

    An encrypted message.

bool fg8_protocol_message_encrypted_compare_equal(fg8_protocol_message_encrypted_const_t const left, fg8_protocol_message_encrypted_const_t const right)

Compare two encrypted messages for equality.

Author
Felix Morgner
Since
0.1.0
Note
Two messages are considered equal iff they have the same content. NULL values always compare unequal.
Return
true if the messages are equal, false otherwise
Parameters
  • left -

    An encrypted message (“left-hand side”)

  • right -

    An encrypted message (“right-hand side”)