1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-15 00:02:49 +03:00

fix base64_encode_expected_len (#4786)

This commit is contained in:
david gauchard
2018-06-07 15:40:17 +02:00
committed by GitHub
parent 8cda9655e3
commit 73d36bbc80
2 changed files with 8 additions and 5 deletions

View File

@ -7,13 +7,11 @@ For details, see http://sourceforge.net/projects/libb64
#include "cencode.h" #include "cencode.h"
const int CHARS_PER_LINE = 72;
void base64_init_encodestate(base64_encodestate* state_in){ void base64_init_encodestate(base64_encodestate* state_in){
state_in->step = step_A; state_in->step = step_A;
state_in->result = 0; state_in->result = 0;
state_in->stepcount = 0; state_in->stepcount = 0;
state_in->stepsnewline = CHARS_PER_LINE; state_in->stepsnewline = BASE64_CHARS_PER_LINE;
} }
@ -72,7 +70,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
*codechar++ = base64_encode_value(result); *codechar++ = base64_encode_value(result);
++(state_in->stepcount); ++(state_in->stepcount);
if ((state_in->stepcount == CHARS_PER_LINE/4) && (state_in->stepsnewline > 0)){ if ((state_in->stepcount == BASE64_CHARS_PER_LINE/4) && (state_in->stepsnewline > 0)){
*codechar++ = '\n'; *codechar++ = '\n';
state_in->stepcount = 0; state_in->stepcount = 0;
} }

View File

@ -8,7 +8,12 @@ For details, see http://sourceforge.net/projects/libb64
#ifndef BASE64_CENCODE_H #ifndef BASE64_CENCODE_H
#define BASE64_CENCODE_H #define BASE64_CENCODE_H
#define base64_encode_expected_len(n) ((((4 * n) / 3) + 3) & ~3) #define BASE64_CHARS_PER_LINE 72
#define base64_encode_expected_len_nonewlines(n) ((((4 * (n)) / 3) + 3) & ~3)
#define base64_encode_expected_len(n) \
(base64_encode_expected_len_nonewlines(n) + ((n / ((BASE64_CHARS_PER_LINE * 3) / 4)) + 1))
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {