roo_io
API Documentation for roo_io
Loading...
Searching...
No Matches
arduino_base64.h
Go to the documentation of this file.
1#pragma once
2
3#include "stdint.h"
4#include "string.h"
5
6/**
7* Convert between binary and base64 encoded string.
8* @see https://github.com/dojyorin/arduino_base64
9*/
10namespace base64 {
11 /**
12 * Convert binary to base64 encoded string.
13 * If input is string, cast to `uint8_t*`.
14 * @example
15 * ```c++
16 * const uint8_t input[] = {0x17, 0x77, 0x3B, 0x11, 0x82, 0xA4, 0xC4, 0xC8};
17 * auto inputLength = sizeof(input);
18 * char output[base64::encodeLength(inputLength)];
19 * base64::encode(input, inputLength, output);
20 * ```
21 */
22 void encode(const uint8_t* input, size_t inputLength, char* output);
23
24 /**
25 * Calculate number of output characters.
26 * @example
27 * ```c++
28 * const uint8_t input[] = {0x17, 0x77, 0x3B, 0x11, 0x82, 0xA4, 0xC4, 0xC8};
29 * auto inputLength = sizeof(input);
30 * char output[base64::encodeLength(inputLength)];
31 * base64::encode(input, inputLength, output);
32 * ```
33 */
34 size_t encodeLength(size_t inputLength);
35
36 /**
37 * Convert base64 encoded string to binary.
38 * If output is string, cast to `char*`.
39 * @example
40 * ```c++
41 * const char input[] = "F3c7EYKkxMgnvO0nB8FWVw==";
42 * uint8_t output[base64::decodeLength(input)];
43 * base64::decode(input, output);
44 * ```
45 */
46 void decode(const char* input, size_t inputLength, uint8_t* output);
47
48 /**
49 * Calculate number of output bytes.
50 * @example
51 * ```c++
52 * const char input[] = "F3c7EYKkxMgnvO0nB8FWVw==";
53 * uint8_t output[base64::decodeLength(input)];
54 * base64::decode(input, output);
55 * ```
56 */
57 size_t decodeLength(const char* input);
58}
Convert between binary and base64 encoded string.
size_t decodeLength(const char *input)
Definition base64.cpp:108
void decode(const char *input, size_t inputLength, uint8_t *output)
Definition base64.cpp:72
void encode(const uint8_t *input, size_t inputLength, char *output)
Definition base64.cpp:30
size_t encodeLength(size_t inputLength)
Definition base64.cpp:68