From c001665a7cd67a89cc33ed482fc8e9f3b2f6812a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Mon, 2 Apr 2012 00:30:27 +0200 Subject: [PATCH] Add a packed argument to encode_base64. Reintroduced the '=' padding modulo 3 characters from the original code from the mail kit, and a packed option to avoid it. Broadway uses this packed scheme to save bytes when sending many separate values. TODO: merge this with the mail kit one somewhere? --- src/servers/app/drawing/html5/base64.cpp | 6 +++++- src/servers/app/drawing/html5/base64.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/servers/app/drawing/html5/base64.cpp b/src/servers/app/drawing/html5/base64.cpp index 2afffe7bab..8081559bd7 100644 --- a/src/servers/app/drawing/html5/base64.cpp +++ b/src/servers/app/drawing/html5/base64.cpp @@ -25,7 +25,7 @@ static const char kHexAlphabet[16] = {'0', '1', '2', '3', '4', '5', '6', '7', ssize_t -encode_base64(char *out, const char *in, off_t length) +encode_base64(char *out, const char *in, off_t length, bool packed) { uint32 concat; int i = 0; @@ -45,8 +45,12 @@ encode_base64(char *out, const char *in, off_t length) out[k++] = kBase64Alphabet[(concat >> 12) & 63]; if ((i+1) < length) out[k++] = kBase64Alphabet[(concat >> 6) & 63]; + else if (!packed) + out[k++] = '='; if ((i+2) < length) out[k++] = kBase64Alphabet[concat & 63]; + else if (!packed) + out[k++] = '='; } return k; diff --git a/src/servers/app/drawing/html5/base64.h b/src/servers/app/drawing/html5/base64.h index fa2d3f0625..8d75312a23 100644 --- a/src/servers/app/drawing/html5/base64.h +++ b/src/servers/app/drawing/html5/base64.h @@ -8,7 +8,8 @@ #include -extern ssize_t encode_base64(char *out, const char *in, off_t length); +extern ssize_t encode_base64(char *out, const char *in, off_t length, + bool packed=false); extern ssize_t decode_base64(char *out, const char *in, off_t length);