Implement token class according to https://github.com/IW4x/iw4x-client-node/wikis/technical-information#incrementing-the-token
This commit is contained in:
parent
307a5367da
commit
99af8fbae7
@ -156,4 +156,17 @@ namespace Components
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Auth::UnitTest()
|
||||
{
|
||||
/*
|
||||
Utils::Cryptography::Token t;
|
||||
for (int i = 0; i < 1'000'000; ++i, ++t)
|
||||
{
|
||||
printf("%s\n", Utils::DumpHex(t.ToString()).data());
|
||||
}
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ namespace Components
|
||||
Auth();
|
||||
~Auth();
|
||||
const char* GetName() { return "Auth"; };
|
||||
bool UnitTest();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -2,6 +2,67 @@ namespace Utils
|
||||
{
|
||||
namespace Cryptography
|
||||
{
|
||||
class Token
|
||||
{
|
||||
public:
|
||||
Token() { this->TokenString.clear(); };
|
||||
Token(std::string token) : TokenString(token.begin(), token.end()) { };
|
||||
Token(std::basic_string<uint8_t> token) : TokenString(token.begin(), token.end()) { };
|
||||
|
||||
Token& operator++ ()
|
||||
{
|
||||
if (this->TokenString.empty())
|
||||
{
|
||||
this->TokenString.append(reinterpret_cast<uint8_t*>("\0"), 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = (this->TokenString.size() - 1); i >= 0; i--)
|
||||
{
|
||||
if (this->TokenString[i] == 0xFF)
|
||||
{
|
||||
this->TokenString[i] = 0;
|
||||
|
||||
if (!i)
|
||||
{
|
||||
// Prepend here, as /dev/urandom says so ;) https://github.com/IW4x/iw4x-client-node/wikis/technical-information#incrementing-the-token
|
||||
this->TokenString = std::basic_string<uint8_t>(reinterpret_cast<uint8_t*>("\0"), 1) + this->TokenString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->TokenString[i]++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Token operator++ (int)
|
||||
{
|
||||
Token result = *this;
|
||||
++(*this);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ToString()
|
||||
{
|
||||
auto str = this->ToUnsignedString();
|
||||
return std::string(str.begin(), str.end());
|
||||
}
|
||||
|
||||
std::basic_string<uint8_t> ToUnsignedString()
|
||||
{
|
||||
return this->TokenString;
|
||||
}
|
||||
|
||||
private:
|
||||
std::basic_string<uint8_t> TokenString;
|
||||
};
|
||||
|
||||
class Rand
|
||||
{
|
||||
public:
|
||||
|
@ -30,6 +30,23 @@ namespace Utils
|
||||
return (strstr(haystack.data(), needle.data()) == (haystack.data() + haystack.size() - needle.size()));
|
||||
}
|
||||
|
||||
std::string DumpHex(std::string data)
|
||||
{
|
||||
std::string result;
|
||||
|
||||
for (unsigned int i = 0; i < data.size(); ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
result.append(" ");
|
||||
}
|
||||
|
||||
result.append(Utils::VA("%02X", data[i] & 0xFF));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Complementary function for memset, which checks if a memory is set
|
||||
bool MemIsSet(void* mem, char chr, size_t length)
|
||||
{
|
||||
|
@ -20,6 +20,8 @@ namespace Utils
|
||||
void WriteFile(std::string file, std::string data);
|
||||
std::string ReadFile(std::string file);
|
||||
|
||||
std::string DumpHex(std::string data);
|
||||
|
||||
bool MemIsSet(void* mem, char chr, size_t length);
|
||||
|
||||
class InfoString
|
||||
|
Loading…
Reference in New Issue
Block a user