1 if (slen-- == 0) { 2 ret = 1; 3 break; 4 } 5 if ((q = base64_table_dec_8bit[*s++]) >= 254) { 6 st.eof = BASE64_EOF; 7 // Treat character '=' as invalid for byte 0: 8 break; 9 } 10 st.carry = q << 2; 11 st.bytes++; 12 13 // Deliberate fallthrough: 14 BASE64_FALLTHROUGH 15 16 case 1: if (slen-- == 0) { 17 ret = 1; 18 break; 19 } 20 if ((q = base64_table_dec_8bit[*s++]) >= 254) { 21 st.eof = BASE64_EOF; 22 // Treat character '=' as invalid for byte 1: 23 break; 24 } 25 *o++ = st.carry | (q >> 4); 26 st.carry = q << 4; 27 st.bytes++; 28 olen++; 29 30 // Deliberate fallthrough: 31 BASE64_FALLTHROUGH 32 33 case 2: if (slen-- == 0) { 34 ret = 1; 35 break; 36 } 37 if ((q = base64_table_dec_8bit[*s++]) >= 254) { 38 st.bytes++; 39 // When q == 254, the input char is '='. 40 // Check if next byte is also '=': 41 if (q == 254) { 42 if (slen-- != 0) { 43 st.bytes = 0; 44 // EOF: 45 st.eof = BASE64_EOF; 46 q = base64_table_dec_8bit[*s++]; 47 ret = ((q == 254) && (slen == 0)) ? 1 : 0; 48 break; 49 } 50 else { 51 // Almost EOF 52 st.eof = BASE64_AEOF; 53 ret = 1; 54 break; 55 } 56 } 57 // If we get here, there was an error: 58 break; 59 } 60 *o++ = st.carry | (q >> 2); 61 st.carry = q << 6; 62 st.bytes++; 63 olen++; 64 65 // Deliberate fallthrough: 66 BASE64_FALLTHROUGH 67 68 case 3: if (slen-- == 0) { 69 ret = 1; 70 break; 71 } 72 if ((q = base64_table_dec_8bit[*s++]) >= 254) { 73 st.bytes = 0; 74 st.eof = BASE64_EOF; 75 // When q == 254, the input char is '='. Return 1 and EOF. 76 // When q == 255, the input char is invalid. Return 0 and EOF. 77 ret = ((q == 254) && (slen == 0)) ? 1 : 0; 78 break; 79 } 80 *o++ = st.carry | q; 81 st.carry = 0; 82 st.bytes = 0; 83 olen++; 84 } 85 } 86 87 state->eof = st.eof; 88 state->bytes = st.bytes; 89 state->carry = st.carry; 90 *outlen = olen; 91 return ret; 92