зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1362449 - part 7 - make decode routines type-generic; r=erahm
The existing Base64URL code converts from `const char` to `uint8_t`. We're going to want versions that convert from character types to character types, so make the decode routines accept generic input and output types.
This commit is contained in:
Родитель
84d527a6e0
Коммит
602ae06673
|
@ -411,9 +411,9 @@ Base64Encode(const nsAString& aBinary, nsAString& aBase64)
|
||||||
return Base64EncodeHelper(aBinary, aBase64);
|
return Base64EncodeHelper(aBinary, aBase64);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Decoder>
|
template<typename T, typename U, typename Decoder>
|
||||||
static bool
|
static bool
|
||||||
Decode4to3(const char* aSrc, uint8_t* aDest, Decoder aToVal)
|
Decode4to3(const T* aSrc, U* aDest, Decoder aToVal)
|
||||||
{
|
{
|
||||||
uint8_t w, x, y, z;
|
uint8_t w, x, y, z;
|
||||||
if (!aToVal(aSrc[0], &w) ||
|
if (!aToVal(aSrc[0], &w) ||
|
||||||
|
@ -422,15 +422,15 @@ Decode4to3(const char* aSrc, uint8_t* aDest, Decoder aToVal)
|
||||||
!aToVal(aSrc[3], &z)) {
|
!aToVal(aSrc[3], &z)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
aDest[0] = w << 2 | x >> 4;
|
aDest[0] = U(w << 2 | x >> 4);
|
||||||
aDest[1] = x << 4 | y >> 2;
|
aDest[1] = U(x << 4 | y >> 2);
|
||||||
aDest[2] = y << 6 | z;
|
aDest[2] = U(y << 6 | z);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Decoder>
|
template<typename T, typename U, typename Decoder>
|
||||||
static bool
|
static bool
|
||||||
Decode3to2(const char* aSrc, uint8_t* aDest, Decoder aToVal)
|
Decode3to2(const T* aSrc, U* aDest, Decoder aToVal)
|
||||||
{
|
{
|
||||||
uint8_t w, x, y;
|
uint8_t w, x, y;
|
||||||
if (!aToVal(aSrc[0], &w) ||
|
if (!aToVal(aSrc[0], &w) ||
|
||||||
|
@ -438,21 +438,21 @@ Decode3to2(const char* aSrc, uint8_t* aDest, Decoder aToVal)
|
||||||
!aToVal(aSrc[2], &y)) {
|
!aToVal(aSrc[2], &y)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
aDest[0] = w << 2 | x >> 4;
|
aDest[0] = U(w << 2 | x >> 4);
|
||||||
aDest[1] = x << 4 | y >> 2;
|
aDest[1] = U(x << 4 | y >> 2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Decoder>
|
template<typename T, typename U, typename Decoder>
|
||||||
static bool
|
static bool
|
||||||
Decode2to1(const char* aSrc, uint8_t* aDest, Decoder aToVal)
|
Decode2to1(const T* aSrc, U* aDest, Decoder aToVal)
|
||||||
{
|
{
|
||||||
uint8_t w, x;
|
uint8_t w, x;
|
||||||
if (!aToVal(aSrc[0], &w) ||
|
if (!aToVal(aSrc[0], &w) ||
|
||||||
!aToVal(aSrc[1], &x)) {
|
!aToVal(aSrc[1], &x)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
aDest[0] = w << 2 | x >> 4;
|
aDest[0] = U(w << 2 | x >> 4);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче