libcontrac
A library for contact tracing
|
Static utility functions. More...
Files | |
file | utils.c |
Static utitlity functions. | |
file | utils.h |
Static utility functions. | |
Macros | |
#define | MAX(a, b) |
#define | MIN(a, b) |
Functions | |
size_t | base64_encode_size (size_t binary_input) |
size_t | base64_decode_size (size_t base64_input) |
void | base64_encode_binary_to_base64 (unsigned char const *input, size_t input_size, unsigned char *output, size_t *output_size) |
void | base64_decode_base64_to_binary (unsigned char const *input, size_t input_size, unsigned char *output, size_t *output_size) |
uint32_t | epoch_to_day_number (time_t epoch) |
uint8_t | epoch_to_time_interval_number (time_t epoch) |
Static utility functions.
Provides various static utitlity functions. In particular:
base64 encoding and decoding functionality. Time conversion: from epoch to day numbers and time interval numbers.
#define MAX | ( | a, | |
b | |||
) |
#define MIN | ( | a, | |
b | |||
) |
void base64_decode_base64_to_binary | ( | unsigned char const * | input, |
size_t | input_size, | ||
unsigned char * | output, | ||
size_t * | output_size | ||
) |
Decodes a base64 string into the original binary data it represents.
Decodes the base64 string provided into binary, storing the result in the output buffer provided. The output buffer must be pre-allocated with enough space to store the result. The size needed can be found by calling the base64_decode_size() function.
If the output buffer is too small (based on the size provided) then the binary output may be only partially written.
input | The base64 string to encode. This doesn't need to be zero terminated. |
input_size | The size of the input buffer to be converted. |
output | A pre-allocated buffer to store the result. |
output_size | The size of the allocated buffer, which will be updated to the number of bytes written to the buffer. |
size_t base64_decode_size | ( | size_t | base64_input | ) |
Returns the amount of space needed to store the binary equivalent of a base64 string.
When converting from base64 it's often useful to know how much space will be needed to store the result, for example so that a buffer of the correct size can be allocated for it.
This function returns the size needed for a buffer that will be large enough to store the result. The returned value may be larger than the size actually needed.
base64_input | The length of a base64 string that would be decoded. |
void base64_encode_binary_to_base64 | ( | unsigned char const * | input, |
size_t | input_size, | ||
unsigned char * | output, | ||
size_t * | output_size | ||
) |
Encodes binary data to base64 format string.
Encodes the binary data provided into a base64 string, storing the result in the output buffer provided. The output buffer must be pre-allocated with enough space to store the result. The size needed can be found by calling the base64_encode_size() function.
If the output buffer is too small (based on the size provided) then the base64 string may be only partially written.
input | The binary data to encode. This doesn't need to be zero terminated. |
input_size | The size of the input buffer to be converted. |
output | A pre-allocated buffer to store the result. |
output_size | The size of the allocated buffer, which will be updated to the number of bytes written to the buffer. |
size_t base64_encode_size | ( | size_t | binary_input | ) |
Returns the amount of space needed to store the base64 equivalent of a binary input.
When converting to base64 it's often useful to know how much space will be needed to store the result, for example so that a buffer of the correct size can be allocated for it.
This function returns the size needed for a buffer that will be large enough to store the result, including a terminating null character. The returned value may be larger than the size actually needed.
binary_input | The length of binary input that would be encoded. |
uint32_t epoch_to_day_number | ( | time_t | epoch | ) |
Converts a time in epoch format into a day number.
Returns the day number for the given epoch time. The epoch time represents the number of seconds since 00:00:00 UTC on 01/01/1970.
The day number is calculated as: (Number of Seconds since Epoch) / (60 * 60 * 24)
epoch | The epoch time in seconds. |
uint8_t epoch_to_time_interval_number | ( | time_t | epoch | ) |
Converts a time in epoch format into a time interval number.
Returns the time interval number for the given epoch time. The epoch time represents the number of seconds since 00:00:00 UTC on 01/01/1970.
The time interval number is calculated as: (Seconds Since Start of DayNumber) / (60 * 10)
and must fall in the interval [0, 143].
epoch | The epoch time in seconds. |