-
Notifications
You must be signed in to change notification settings - Fork 4
/
arduino_base64.hpp
58 lines (53 loc) · 1.58 KB
/
arduino_base64.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include "stdint.h"
#include "string.h"
/**
* Convert between binary and base64 encoded string.
* @see https://github.com/dojyorin/arduino_base64
*/
namespace base64 {
/**
* Convert binary to base64 encoded string.
* If input is string, cast to `uint8_t*`.
* @example
* ```c++
* const uint8_t input[] = {0x17, 0x77, 0x3B, 0x11, 0x82, 0xA4, 0xC4, 0xC8};
* auto inputLength = sizeof(input);
* char output[base64::encodeLength(inputLength)];
* base64::encode(input, inputLength, output);
* ```
*/
void encode(const uint8_t* input, size_t inputLength, char* output);
/**
* Calculate number of output characters.
* @example
* ```c++
* const uint8_t input[] = {0x17, 0x77, 0x3B, 0x11, 0x82, 0xA4, 0xC4, 0xC8};
* auto inputLength = sizeof(input);
* char output[base64::encodeLength(inputLength)];
* base64::encode(input, inputLength, output);
* ```
*/
size_t encodeLength(size_t inputLength);
/**
* Convert base64 encoded string to binary.
* If output is string, cast to `char*`.
* @example
* ```c++
* const char input[] = "F3c7EYKkxMgnvO0nB8FWVw==";
* uint8_t output[base64::decodeLength(input)];
* base64::decode(input, output);
* ```
*/
void decode(const char* input, uint8_t* output);
/**
* Calculate number of output bytes.
* @example
* ```c++
* const char input[] = "F3c7EYKkxMgnvO0nB8FWVw==";
* uint8_t output[base64::decodeLength(input)];
* base64::decode(input, output);
* ```
*/
size_t decodeLength(const char* input);
}