aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-11 10:37:00 -0400
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-11 10:37:00 -0400
commit2267c37ca0cbb4fd7ff188fdae0512773fb28866 (patch)
tree0fe44255469f1df2a70392ddd4b16709b6b50813
parent426133915bc1cce66a9421409ffe47e50d1bd0c6 (diff)
downloaddeduper-2267c37ca0cbb4fd7ff188fdae0512773fb28866.tar.xz
Remove unused base64 functions.
-rw-r--r--base64.cpp106
-rw-r--r--base64.hpp3
2 files changed, 2 insertions, 107 deletions
diff --git a/base64.cpp b/base64.cpp
index 7de7ade..3dae3a2 100644
--- a/base64.cpp
+++ b/base64.cpp
@@ -1,113 +1,11 @@
+//Chris Xiong 2022
+//License: MPL-2.0
#include <string>
#include <cstdint>
#include <cstdlib>
#include "base64.hpp"
-std::string base64_encode(const void *data, size_t len)
-{
- static const char *b64c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- std::string ret;
- size_t counter = 0;
- uint8_t rem;
- const uint8_t *u8d = (uint8_t*) data;
- for (size_t i = 0; i < len; ++i)
- {
- ++counter;
- if (counter == 3) counter = 0;
- switch (counter)
- {
- case 0:
- rem |= (u8d[i] >> 6);
- ret.push_back(b64c[rem]);
- ret.push_back(b64c[u8d[i] & 0b111111]);
- break;
- case 1:
- ret.push_back(b64c[u8d[i] >> 2]);
- rem = (u8d[i] & 0b11) << 4;
- break;
- case 2:
- rem |= (u8d[i] >> 4);
- ret.push_back(b64c[rem]);
- rem = (u8d[i] & 0b1111) << 2;
- break;
- }
- }
- if (counter)
- {
- ret.push_back(b64c[rem]);
- for (int i = 0; i < 3 - counter; ++i)
- ret.push_back('=');
- }
- return ret;
-}
-
-void* base64_decode(const std::string& s, size_t *rel)
-{
- static const uint8_t b64v[] = {
- 65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,
- 65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,
- 65,65,65,65,65,65,65,65,65,65,65,62,65,65,65,63,
- 52,53,54,55,56,57,58,59,60,61,65,65,65,64,65,65,
- 65, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
- 15,16,17,18,19,20,21,22,23,24,25,65,65,65,65,65,
- 65,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
- 41,42,43,44,45,46,47,48,49,50,51,65,65,65,65,65
- };
- size_t npadd = 0;
- for (auto ri = s.rbegin(); ri != s.rend(); ++ri)
- if (*ri == '=')
- ++npadd;
- else break;
- *rel = (s.length() - npadd) / 4 * 3;
- switch (npadd)
- {
- case 0: break;
- case 1: *rel += 2; break;
- case 2: *rel += 1; break;
- default:
- return nullptr;
- }
- uint8_t *ret = (uint8_t*)malloc(*rel);
- uint8_t rem = 0;
- uint8_t counter = 0;
- uint8_t *rp = ret;
- for (size_t i = 0; i < s.size(); ++i)
- {
- ++counter;
- if (counter == 4) counter = 0;
- if (s[i] == '=') break;
- if (s[i] < 0 || b64v[s[i]] > 64)
- return nullptr;
- switch (counter)
- {
- case 0:
- rem |= b64v[s[i]];
- *(rp++) = rem;
- break;
- case 1:
- rem = b64v[s[i]] << 2;
- break;
- case 2:
- rem |= b64v[s[i]] >> 4;
- *(rp++) = rem;
- rem = (b64v[s[i]] & 0b1111) << 4;
- break;
- case 3:
- rem |= b64v[s[i]] >> 2;
- *(rp++) = rem;
- rem = (b64v[s[i]] & 0b11) << 6;
- break;
- }
- }
- if (rp - ret != *rel)
- {
- free(ret);
- return nullptr;
- }
- return ret;
-}
-
const char *Base64Encoder::b64c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
Base64Encoder::Base64Encoder() : counter(0), rem(0), ret(std::string()) {}
diff --git a/base64.hpp b/base64.hpp
index aa48fa7..70d4e40 100644
--- a/base64.hpp
+++ b/base64.hpp
@@ -3,9 +3,6 @@
#include <cstdint>
#include <string>
-std::string base64_encode(const void *data, size_t len);
-void* base64_decode(const std::string &s, size_t *rel);
-
class Base64Encoder
{
private: