From 38b4a53d57c85ba52952d04ea96f7649ef1295ef Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 16 Dec 2018 16:21:58 -0500 Subject: Move base64 to string.c --- pls.c | 60 ------------------------------------------------------------ 1 file changed, 60 deletions(-) (limited to 'pls.c') diff --git a/pls.c b/pls.c index 4e032c8..d91fc97 100644 --- a/pls.c +++ b/pls.c @@ -131,63 +131,3 @@ int aswprintf(wchar_t **ret, const wchar_t *format, ...) { va_end(ap); return n; } - -static const char Base64[64] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -char *base64(const byte *src, size_t len) { - char *dst = malloc(1 + 4 * (len + 2) / 3); - if (!dst) return NULL; - size_t i = 0; - while (len > 2) { - dst[i++] = Base64[0x3F & (src[0] >> 2)]; - dst[i++] = Base64[0x3F & (src[0] << 4 | src[1] >> 4)]; - dst[i++] = Base64[0x3F & (src[1] << 2 | src[2] >> 6)]; - dst[i++] = Base64[0x3F & src[2]]; - src += 3; - len -= 3; - } - if (len) { - dst[i++] = Base64[0x3F & (src[0] >> 2)]; - if (len > 1) { - dst[i++] = Base64[0x3F & (src[0] << 4 | src[1] >> 4)]; - dst[i++] = Base64[0x3F & (src[1] << 2)]; - } else { - dst[i++] = Base64[0x3F & (src[0] << 4)]; - dst[i++] = '='; - } - dst[i++] = '='; - } - dst[i] = '\0'; - return dst; -} - -#ifdef TEST -#include -#include - -int main() { - char *cat = base64((byte *)"cat", 3); - char *ca = base64((byte *)"ca", 2); - char *c = base64((byte *)"c", 1); - assert(cat); - assert(ca); - assert(c); - assert(!strcmp("Y2F0", cat)); - assert(!strcmp("Y2E=", ca)); - assert(!strcmp("Yw==", c)); - free(cat); - free(ca); - free(c); - - char *fzf = base64((byte []) { 0xFF, 0x00, 0xFF }, 3); - char *zfz = base64((byte []) { 0x00, 0xFF, 0x00 }, 3); - assert(fzf); - assert(zfz); - assert(!strcmp("/wD/", fzf)); - assert(!strcmp("AP8A", zfz)); - free(fzf); - free(zfz); -} - -#endif -- cgit 1.4.1 ption value='author'>author
Commit message (Expand)Author
2020-02-11Add .gz to chroot-man scriptJune McEnroe
2020-02-11Add -R restricted flagJune McEnroe
2020-02-11Add chroot targetJune McEnroe
2020-02-11Exit focus and paste modes on err exitJune McEnroe
2020-02-11Add startup GPLv3 note and URLJune McEnroe
2020-02-11Make sure -D_GNU_SOURCE ends up in CFLAGS on LinuxJune McEnroe
2020-02-11Add note about setting PKG_CONFIG_PATHJune McEnroe
2020-02-11Rename query ID on nick changeJune McEnroe
2020-02-11Call completeClear when closing a windowJune McEnroe
2020-02-11Don't insert color codes for non-mentionsJune McEnroe
2020-02-11Take first two words in colorMentionsJune McEnroe
2020-02-11Use time_t for save signatureJune McEnroe
2020-02-11Set self.nick to * initiallyJune McEnroe
2020-02-11Define ColorCap instead of hardcoding 100June McEnroe
2020-02-11Move hash to top of chat.hJune McEnroe
2020-02-11Move base64 out of chat.hJune McEnroe
2020-02-11Move XDG_SUBDIR out of chat.hJune McEnroe
2020-02-11Fix whois idle unit calculationJune McEnroe
2020-02-11Cast towupper to wchar_tJune McEnroe
2020-02-11Cast set but unused variables to voidJune McEnroe
2020-02-11Declare strlcatJune McEnroe
2020-02-11Check if VDSUSP existsJune McEnroe
2020-02-11Fix completeReplace iterationJune McEnroe
2020-02-11Use pkg(8) to configure on FreeBSDJune McEnroe
2020-02-11Remove legacy codeJune McEnroe
2020-02-11Add INSTALLING section to READMEJune McEnroe