aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/string_utils/base64/base64.cpp
diff options
context:
space:
mode:
authorAlexey Salmin <alexey.salmin@gmail.com>2022-02-10 16:49:37 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:37 +0300
commit3c5b1607b38f637d2f3313791ed25c2e080d2647 (patch)
tree99be7b96e7c66612fbca94331100ef3b5fedcb88 /library/cpp/string_utils/base64/base64.cpp
parentde89752358147d7b25ef59a85b431bb564068a49 (diff)
downloadydb-3c5b1607b38f637d2f3313791ed25c2e080d2647.tar.gz
Restoring authorship annotation for Alexey Salmin <alexey.salmin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/string_utils/base64/base64.cpp')
-rw-r--r--library/cpp/string_utils/base64/base64.cpp66
1 files changed, 33 insertions, 33 deletions
diff --git a/library/cpp/string_utils/base64/base64.cpp b/library/cpp/string_utils/base64/base64.cpp
index 05c201f0de..d368156033 100644
--- a/library/cpp/string_utils/base64/base64.cpp
+++ b/library/cpp/string_utils/base64/base64.cpp
@@ -95,46 +95,46 @@ static_assert(Y_ARRAY_SIZE(base64_bkw) == 256, "wrong size");
// Base64 for url encoding, RFC3548
static const char base64_etab_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
-static inline unsigned char GetBase64EncodedIndex0(unsigned char octet0) {
- return (octet0 >> 2);
-}
-
-static inline unsigned char GetBase64EncodedIndex1(unsigned char octet0, unsigned char octet1) {
- return (((octet0 << 4) & 0x30) | ((octet1 >> 4) & 0x0f));
-}
-
-static inline unsigned char GetBase64EncodedIndex2(unsigned char octet1, unsigned char octet2) {
- return (((octet1 << 2) & 0x3c) | ((octet2 >> 6) & 0x03));
-}
-
-static inline unsigned char GetBase64EncodedIndex3(unsigned char octet2) {
- return (octet2 & 0x3f);
-}
-
+static inline unsigned char GetBase64EncodedIndex0(unsigned char octet0) {
+ return (octet0 >> 2);
+}
+
+static inline unsigned char GetBase64EncodedIndex1(unsigned char octet0, unsigned char octet1) {
+ return (((octet0 << 4) & 0x30) | ((octet1 >> 4) & 0x0f));
+}
+
+static inline unsigned char GetBase64EncodedIndex2(unsigned char octet1, unsigned char octet2) {
+ return (((octet1 << 2) & 0x3c) | ((octet2 >> 6) & 0x03));
+}
+
+static inline unsigned char GetBase64EncodedIndex3(unsigned char octet2) {
+ return (octet2 & 0x3f);
+}
+
template <bool urlVersion>
static inline char* Base64EncodeImpl(char* outstr, const unsigned char* instr, size_t len) {
- const char* const base64_etab = (urlVersion ? base64_etab_url : base64_etab_std);
- const char pad = (urlVersion ? ',' : '=');
+ const char* const base64_etab = (urlVersion ? base64_etab_url : base64_etab_std);
+ const char pad = (urlVersion ? ',' : '=');
size_t idx = 0;
- while (idx + 2 < len) {
- *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])];
- *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])];
- *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], instr[idx + 2])];
- *outstr++ = base64_etab[GetBase64EncodedIndex3(instr[idx + 2])];
- idx += 3;
- }
- if (idx < len) {
- *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])];
- if (idx + 1 < len) {
- *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])];
- *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], '\0')];
+ while (idx + 2 < len) {
+ *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])];
+ *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])];
+ *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], instr[idx + 2])];
+ *outstr++ = base64_etab[GetBase64EncodedIndex3(instr[idx + 2])];
+ idx += 3;
+ }
+ if (idx < len) {
+ *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])];
+ if (idx + 1 < len) {
+ *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])];
+ *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], '\0')];
} else {
- *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], '\0')];
- *outstr++ = pad;
+ *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], '\0')];
+ *outstr++ = pad;
}
- *outstr++ = pad;
+ *outstr++ = pad;
}
*outstr = 0;