summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--decode.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/decode.c b/decode.c
index 8578c41..8fd005d 100644
--- a/decode.c
+++ b/decode.c
@@ -86,20 +86,30 @@ static void convertCharset(
 	iconv_close(conv);
 }
 
-static const char Base64[64] = {
+static const uint8_t Base64[64] = {
 	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
 };
+static uint8_t Table64[256];
+
+static uint8_t unbase64(char ch) {
+	if (!Table64[Base64[1]]) {
+		for (size_t i = 0; i < sizeof(Base64); ++i) {
+			Table64[Base64[i]] = i;
+		}
+	}
+	return Table64[(uint8_t)ch];
+}
 
 static void decodeBase64(struct Buffer *dst, const char *src) {
 	while (src[0] && src[1] && src[2] && src[3]) {
-		if (!strchr(Base64, src[0])) {
+		if (!unbase64(src[0]) && src[0] != Base64[0]) {
 			src++;
 			continue;
 		}
 		uint32_t bits = 0;
 		for (int i = 0; i < 4; ++i) {
 			bits <<= 6;
-			bits |= strchr(Base64, src[i]) - Base64;
+			bits |= unbase64(src[i]);
 		}
 		*bufferDest(dst, 1) = bits >> 16;
 		if (src[2] != '=') *bufferDest(dst, 1) = bits >> 8;
f&follow=1'>Add DO YOU DOUBT ME TRAITORJune McEnroe 2019-12-22Add license header to cgit CSSJune McEnroe 2019-12-22Add The Book of EttaJune McEnroe 2019-12-21Revert "Add first working version of imbox"June McEnroe 2019-12-21Add first working version of imboxJune McEnroe 2019-12-20Respect mailmap in gl pretty formatJune McEnroe 2019-12-20Set LANG in cgit filtersJune McEnroe 2019-12-20Source .editrc before applying -v or -eJune McEnroe 2019-12-20Disable signing commitsJune McEnroe 2019-12-19Ignore about-filterJune McEnroe 2019-12-19Fix matching make tags with no sourcesJune McEnroe 2019-12-19Avoid matching := assignments as tagsJune McEnroe 2019-12-18Hide line numbers when rendering mdocJune McEnroe 2019-12-18Customize cgit CSSJune McEnroe 2019-12-18Use :target rather than :focus pseudo-classJune McEnroe 2019-12-18Copy cgit auxiliary binaries properlyJune McEnroe 2019-12-18Add git.causal.agency cgit configJune McEnroe 2019-12-18Bail from hi if input is binaryJune McEnroe 2019-12-16Post "cgit setup"June McEnroe