KNX IoT
KNX IoT Point API stack implementation
|
Base64 encoding and decoding functions. More...
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Functions | |
int | oc_base64_decode (uint8_t *str, size_t len) |
In place decoding of base 64 string. More... | |
int | oc_base64_encode (const uint8_t *input, size_t input_len, uint8_t *output_buffer, size_t output_buffer_len) |
encode byte buffer to base64 string. More... | |
Base64 encoding and decoding functions.
Definition in file oc_base64.h.
int oc_base64_decode | ( | uint8_t * | str, |
size_t | len | ||
) |
In place decoding of base 64 string.
Size of a base 64 input string will always be larger than the resulting byte array. Unused trailing bytes will be set to zero. Use the return value to know the size of the output array.
Example: output_len = oc_base64_decode(b64_buf, strlen(b64_buf)); if (output_len < 0) { //handle error }
[in,out] | str | base 64 encoded string that will be decoded in place. |
[in] | len | size of the base 64 encoded string. |
int oc_base64_encode | ( | const uint8_t * | input, |
size_t | input_len, | ||
uint8_t * | output_buffer, | ||
size_t | output_buffer_len | ||
) |
encode byte buffer to base64 string.
The base64 encoder does not NUL terminate its output. User the return value to add '\0' to the end of the string.
Output is uint8_t casting is needed to use value as a string.
Example:
// calculate the space required for the output size_t b64_buf_size = (sizeof(input) / 3) * 4; if (sizeof(input) % 3 != 0) { b64_buf_size += 4; } // one extra byte for terminating NUL character. b64_buf_size++; // allocate space char *b64_buf = (char *)calloc(1, b64_buf_size); int output_len = oc_base64_encode(input, sizeof(input), (uint8_t *)b64_buf, b64_buf_size); if (output_len < 0) { //handle error } // append NUL character to end of string. b64Buf[output_len] = '\0';
[in] | input | pointer to input byte array to be encoded |
[in] | input_len | size of input byte array |
[out] | output_buffer | buffer to hold the base 64 encoded string |
[in] | output_buffer_len | size of the output_buffer |
-1
if the output buffer provided was not large enough