Skip to content
Snippets Groups Projects
Commit 27263219 authored by Cinder's avatar Cinder
Browse files

Transplant apr's base64 decode binary function with modification because...

Transplant apr's base64 decode binary function with modification because vivox's servers are doing something fishy with their ascii encoding and openssl just cannot deal with it.
parent 76a347ed
No related branches found
No related tags found
No related merge requests found
......@@ -104,3 +104,75 @@ size_t LLBase64::requiredDecryptionSpace(const std::string& str)
return len * 0.75 - padding;
}
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
static const U8 apr_pr2six[256] =
{
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
64, 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, 64, 64, 64, 64, 64,
64, 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, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
};
size_t LLBase64::apr_base64_decode_binary(U8 *bufplain, const char* bufcoded)
{
size_t nbytesdecoded, nprbytes;
const U8 *bufin;
U8 *bufout;
bufin = (const U8*) bufcoded;
while (apr_pr2six[*(bufin++)] <= 63);
nprbytes = (bufin - (const U8 *) bufcoded) - 1;
nbytesdecoded = (((size_t)nprbytes + 3) / 4) * 3;
bufout = (U8 *) bufplain;
bufin = (const U8 *) bufcoded;
while (nprbytes > 4) {
*(bufout++) = (U8) (apr_pr2six[*bufin] << 2 | apr_pr2six[bufin[1]] >> 4);
*(bufout++) = (U8) (apr_pr2six[bufin[1]] << 4 | apr_pr2six[bufin[2]] >> 2);
*(bufout++) = (U8) (apr_pr2six[bufin[2]] << 6 | apr_pr2six[bufin[3]]);
bufin += 4;
nprbytes -= 4;
}
/* Note: (nprbytes == 1) would be an error, so just ingore that case */
if (nprbytes > 1) {
*(bufout++) = (U8) (apr_pr2six[*bufin] << 2 | apr_pr2six[bufin[1]] >> 4);
}
if (nprbytes > 2) {
*(bufout++) = (U8) (apr_pr2six[bufin[1]] << 4 | apr_pr2six[bufin[2]] >> 2);
}
if (nprbytes > 3) {
*(bufout++) = (U8) (apr_pr2six[bufin[2]] << 6 | apr_pr2six[bufin[3]]);
}
nbytesdecoded -= (4 - (size_t)nprbytes) & 3;
return nbytesdecoded;
}
......@@ -36,6 +36,9 @@ public:
static size_t decode(const std::string& input, U8 * buffer, size_t buffer_size);
static std::string decode(const std::string& input);
static size_t requiredDecryptionSpace(const std::string& str);
// *HACK: Special case because of OpenSSL ASCII/EBCDIC issues
static size_t apr_base64_decode_binary(U8 *bufplain, const char* bufcoded);
};
#endif
......@@ -64,9 +64,6 @@
#include "llviewernetwork.h"
#include "llnotificationsutil.h"
// for base64 decoding
#include "apr_base64.h"
#define USE_SESSION_GROUPS 0
extern LLMenuBarGL* gMenuBarView;
......@@ -4479,8 +4476,8 @@ bool LLVivoxVoiceClient::IDFromName(const std::string inName, LLUUID &uuid)
LLStringUtil::replaceChar(temp, '-', '+');
LLStringUtil::replaceChar(temp, '_', '/');
U8 rawuuid[UUID_BYTES + 1];
int len = apr_base64_decode_binary(rawuuid, temp.c_str() + 1);
U8 rawuuid[UUID_BYTES + 1];
int len = LLBase64::apr_base64_decode_binary(rawuuid, temp.c_str() + 1);
if(len == UUID_BYTES)
{
// The decode succeeded. Stuff the bits into the result's UUID
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment