Delikatne zmiany w strukturze PAK. signed char zamiast short

This commit is contained in:
yanczi 2025-12-12 10:12:22 +01:00
parent b4f6d3a85a
commit a84a69cbd6
12 changed files with 330 additions and 73 deletions

View file

@ -67,8 +67,8 @@ void EncryptionManager::generateKeys()
void EncryptionManager::saveKey(const std::string& path, bool hpp)
{
const int sig = SIGNATURE_KEY_FILE;
const short ver = VERSION;
const std::string sig = SIGNATURE_KEY_FILE;
const int8_t ver = VERSION;
// Wygeneruj time stamp
std::time_t now = std::time(nullptr);
@ -84,7 +84,7 @@ void EncryptionManager::saveKey(const std::string& path, bool hpp)
std::ofstream file(path + ".key", std::ios::binary);
if (!file) { std::cout << "Failed to save encryption key to file" << std::endl; }
file.write(reinterpret_cast<const char*>(&sig), sizeof(sig));
file.write(sig.data(), sig.length());
file.write(reinterpret_cast<const char*>(&ver), sizeof(ver));
file.write(reinterpret_cast<const char*>(&time), sizeof(time));
file.write(reinterpret_cast<const char*>(keyVec.data()), keyVec.size());
@ -138,16 +138,17 @@ void EncryptionManager::loadKey(const std::string& path)
{
std::ifstream file(path + ".key", std::ios::binary);
int sig;
short ver;
const std::string signature = SIGNATURE_KEY_FILE;
std::vector<char> sig(signature.size());
int8_t ver;
int time;
// Wczytaj
file.read(reinterpret_cast<char*>(&sig), sizeof(sig));
file.read(sig.data(), sig.size());
file.read(reinterpret_cast<char*>(&ver), sizeof(ver));
// SprawdŸ czy plik klucza jest poprawny
if (sig != SIGNATURE_KEY_FILE || ver != VERSION)
if (std::string(sig.begin(), sig.end()) != signature || ver != VERSION)
{
throw std::runtime_error("Invalid key file!");
}