summaryrefslogtreecommitdiff
path: root/plugins/CryptoPP/src/base64.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-06-16 14:52:30 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-06-16 14:52:30 +0000
commit061047f67b695296a39a65df4a24916def1f67d5 (patch)
tree1b8b26385c66a0605e1a2688b23d68ea4558b32a /plugins/CryptoPP/src/base64.cpp
parent16883b99a9de3b600bb7cc0bd42317249e74f2df (diff)
custom (and also buggy) base64 processing code replaced with the core functions
git-svn-id: http://svn.miranda-ng.org/main/trunk@4987 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CryptoPP/src/base64.cpp')
-rw-r--r--plugins/CryptoPP/src/base64.cpp99
1 files changed, 12 insertions, 87 deletions
diff --git a/plugins/CryptoPP/src/base64.cpp b/plugins/CryptoPP/src/base64.cpp
index 92f23ba64b..8daa2bd598 100644
--- a/plugins/CryptoPP/src/base64.cpp
+++ b/plugins/CryptoPP/src/base64.cpp
@@ -1,97 +1,22 @@
#include "commonheaders.h"
-
-string base64encode(const string buf)
+string base64encode(const string& buf)
{
- string out;
- char *base64 = base64encode(buf.data(), buf.length());
- out.assign(base64);
- free(base64);
- return out;
-}
-
-
-char *base64encode(const char *inBuffer, const size_t count) {
-
- int srcIndex = 0, destIndex = 0, remainder = count % 3;
- char *outBuffer = (char *) malloc(count*2+1);
- BYTE *inBufferPtr = (BYTE *) inBuffer;
-
- while(srcIndex < count) {
- outBuffer[destIndex++] = encode64(inBufferPtr[srcIndex] >> 2);
- outBuffer[destIndex++] = encode64(((inBufferPtr[srcIndex] << 4) & 0x30) | ((inBufferPtr[srcIndex + 1] >> 4) & 0x0F));
- srcIndex++;
- outBuffer[destIndex++] = encode64(((inBufferPtr[srcIndex] << 2) & 0x3C) | ((inBufferPtr[srcIndex + 1] >> 6) & 0x03));
- srcIndex++;
- outBuffer[destIndex++] = encode64(inBufferPtr[srcIndex++] & 0x3F);
- }
-
- if (remainder == 2) {
- outBuffer[destIndex - 1] = BPAD;
- outBuffer[destIndex - 2] = encode64((inBufferPtr[srcIndex - 2] << 2) & 0x3C);
- }
- else if (remainder == 1) {
- outBuffer[destIndex - 2] = outBuffer[destIndex - 1] = BPAD;
- outBuffer[destIndex - 3] = encode64((inBufferPtr[srcIndex - 3] << 4) & 0x30);
- }
- destIndex -= (3 - remainder) % 3;
- outBuffer[destIndex] = '\0';
-
- return outBuffer;
+ return (char*)ptrA( mir_base64_encode((PBYTE)buf.data(), (unsigned)buf.length()));
}
-
-string base64decode(const string buf) {
- string out;
- size_t len = buf.length();
- char *plain = base64decode(buf.data(), &len);
- out.assign(plain,len);
- free(plain);
- return out;
-}
-
-
-string base64decode(const char *buf) {
- string out;
- size_t len = strlen(buf);
- char *plain = base64decode(buf, &len);
- out.assign(plain,len);
- free(plain);
- return out;
+string base64decode(const string& buf)
+{
+ unsigned len;
+ char *plain = (char*)mir_base64_decode(buf.data(), &len);
+ return (plain == NULL) ? string() : string(plain, len);
}
-
-char *base64decode(const char *inBuffer, size_t *count) {
-
- int srcIndex = 0, destIndex = 0;
- char *outBuffer = (char *) malloc(*count);
-
- while(srcIndex < *count) {
- BYTE c0, c1, c2 = 0, c3 = 0;
- const size_t delta = *count - srcIndex;
- c0 = decode64(inBuffer[srcIndex++]);
- c1 = decode64(inBuffer[srcIndex++]);
- if (delta > 2) {
- c2 = decode64(inBuffer[srcIndex++]);
- if (delta > 3)
- c3 = decode64(inBuffer[srcIndex++]);
- }
- if ((c0 | c1 | c2 | c3) == BERR) {
- free(outBuffer);
- return(NULL);
- }
- outBuffer[destIndex++] = (c0 << 2) | (c1 >> 4);
- if (delta > 2) {
- outBuffer[destIndex++] = (c1 << 4) | (c2 >> 2);
- if (delta > 3 )
- outBuffer[destIndex++] = (c2 << 6) | (c3);
- }
- }
- outBuffer[destIndex] = '\0';
- *count = destIndex;
-
- return outBuffer;
+string base64decode(const char *buf)
+{
+ unsigned len;
+ char *plain = (char*)mir_base64_decode(buf, &len);
+ return (plain == NULL) ? string() : string(plain, len);
}
-
// EOF