28 static const char lookup[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
29 auto* source =
static_cast<const uint8*
> (sourceData);
31 while (sourceDataSize > 0)
34 auto byte0 = *source++;
38 if (sourceDataSize > 1)
40 auto byte1 = *source++;
42 bits = (
byte1 & 0x0fu) << 2;
44 if (sourceDataSize > 2)
46 auto byte2 = *source++;
79 for (
int i = 0; i < 4; ++i)
81 auto c = (
uint32) s.getAndAdvance();
83 if (
c >=
'A' &&
c <=
'Z')
c -=
'A';
84 else if (
c >=
'a' &&
c <=
'z')
c -=
'a' - 26;
85 else if (
c >=
'0' &&
c <=
'9')
c += 52 -
'0';
86 else if (
c ==
'+')
c = 62;
87 else if (
c ==
'/')
c = 63;
88 else if (
c ==
'=') {
c = 64;
if (i <= 1)
return false; }
94 binaryOutput.writeByte ((
char) ((data[0] << 2) | (data[1] >> 4)));
98 binaryOutput.writeByte ((
char) ((data[1] << 4) | (data[2] >> 2)));
101 binaryOutput.writeByte ((
char) ((data[2] << 6) | data[3]));
131 :
UnitTest (
"Base64 class", UnitTestCategories::text)
136 MemoryOutputStream m;
138 for (
int i = r.nextInt (400); --i >= 0;)
139 m.writeByte ((
char) r.nextInt (256));
141 return m.getMemoryBlock();
144 void runTest()
override
146 beginTest (
"Base64");
148 auto r = getRandom();
150 for (
int i = 1000; --i >= 0;)
154 MemoryOutputStream
out;
156 auto result =
out.getMemoryBlock();
162static Base64Tests base64Tests;
const char * toRawUTF8() const
static bool convertToBase64(OutputStream &base64Result, const void *sourceData, size_t sourceDataSize)
static String toBase64(const void *sourceData, size_t sourceDataSize)
static bool convertFromBase64(OutputStream &binaryOutput, StringRef base64TextInput)