| 34 | static char base64_codes[256]; |
| 35 | |
| 36 | static char * |
| 37 | base64_decode(const char *input) |
| 38 | { |
| 39 | #define decode(A) ((unsigned int)base64_codes[(int)input[A]]) |
| 40 | |
| 41 | char *output; |
| 42 | char *obuf; |
| 43 | int len; |
| 44 | |
| 45 | for (len = 0; (input[len] != '\0') && (input[len] != '='); len++) { |
| 46 | ; |
| 47 | } |
| 48 | |
| 49 | output = obuf = static_cast<char *>(TSmalloc((len * 6) / 8 + 3)); |
| 50 | |
| 51 | while (len > 0) { |
| 52 | *output++ = decode(0) << 2 | decode(1) >> 4; |
| 53 | *output++ = decode(1) << 4 | decode(2) >> 2; |
| 54 | *output++ = decode(2) << 6 | decode(3); |
| 55 | len -= 4; |
| 56 | input += 4; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * We don't need to worry about leftover bits because |
| 61 | * we've allocated a few extra characters and if there |
| 62 | * are leftover bits they will be zeros because the extra |
| 63 | * inputs will be '='s and '=' decodes to 0. |
| 64 | */ |
| 65 | |
| 66 | *output = '\0'; |
| 67 | return obuf; |
| 68 | |
| 69 | #undef decode |
| 70 | } |
| 71 | |
| 72 | static int |
| 73 | authorized(char *user, char *password) |
no test coverage detected