--- a/xpcom/io/Base64.cpp
+++ b/xpcom/io/Base64.cpp
@@ -239,17 +239,19 @@ EncodeInputStream(nsIInputStream* aInput
*aDest.EndWriting() = '\0';
}
return NS_OK;
}
// Maps an encoded character to a value in the Base64 alphabet, per
// RFC 4648, Table 1. Invalid input characters map to UINT8_MAX.
+
static const uint8_t kBase64DecodeTable[] = {
+// clang-format off
/* 0 */ 255, 255, 255, 255, 255, 255, 255, 255,
/* 8 */ 255, 255, 255, 255, 255, 255, 255, 255,
/* 16 */ 255, 255, 255, 255, 255, 255, 255, 255,
/* 24 */ 255, 255, 255, 255, 255, 255, 255, 255,
/* 32 */ 255, 255, 255, 255, 255, 255, 255, 255,
/* 40 */ 255, 255, 255,
62 /* + */,
255, 255, 255,
@@ -262,16 +264,17 @@ static const uint8_t kBase64DecodeTable[
/* 72 */ 7, 8, 9, 10, 11, 12, 13, 14,
/* 80 */ 15, 16, 17, 18, 19, 20, 21, 22,
/* 88 */ 23, 24, 25, 255, 255, 255, 255, 255,
/* 96 */ 255, /* a - z */ 26, 27, 28, 29, 30, 31, 32,
/* 104 */ 33, 34, 35, 36, 37, 38, 39, 40,
/* 112 */ 41, 42, 43, 44, 45, 46, 47, 48,
/* 120 */ 49, 50, 51, 255, 255, 255, 255, 255,
};
+// clang-format on
template<typename T>
MOZ_MUST_USE bool
Base64CharToValue(T aChar, uint8_t* aValue)
{
static const size_t mask = 0x7f;
static_assert((mask + 1) == sizeof(kBase64DecodeTable)/sizeof(kBase64DecodeTable[0]),
"wrong mask");
@@ -286,16 +289,17 @@ Base64CharToValue(T aChar, uint8_t* aVal
}
static const char kBase64URLAlphabet[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
// Maps an encoded character to a value in the Base64 URL alphabet, per
// RFC 4648, Table 2. Invalid input characters map to UINT8_MAX.
static const uint8_t kBase64URLDecodeTable[] = {
+// clang-format off
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255,
62 /* - */,
255, 255,
@@ -305,16 +309,17 @@ static const uint8_t kBase64URLDecodeTab
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, /* A - Z */
255, 255, 255, 255,
63 /* _ */,
255,
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, /* a - z */
255, 255, 255, 255,
};
+// clang-format on
bool
Base64URLCharToValue(char aChar, uint8_t* aValue) {
uint8_t index = static_cast<uint8_t>(aChar);
*aValue = kBase64URLDecodeTable[index & 0x7f];
return (*aValue != 255) && !(index & ~0x7f);
}