MCPcopy Create free account
hub / github.com/apache/trafficserver / base64_decode

Function base64_decode

example/plugins/c-api/basic_auth/basic_auth.cc:36–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34static char base64_codes[256];
35
36static char *
37base64_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
72static int
73authorized(char *user, char *password)

Callers 1

handle_dnsFunction · 0.85

Calls 1

TSmallocFunction · 0.85

Tested by

no test coverage detected