28 static const char lookup[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
34 auto byte0 = *source++;
40 auto byte1 = *source++;
42 bits = (
byte1 & 0x0fu) << 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]));
135 MemoryOutputStream m;
137 for (
int i = r.nextInt (400); --i >= 0;)
138 m.writeByte ((
char) r.nextInt (256));
140 return m.getMemoryBlock();
143 void runTest()
override
145 beginTest (
"Base64");
147 auto r = getRandom();
149 for (
int i = 1000; --i >= 0;)
153 MemoryOutputStream out;
155 auto result = out.getMemoryBlock();
Writes data to an internal memory buffer, which grows as required.
String toString() const
Attempts to detect the encoding of the data and convert it to a string.
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.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
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.