IoTivity-Lite
|
#include "oc_export.h"
#include "util/oc_compiler.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Enumerations | |
enum | oc_base64_encoding_t { OC_BASE64_ENCODING_STD , OC_BASE64_ENCODING_URL } |
Functions | |
int | oc_base64_decode (uint8_t *str, size_t len) |
In place decoding of base 64 string. More... | |
int | oc_base64_decode_v1 (oc_base64_encoding_t encoding, bool padding, const uint8_t *input, size_t input_size, uint8_t *output_buffer, size_t output_buffer_size) |
Decode a base64 array to a byte array. More... | |
int | oc_base64_decoded_output_size (const uint8_t *input, size_t input_size, bool padding) |
Calculate the size of the output buffer required to store a decoded base64 array. More... | |
int | oc_base64_encode (const uint8_t *input, size_t input_size, uint8_t *output_buffer, size_t output_buffer_size) |
Encode byte buffer to base64 string. More... | |
int | oc_base64_encode_v1 (oc_base64_encoding_t encoding, bool padding, const uint8_t *input, size_t input_size, uint8_t *output_buffer, size_t output_buffer_size) |
Encode byte buffer to base64 string. More... | |
size_t | oc_base64_encoded_output_size (size_t size, bool padding) |
Calculate the size of the output buffer required to encode a byte array to base64. More... | |
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_decode_v1 | ( | oc_base64_encoding_t | encoding, |
bool | padding, | ||
const uint8_t * | input, | ||
size_t | input_size, | ||
uint8_t * | output_buffer, | ||
size_t | output_buffer_size | ||
) |
Decode a base64 array to a byte array.
encoding | type of encoding to use | |
padding | true if the input array is padded with '=' characters at the end | |
input | pointer to base64 encoded string | |
input_size | size of base64 encoded string | |
[out] | output_buffer | buffer to hold the decoded byte array |
output_buffer_size | size of the output_buffer |
int oc_base64_decoded_output_size | ( | const uint8_t * | input, |
size_t | input_size, | ||
bool | padding | ||
) |
Calculate the size of the output buffer required to store a decoded base64 array.
input | input base64-encoded array |
input_size | size of the input base64-encoded array |
padding | true if the input array is padded with '=' characters at the end |
int oc_base64_encode | ( | const uint8_t * | input, |
size_t | input_size, | ||
uint8_t * | output_buffer, | ||
size_t | output_buffer_size | ||
) |
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_size | size of input byte array |
[out] | output_buffer | buffer to hold the base 64 encoded string |
[in] | output_buffer_size | size of the output_buffer |
-1
if the output buffer provided was not large enough int oc_base64_encode_v1 | ( | oc_base64_encoding_t | encoding, |
bool | padding, | ||
const uint8_t * | input, | ||
size_t | input_size, | ||
uint8_t * | output_buffer, | ||
size_t | output_buffer_size | ||
) |
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.
encoding | type of encoding to use | |
padding | true if padding should be used | |
input | pointer to input byte array to be encoded | |
input_size | size of input byte array | |
[out] | output_buffer | buffer to hold the base 64 encoded string |
output_buffer_size | size of the output_buffer |
-1
if the output buffer provided was not large enough size_t oc_base64_encoded_output_size | ( | size_t | size, |
bool | padding | ||
) |
Calculate the size of the output buffer required to encode a byte array to base64.
size | size of the input byte array |
padding | true if padding should be used |