28 static const char lookup[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
34 auto byte0 = *source++;
40 auto byte1 = *source++;
46 auto byte2 = *source++;
79 for (
int i = 0; i < 4; ++i)
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]));
134 MemoryOutputStream
m;
136 for (
int i = r.nextInt (400); --i >= 0;)
137 m.writeByte ((
char) r.nextInt (256));
139 return m.getMemoryBlock();
142 void runTest()
override
144 beginTest (
"Base64");
146 auto r = getRandom();
148 for (
int i = 1000; --i >= 0;)
152 MemoryOutputStream
out;
154 auto result =
out.getMemoryBlock();
160static Base64Tests base64Tests;
Holds a resizable array of primitive or copy-by-value objects.
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
Array()=default
Creates an empty array.
Writes data to an internal memory buffer, which grows as required.
The base class for streams that write data to some kind of destination.
A simple class for holding temporary references to a string literal or String.
const char * toRawUTF8() const
Returns a pointer to a UTF-8 version of this string.
This is a base class for classes that perform a unit test.
static bool convertToBase64(OutputStream &base64Result, const void *sourceData, size_t sourceDataSize)
Converts a binary block of data into a base-64 string.
static String toBase64(const void *sourceData, size_t sourceDataSize)
Converts a block of binary data to a base-64 string.
static bool convertFromBase64(OutputStream &binaryOutput, StringRef base64TextInput)
Converts a base-64 string back to its binary representation.