mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Reformat per new coding guidelines.
Change-Id: Ib0e5d3a6fabe6db414d72b334ca7a7f33bc5726b
This commit is contained in:
@@ -64,12 +64,12 @@
|
||||
|
||||
#include "nt_base64.h"
|
||||
|
||||
namespace NtImpl {
|
||||
namespace ntimpl {
|
||||
|
||||
/* aaaack but it's fast and const should make it shared text page. */
|
||||
// aaaack but it's fast and const should make it shared text page.
|
||||
static const unsigned char pr2six[256] =
|
||||
{
|
||||
/* ASCII table */
|
||||
// ASCII table
|
||||
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,
|
||||
@@ -88,106 +88,88 @@ static const unsigned char pr2six[256] =
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
|
||||
};
|
||||
|
||||
std::size_t
|
||||
base64decode_len(const char *bufcoded)
|
||||
{
|
||||
const unsigned char *bufin = (const unsigned char *) bufcoded;
|
||||
while (pr2six[*(bufin++)] <= 63) {}
|
||||
std::size_t base64decode_len(const char *bufcoded) {
|
||||
const unsigned char *bufin = (const unsigned char *)bufcoded;
|
||||
while (pr2six[*(bufin++)] <= 63) {
|
||||
}
|
||||
|
||||
std::size_t nprbytes = (bufin - (const unsigned char *) bufcoded) - 1;
|
||||
std::size_t nbytesdecoded = ((nprbytes + 3) / 4) * 3;
|
||||
std::size_t nprbytes = (bufin - (const unsigned char *)bufcoded) - 1;
|
||||
std::size_t nbytesdecoded = ((nprbytes + 3) / 4) * 3;
|
||||
|
||||
return nbytesdecoded + 1;
|
||||
return nbytesdecoded + 1;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
base64decode(char *bufplain, const char *bufcoded)
|
||||
{
|
||||
const unsigned char *bufin = (const unsigned char *) bufcoded;
|
||||
while (pr2six[*(bufin++)] <= 63) {}
|
||||
std::size_t nprbytes = (bufin - (const unsigned char *) bufcoded) - 1;
|
||||
std::size_t nbytesdecoded = ((nprbytes + 3) / 4) * 3;
|
||||
std::size_t base64decode(char *bufplain, const char *bufcoded) {
|
||||
const unsigned char *bufin = (const unsigned char *)bufcoded;
|
||||
while (pr2six[*(bufin++)] <= 63) {
|
||||
}
|
||||
std::size_t nprbytes = (bufin - (const unsigned char *)bufcoded) - 1;
|
||||
std::size_t nbytesdecoded = ((nprbytes + 3) / 4) * 3;
|
||||
|
||||
unsigned char *bufout = (unsigned char *) bufplain;
|
||||
bufin = (const unsigned char *) bufcoded;
|
||||
unsigned char *bufout = (unsigned char *)bufplain;
|
||||
bufin = (const unsigned char *)bufcoded;
|
||||
|
||||
while (nprbytes > 4)
|
||||
{
|
||||
*(bufout++) =
|
||||
(unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
|
||||
*(bufout++) =
|
||||
(unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
|
||||
*(bufout++) =
|
||||
(unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
|
||||
bufin += 4;
|
||||
nprbytes -= 4;
|
||||
}
|
||||
while (nprbytes > 4) {
|
||||
*(bufout++) = (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
|
||||
*(bufout++) =
|
||||
(unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
|
||||
*(bufout++) = (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
|
||||
bufin += 4;
|
||||
nprbytes -= 4;
|
||||
}
|
||||
|
||||
/* Note: (nprbytes == 1) would be an error, so just ingore that case */
|
||||
if (nprbytes > 1)
|
||||
{
|
||||
*(bufout++) =
|
||||
(unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
|
||||
}
|
||||
if (nprbytes > 2)
|
||||
{
|
||||
*(bufout++) =
|
||||
(unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
|
||||
}
|
||||
if (nprbytes > 3)
|
||||
{
|
||||
*(bufout++) =
|
||||
(unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
|
||||
}
|
||||
// Note: (nprbytes == 1) would be an error, so just ingore that case
|
||||
if (nprbytes > 1) {
|
||||
*(bufout++) = (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
|
||||
}
|
||||
if (nprbytes > 2) {
|
||||
*(bufout++) =
|
||||
(unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
|
||||
}
|
||||
if (nprbytes > 3) {
|
||||
*(bufout++) = (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
|
||||
}
|
||||
|
||||
*(bufout++) = '\0';
|
||||
nbytesdecoded -= (4 - nprbytes) & 3;
|
||||
return nbytesdecoded;
|
||||
*(bufout++) = '\0';
|
||||
nbytesdecoded -= (4 - nprbytes) & 3;
|
||||
return nbytesdecoded;
|
||||
}
|
||||
|
||||
static const char basis_64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
std::size_t
|
||||
base64encode_len(std::size_t len)
|
||||
{
|
||||
return ((len + 2) / 3 * 4) + 1;
|
||||
std::size_t base64encode_len(std::size_t len) {
|
||||
return ((len + 2) / 3 * 4) + 1;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
base64encode(char *encoded, const unsigned char *string, std::size_t len)
|
||||
{
|
||||
std::size_t i;
|
||||
char *p = encoded;
|
||||
std::size_t base64encode(char *encoded, const unsigned char *string,
|
||||
std::size_t len) {
|
||||
std::size_t i;
|
||||
char *p = encoded;
|
||||
|
||||
for (i = 0; i < len - 2; i += 3)
|
||||
{
|
||||
*p++ = basis_64[(string[i] >> 2) & 0x3F];
|
||||
*p++ = basis_64[((string[i] & 0x3) << 4) |
|
||||
((int) (string[i + 1] & 0xF0) >> 4)];
|
||||
*p++ = basis_64[((string[i + 1] & 0xF) << 2) |
|
||||
((int) (string[i + 2] & 0xC0) >> 6)];
|
||||
*p++ = basis_64[string[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < len)
|
||||
{
|
||||
*p++ = basis_64[(string[i] >> 2) & 0x3F];
|
||||
if (i == (len - 1))
|
||||
{
|
||||
*p++ = basis_64[((string[i] & 0x3) << 4)];
|
||||
*p++ = '=';
|
||||
}
|
||||
else
|
||||
{
|
||||
*p++ = basis_64[((string[i] & 0x3) << 4) |
|
||||
((int) (string[i + 1] & 0xF0) >> 4)];
|
||||
*p++ = basis_64[((string[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*p++ = '=';
|
||||
for (i = 0; i < len - 2; i += 3) {
|
||||
*p++ = basis_64[(string[i] >> 2) & 0x3F];
|
||||
*p++ =
|
||||
basis_64[((string[i] & 0x3) << 4) | ((int)(string[i + 1] & 0xF0) >> 4)];
|
||||
*p++ = basis_64[((string[i + 1] & 0xF) << 2) |
|
||||
((int)(string[i + 2] & 0xC0) >> 6)];
|
||||
*p++ = basis_64[string[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < len) {
|
||||
*p++ = basis_64[(string[i] >> 2) & 0x3F];
|
||||
if (i == (len - 1)) {
|
||||
*p++ = basis_64[((string[i] & 0x3) << 4)];
|
||||
*p++ = '=';
|
||||
} else {
|
||||
*p++ = basis_64[((string[i] & 0x3) << 4) |
|
||||
((int)(string[i + 1] & 0xF0) >> 4)];
|
||||
*p++ = basis_64[((string[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*p++ = '=';
|
||||
}
|
||||
|
||||
*p++ = '\0';
|
||||
return p - encoded;
|
||||
*p++ = '\0';
|
||||
return p - encoded;
|
||||
}
|
||||
|
||||
} // namespace NtImpl
|
||||
} // namespace ntimpl
|
||||
|
||||
Reference in New Issue
Block a user