Skip to content

Commit 259ff80

Browse files
marcelkottmannme-no-dev
authored andcommitted
use libbase64 macro to calculate base64 length (#2007)
1 parent 3902aa4 commit 259ff80

File tree

2 files changed

+1
-11
lines changed

2 files changed

+1
-11
lines changed

Diff for: cores/esp32/base64.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ extern "C" {
3737
*/
3838
String base64::encode(uint8_t * data, size_t length)
3939
{
40-
// base64 needs more size then the source data
41-
size_t size = ((length * 1.6f) + 1);
40+
size_t size = base64_encode_expected_len(length) + 1;
4241
char * buffer = (char *) malloc(size);
4342
if(buffer) {
4443
base64_encodestate _state;

Diff for: cores/esp32/libb64/cencode.c

-9
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ For details, see http://sourceforge.net/projects/libb64
77

88
#include "cencode.h"
99

10-
const int CHARS_PER_LINE = 72;
11-
1210
void base64_init_encodestate(base64_encodestate* state_in)
1311
{
1412
state_in->step = step_A;
1513
state_in->result = 0;
16-
state_in->stepcount = 0;
1714
}
1815

1916
char base64_encode_value(char value_in)
@@ -68,12 +65,6 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
6865
*codechar++ = base64_encode_value(result);
6966
result = (fragment & 0x03f) >> 0;
7067
*codechar++ = base64_encode_value(result);
71-
72-
++(state_in->stepcount);
73-
if (state_in->stepcount == CHARS_PER_LINE/4) {
74-
*codechar++ = '\n';
75-
state_in->stepcount = 0;
76-
}
7768
}
7869
}
7970
/* control should not reach here */

0 commit comments

Comments
 (0)