[General]: Syntax cleanup in utils (#1010)

This commit is contained in:
Edo 2023-05-04 19:18:35 +01:00 committed by GitHub
parent e018f6c8fd
commit 00bc10ac3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,7 @@ namespace Utils
pos += sprintf_s(&buffer[pos], sizeof(buffer) - pos, "%X", ~timeGetTime() ^ GenerateInt());
pos += sprintf_s(&buffer[pos], sizeof(buffer) - pos, "%X", GenerateInt());
return std::string(buffer, static_cast<std::size_t>(pos));
return std::string{ buffer, static_cast<std::size_t>(pos) };
}
std::uint32_t Rand::GenerateInt()
@ -62,13 +62,13 @@ namespace Utils
if (!key.isValid()) return {};
std::uint8_t buffer[512];
DWORD length = sizeof(buffer);
unsigned long length = sizeof(buffer);
ltc_mp = ltm_desc;
register_prng(&sprng_desc);
ecc_sign_hash(reinterpret_cast<const std::uint8_t*>(message.data()), message.size(), buffer, &length, nullptr, find_prng("sprng"), key.getKeyPtr());
return {reinterpret_cast<char*>(buffer), length};
return std::string{ reinterpret_cast<char*>(buffer), length };
}
bool ECC::VerifyMessage(Key key, const std::string& message, const std::string& signature)
@ -78,7 +78,9 @@ namespace Utils
ltc_mp = ltm_desc;
int result = 0;
return (ecc_verify_hash(reinterpret_cast<const std::uint8_t*>(signature.data()), signature.size(), reinterpret_cast<const std::uint8_t*>(message.data()), message.size(), &result, key.getKeyPtr()) == CRYPT_OK && result != 0);
return (ecc_verify_hash(reinterpret_cast<const std::uint8_t*>(signature.data()), signature.size(),
reinterpret_cast<const std::uint8_t*>(message.data()), message.size(),
&result, key.getKeyPtr()) == CRYPT_OK && result != 0);
}
#pragma endregion
@ -104,7 +106,7 @@ namespace Utils
if (!key.isValid()) return {};
std::uint8_t buffer[512];
DWORD length = sizeof(buffer);
unsigned long length = sizeof(buffer);
register_prng(&sprng_desc);
register_hash(&sha1_desc);
@ -113,7 +115,7 @@ namespace Utils
rsa_sign_hash(reinterpret_cast<const std::uint8_t*>(message.data()), message.size(), buffer, &length, NULL, find_prng("sprng"), find_hash("sha1"), 0, key.getKeyPtr());
return {reinterpret_cast<char*>(buffer), length};
return std::string{ reinterpret_cast<char*>(buffer), length };
}
bool RSA::VerifyMessage(Key key, const std::string& message, const std::string& signature)
@ -185,7 +187,7 @@ namespace Utils
tiger_process(&state, data, length);
tiger_done(&state, buffer);
std::string hash(reinterpret_cast<char*>(buffer), sizeof(buffer));
std::string hash{ reinterpret_cast<char*>(buffer), sizeof(buffer) };
if (!hex) return hash;
return String::DumpHex(hash, {});
@ -209,7 +211,7 @@ namespace Utils
sha1_process(&state, data, length);
sha1_done(&state, buffer);
std::string hash(reinterpret_cast<char*>(buffer), sizeof(buffer));
std::string hash{ reinterpret_cast<char*>(buffer), sizeof(buffer) };
if (!hex) return hash;
return String::DumpHex(hash, {});
@ -233,7 +235,7 @@ namespace Utils
sha256_process(&state, data, length);
sha256_done(&state, buffer);
std::string hash(reinterpret_cast<char*>(buffer), sizeof(buffer));
std::string hash{ reinterpret_cast<char*>(buffer), sizeof(buffer) };
if (!hex) return hash;
return String::DumpHex(hash, {});
@ -257,7 +259,7 @@ namespace Utils
sha512_process(&state, data, length);
sha512_done(&state, buffer);
std::string hash(reinterpret_cast<char*>(buffer), sizeof(buffer));
std::string hash{ reinterpret_cast<char*>(buffer), sizeof(buffer) };
if (!hex) return hash;
return String::DumpHex(hash, {});