Skip to content

Commit 70f844d

Browse files
committed
Test
1 parent d52d99b commit 70f844d

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

cores/esp32/base64-copy.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* base64.cpp
3+
*
4+
* Created on: 09.12.2015
5+
*
6+
* Copyright (c) 2015 Markus Sattler. All rights reserved.
7+
* This file is part of the ESP31B core for Arduino.
8+
*
9+
* This library is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with this library; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*
23+
*/
24+
25+
#include "Arduino.h"
26+
extern "C" {
27+
#include "libb64/cdecode.h"
28+
#include "libb64/cencode.h"
29+
}
30+
#include "base64.h"
31+
32+
/**
33+
* convert input data to base64
34+
* @param data const uint8_t *
35+
* @param length size_t
36+
* @return String
37+
*/
38+
String base64::encode(const uint8_t *data, size_t length) {
39+
size_t size = base64_encode_expected_len(length) + 1;
40+
char *buffer = (char *)malloc(size);
41+
if (buffer) {
42+
base64_encodestate _state;
43+
base64_init_encodestate(&_state);
44+
int len = base64_encode_block((const char *)&data[0], length, &buffer[0], &_state);
45+
len = base64_encode_blockend((buffer + len), &_state);
46+
47+
String base64 = String(buffer);
48+
free(buffer);
49+
return base64;
50+
}
51+
return String("-FAIL-");
52+
}
53+
54+
/**
55+
* convert input data to base64
56+
* @param text const String&
57+
* @return String
58+
*/
59+
String base64::encode(const String &text) {
60+
return base64::encode((uint8_t *)text.c_str(), text.length());
61+
}

0 commit comments

Comments
 (0)