base64.obj: decoding algorithm skips spaces, newlines and tabs

git-svn-id: svn://kolibrios.org@9637 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2022-01-15 05:31:50 +00:00
parent 09089615eb
commit 40faa04f49

View File

@ -65,31 +65,33 @@ return j+1;
int base64_decode(char inp[], char outp[], int len) int base64_decode(char inp[], char outp[], int len)
{ {
int i, j, k; int i, j, k, n;
char *chr_adr;
char chr[4]; char chr[4];
for (i = 0, j=-1, k=0; i < len; i+=4) i = 0;
j = -1;
k = 0;
while (i < len)
{ {
chr[0] = strchr(base64_table, inp[i]) - base64_table; for (n = 0; n <= 3; n++)
chr[1] = strchr(base64_table, inp[i+1]) - base64_table;
if (inp[i+2] == '=')
{ {
chr[2] = 0; chr[n] = 0;
while ((inp[i] <= 0x20) & (i < len))
i++;
if (i < len)
{
if ((n >= 2) & (inp[i] == '='))
k++; k++;
}
else else
chr[2] = strchr(base64_table, inp[i+2]) - base64_table;
if (inp[i+3] == '=')
{ {
chr[3] = 0; chr_adr = strchr(base64_table, inp[i]);
k++; if (chr_adr)
chr[n] = chr_adr - base64_table;
}
i++;
}
} }
else
chr[3] = strchr(base64_table, inp[i+3]) - base64_table;
outp[++j] = ((chr[0] << 2) | (chr[1] >> 4)); outp[++j] = ((chr[0] << 2) | (chr[1] >> 4));
outp[++j] = ((chr[1] << 4) | (chr[2] >> 2)); outp[++j] = ((chr[1] << 4) | (chr[2] >> 2));
outp[++j] = ((chr[2] & 0x03 )<< 6) | (chr[3] & 0x3f); outp[++j] = ((chr[2] & 0x03 )<< 6) | (chr[3] & 0x3f);