Browse Source

Fix Base64 size calculation behavior to always return the actual conversion size

Michael Hansen 13 years ago
parent
commit
dfebad4a54
  1. 16
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp
  2. 2
      Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBase64.cpp
  3. 9
      Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBase64.h

16
Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp

@ -1132,7 +1132,7 @@ PF_CONSOLE_CMD(
"Set the Auth Server N key"
) {
int baseLength = hsStrlen((const char *)params[0]);
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength)) {
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) {
PrintStringF(PrintString, "Invalid key: should be exactly %u bytes",
kNetDiffieHellmanKeyBits / 8);
return;
@ -1150,7 +1150,7 @@ PF_CONSOLE_CMD(
"Set the Auth Server X key"
) {
int baseLength = hsStrlen((const char *)params[0]);
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength)) {
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) {
PrintStringF(PrintString, "Invalid key: should be exactly %u bytes",
kNetDiffieHellmanKeyBits / 8);
return;
@ -1185,7 +1185,7 @@ PF_CONSOLE_CMD(
"Set the Csr Server N key"
) {
int baseLength = hsStrlen((const char *)params[0]);
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength)) {
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) {
PrintStringF(PrintString, "Invalid key: should be exactly %u bytes",
kNetDiffieHellmanKeyBits / 8);
return;
@ -1203,7 +1203,7 @@ PF_CONSOLE_CMD(
"Set the Csr Server X key"
) {
int baseLength = hsStrlen((const char *)params[0]);
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength)) {
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) {
PrintStringF(PrintString, "Invalid key: should be exactly %u bytes",
kNetDiffieHellmanKeyBits / 8);
return;
@ -1226,7 +1226,7 @@ PF_CONSOLE_CMD(
"Set the Game Server N key"
) {
int baseLength = hsStrlen((const char *)params[0]);
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength)) {
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) {
PrintStringF(PrintString, "Invalid key: should be exactly %u bytes",
kNetDiffieHellmanKeyBits / 8);
return;
@ -1244,7 +1244,7 @@ PF_CONSOLE_CMD(
"Set the Game Server X key"
) {
int baseLength = hsStrlen((const char *)params[0]);
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength)) {
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) {
PrintStringF(PrintString, "Invalid key: should be exactly %u bytes",
kNetDiffieHellmanKeyBits / 8);
return;
@ -1279,7 +1279,7 @@ PF_CONSOLE_CMD(
"Set the GateKeeper Server N key"
) {
int baseLength = hsStrlen((const char *)params[0]);
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength)) {
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) {
PrintStringF(PrintString, "Invalid key: should be exactly %u bytes",
kNetDiffieHellmanKeyBits / 8);
return;
@ -1297,7 +1297,7 @@ PF_CONSOLE_CMD(
"Set the GateKeeper Server X key"
) {
int baseLength = hsStrlen((const char *)params[0]);
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength)) {
if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) {
PrintStringF(PrintString, "Invalid key: should be exactly %u bytes",
kNetDiffieHellmanKeyBits / 8);
return;

2
Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBase64.cpp

@ -132,7 +132,7 @@ unsigned Base64Decode (
byte * dstData
) {
ASSERT(srcData);
ASSERT(dstChars >= Base64DecodeSize(srcChars));
ASSERT(dstChars >= Base64DecodeSize(srcChars, srcData));
ASSERT(dstData);
const byte * dstBase = dstData;

9
Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBase64.h

@ -46,7 +46,8 @@ const unsigned kBase64EncodeBlock = 4;
const unsigned kBase64EncodeMultiple = 3;
inline unsigned Base64EncodeSize (unsigned srcChars) {
return srcChars * kBase64EncodeBlock / kBase64EncodeMultiple + kBase64EncodeBlock;
return (srcChars + kBase64EncodeMultiple - 1) / kBase64EncodeMultiple
* kBase64EncodeBlock;
}
unsigned Base64Encode (
unsigned srcChars,
@ -55,8 +56,10 @@ unsigned Base64Encode (
char * dstData
);
inline unsigned Base64DecodeSize (unsigned srcChars) {
return srcChars * kBase64EncodeMultiple / kBase64EncodeBlock + kBase64EncodeMultiple;
inline unsigned Base64DecodeSize (unsigned srcChars, const char srcData[]) {
return srcChars * kBase64EncodeMultiple / kBase64EncodeBlock
- ((srcChars >= 1 && srcData[srcChars - 1] == '=') ? 1 : 0)
- ((srcChars >= 2 && srcData[srcChars - 2] == '=') ? 1 : 0);
}
unsigned Base64Decode (
unsigned srcChars,

Loading…
Cancel
Save