Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when compiling the base example - error: "'base64_enc_len' was not declared in this scope" #18

Open
kwhizr opened this issue Nov 11, 2016 · 7 comments

Comments

@kwhizr
Copy link

kwhizr commented Nov 11, 2016

Arduino IDE 1.6.12

'base64_enc_len' was not declared in this scope

@muhammedkanlidere
Copy link

Same issue did anyone fixed ?

@CvdH
Copy link

CvdH commented Oct 13, 2017

Not sure if any of you are still having this problem, but I ran into this as well (Arduino IDE 1.8.2) and fixed it by renaming the files and functions in the library that were causing the issues

@rkoptev
Copy link

rkoptev commented Apr 13, 2018

Having the same issue (Arduino 1.8.5 & ESP8266). Looks like this file already defined somewhere in sources.

@SimonKlausLudwig
Copy link

SimonKlausLudwig commented Mar 26, 2019

same problem here. I just renamed the two files to MyBase64 and added
#include <WString.h>
to base64.h

@FlorSanders
Copy link

This issue still seems to persist on the ESP8266, the workaround proposed by @SimonKlausLudwig does work though, if anyone but me still might come across this issue.

@RohankumarM
Copy link

#if (defined(AVR))
#include <avr\pgmspace.h>
#else
#include <pgmspace.h>
#endif

const char PROGMEM b64_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";

/* 'Private' declarations */
inline void a3_to_a4(unsigned char * a4, unsigned char * a3);
inline void a4_to_a3(unsigned char * a3, unsigned char * a4);
inline unsigned char b64_lookup(char c);

int base64_encode(char *output, char *input, int inputLen) {
int i = 0, j = 0;
int encLen = 0;
unsigned char a3[3];
unsigned char a4[4];

while(inputLen--) {
	a3[i++] = *(input++);
	if(i == 3) {
		a3_to_a4(a4, a3);

		for(i = 0; i < 4; i++) {
			output[encLen++] = pgm_read_byte(&b64_alphabet[a4[i]]);
		}

		i = 0;
	}
}

if(i) {
	for(j = i; j < 3; j++) {
		a3[j] = '\0';
	}

	a3_to_a4(a4, a3);

	for(j = 0; j < i + 1; j++) {
		output[encLen++] = pgm_read_byte(&b64_alphabet[a4[j]]);
	}

	while((i++ < 3)) {
		output[encLen++] = '=';
	}
}
output[encLen] = '\0';
return encLen;

}

int base64_decode(char * output, char * input, int inputLen) {
int i = 0, j = 0;
int decLen = 0;
unsigned char a3[3];
unsigned char a4[4];

while (inputLen--) {
	if(*input == '=') {
		break;
	}

	a4[i++] = *(input++);
	if (i == 4) {
		for (i = 0; i <4; i++) {
			a4[i] = b64_lookup(a4[i]);
		}

		a4_to_a3(a3,a4);

		for (i = 0; i < 3; i++) {
			output[decLen++] = a3[i];
		}
		i = 0;
	}
}

if (i) {
	for (j = i; j < 4; j++) {
		a4[j] = '\0';
	}

	for (j = 0; j <4; j++) {
		a4[j] = b64_lookup(a4[j]);
	}

	a4_to_a3(a3,a4);

	for (j = 0; j < i - 1; j++) {
		output[decLen++] = a3[j];
	}
}
output[decLen] = '\0';
return decLen;

}

int base64_enc_len(int plainLen) {
int n = plainLen;
return (n + 2 - ((n + 2) % 3)) / 3 * 4;
}

int base64_dec_len(char * input, int inputLen) {
int i = 0;
int numEq = 0;
for(i = inputLen - 1; input[i] == '='; i--) {
numEq++;
}

return ((6 * inputLen) / 8) - numEq;

}

inline void a3_to_a4(unsigned char * a4, unsigned char * a3) {
a4[0] = (a3[0] & 0xfc) >> 2;
a4[1] = ((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4);
a4[2] = ((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6);
a4[3] = (a3[2] & 0x3f);
}

inline void a4_to_a3(unsigned char * a3, unsigned char * a4) {
a3[0] = (a4[0] << 2) + ((a4[1] & 0x30) >> 4);
a3[1] = ((a4[1] & 0xf) << 4) + ((a4[2] & 0x3c) >> 2);
a3[2] = ((a4[2] & 0x3) << 6) + a4[3];
}

inline unsigned char b64_lookup(char c) {
if(c >='A' && c <='Z') return c - 'A';
if(c >='a' && c <='z') return c - 71;
if(c >='0' && c <='9') return c + 4;
if(c == '+') return 62;
if(c == '/') return 63;
return -1;
}

@Davithronix
Copy link

Pls anyone who can help to solve this error code as below?

C:\Users\user\Documents\Arduino\libraries\WaziDev\src\WaziDev.cpp:188:18: error: 'base64_enc_len' was not declared in this scope
int encLen = base64_enc_len(len);
^~~~~~~~~~~~~~
C:\Users\user\Documents\Arduino\libraries\WaziDev\src\WaziDev.cpp:190:5: error: 'base64_encode' was not declared in this scope
base64_encode(h, buf, len);
^~~~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants