diff --git a/matcher/base64.c b/matcher/base64.c new file mode 100644 index 0000000..62b2589 --- /dev/null +++ b/matcher/base64.c @@ -0,0 +1,48 @@ +#include +#include +#include + +static int B64Lookup(char x) { + if (x >= 0x41 && x <= 0x5a) { + return x-0x41; + } else if (x >= 0x61 && x <= 0x7a) { + return x-0x61+26; + } else if (x >= 0x30 && x <= 0x39) { + return x-0x30+52; + } else if (x == 0x2d) { + return 62; + } else if (x == 0x5f) { + return 63; + } else { + return 0; + } +} + +int B64DecodeURL(char* input, char** output) { + int b64len = strlen(input); + int output_len = (b64len/4) * 3; + char* buffer = malloc(output_len); + + int count = 0; + for(int i=0; i> 16); + buffer[count++] = (v >> 8) & 0xff; + buffer[count++] = v & 0xFF; + } + *output = buffer; + + if (b64len > 0 && input[b64len-1] == '=') { + output_len--; + } + if (b64len > 1 && input[b64len-2] == '=') { + output_len--; + } + + + return output_len; +} diff --git a/matcher/base64.h b/matcher/base64.h new file mode 100644 index 0000000..daa7f9c --- /dev/null +++ b/matcher/base64.h @@ -0,0 +1,6 @@ +#ifndef BASE64_H +#define BASE64_H + +int B64DecodeURL(char* input, char** output); + +#endif