forked from osmocom/wireshark
Allow the base64 decoding to cope with lines broken with \r\n.
svn path=/trunk/; revision=22309
This commit is contained in:
parent
fc842e9933
commit
cf24e2c104
|
@ -35,28 +35,35 @@
|
|||
|
||||
size_t epan_base64_decode(char *s)
|
||||
{
|
||||
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n";
|
||||
int bit_offset, byte_offset, idx, i, n;
|
||||
unsigned char *d = (unsigned char *)s;
|
||||
char *p;
|
||||
int cr_idx;
|
||||
|
||||
/* we will allow CR and LF - but ignore them */
|
||||
cr_idx = strchr(b64, '\r') - b64;
|
||||
|
||||
n=i=0;
|
||||
|
||||
while (*s && (p=strchr(b64, *s))) {
|
||||
idx = (int)(p - b64);
|
||||
byte_offset = (i*6)/8;
|
||||
bit_offset = (i*6)%8;
|
||||
d[byte_offset] &= ~((1<<(8-bit_offset))-1);
|
||||
if (bit_offset < 3) {
|
||||
d[byte_offset] |= (idx << (2-bit_offset));
|
||||
n = byte_offset+1;
|
||||
} else {
|
||||
d[byte_offset] |= (idx >> (bit_offset-2));
|
||||
d[byte_offset+1] = 0;
|
||||
d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
|
||||
n = byte_offset+2;
|
||||
if(idx < cr_idx) {
|
||||
byte_offset = (i*6)/8;
|
||||
bit_offset = (i*6)%8;
|
||||
d[byte_offset] &= ~((1<<(8-bit_offset))-1);
|
||||
if (bit_offset < 3) {
|
||||
d[byte_offset] |= (idx << (2-bit_offset));
|
||||
n = byte_offset+1;
|
||||
} else {
|
||||
d[byte_offset] |= (idx >> (bit_offset-2));
|
||||
d[byte_offset+1] = 0;
|
||||
d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
|
||||
n = byte_offset+2;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
s++; i++;
|
||||
s++;
|
||||
}
|
||||
|
||||
return n;
|
||||
|
|
Loading…
Reference in New Issue