| 1 |
int ret = 0; |
| 2 |
const uint8_t *s = (const uint8_t *) src; |
| 3 |
uint8_t *o = (uint8_t *) out; |
| 4 |
uint8_t q; |
| 5 |
|
| 6 |
// Use local temporaries to avoid cache thrashing: |
| 7 |
size_t olen = 0; |
| 8 |
size_t slen = srclen; |
| 9 |
struct base64_state st; |
| 10 |
st.eof = state->eof; |
| 11 |
st.bytes = state->bytes; |
| 12 |
st.carry = state->carry; |
| 13 |
|
| 14 |
// If we previously saw an EOF or an invalid character, bail out: |
| 15 |
if (st.eof) { |
| 16 |
*outlen = 0; |
| 17 |
ret = 0; |
| 18 |
// If there was a trailing '=' to check, check it: |
| 19 |
if (slen && (st.eof == BASE64_AEOF)) { |
| 20 |
state->bytes = 0; |
| 21 |
state->eof = BASE64_EOF; |
| 22 |
ret = ((base64_table_dec_8bit[*s++] == 254) && (slen == 1)) ? 1 : 0; |
| 23 |
} |
| 24 |
return ret; |
| 25 |
} |
| 26 |
|
| 27 |
// Turn four 6-bit numbers into three bytes: |
| 28 |
// out[0] = 11111122 |
| 29 |
// out[1] = 22223333 |
| 30 |
// out[2] = 33444444 |
| 31 |
|
| 32 |
// Duff's device again: |
| 33 |
switch (st.bytes) |
| 34 |
{ |
| 35 |
for (;;) |
| 36 |
{ |
| 37 |
case 0: |