diff options
Diffstat (limited to 'third_party/nix/src/libutil/util.cc')
-rw-r--r-- | third_party/nix/src/libutil/util.cc | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/third_party/nix/src/libutil/util.cc b/third_party/nix/src/libutil/util.cc index b97624e58dbb..f69c341c2c59 100644 --- a/third_party/nix/src/libutil/util.cc +++ b/third_party/nix/src/libutil/util.cc @@ -1321,73 +1321,6 @@ std::string filterANSIEscapes(const std::string& s, bool filterAll, return t; } -static char base64Chars[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -std::string base64Encode(const std::string& s) { - std::string res; - int data = 0; - int nbits = 0; - - for (char c : s) { - data = data << 8 | (unsigned char)c; - nbits += 8; - while (nbits >= 6) { - nbits -= 6; - res.push_back(base64Chars[data >> nbits & 0x3f]); - } - } - - if (nbits != 0) { - res.push_back(base64Chars[data << (6 - nbits) & 0x3f]); - } - while ((res.size() % 4) != 0u) { - res.push_back('='); - } - - return res; -} - -std::string base64Decode(const std::string& s) { - bool init = false; - char decode[256]; - if (!init) { - // FIXME: not thread-safe. - memset(decode, -1, sizeof(decode)); - for (int i = 0; i < 64; i++) { - decode[(int)base64Chars[i]] = i; - } - init = true; - } - - std::string res; - unsigned int d = 0; - unsigned int bits = 0; - - for (char c : s) { - if (c == '=') { - break; - } - if (c == '\n') { - continue; - } - - char digit = decode[(unsigned char)c]; - if (digit == -1) { - throw Error("invalid character in Base64 string"); - } - - bits += 6; - d = d << 6 | digit; - if (bits >= 8) { - res.push_back(d >> (bits - 8) & 0xff); - bits -= 8; - } - } - - return res; -} - void callFailure(const std::function<void(std::exception_ptr exc)>& failure, const std::exception_ptr& exc) { try { |