mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Cryptography: Move the SHA1 calculate helper to the SHA1 header
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "SHA1.h"
|
||||
#include "BigNumber.h"
|
||||
#include "Util.h"
|
||||
#include <cstring>
|
||||
#include <stdarg.h>
|
||||
|
||||
@@ -67,3 +68,10 @@ void SHA1Hash::Finalize(void)
|
||||
SHA1_Final(mDigest, &mC);
|
||||
}
|
||||
|
||||
std::string CalculateSHA1Hash(std::string const& content)
|
||||
{
|
||||
unsigned char digest[SHA_DIGEST_LENGTH];
|
||||
SHA1((unsigned char*)content.c_str(), content.length(), (unsigned char*)&digest);
|
||||
|
||||
return ByteArrayToHexStr(digest, SHA_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
@@ -46,5 +46,8 @@ class TC_COMMON_API SHA1Hash
|
||||
SHA_CTX mC;
|
||||
uint8 mDigest[SHA_DIGEST_LENGTH];
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Returns the SHA1 hash of the given content as hex string.
|
||||
TC_COMMON_API std::string CalculateSHA1Hash(std::string const& content);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "UpdateFetcher.h"
|
||||
#include "Log.h"
|
||||
#include "Util.h"
|
||||
#include "SHA1.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
@@ -25,7 +26,6 @@
|
||||
#include <sstream>
|
||||
#include <exception>
|
||||
#include <unordered_map>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
|
||||
@@ -209,9 +209,8 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate hash
|
||||
std::string const hash =
|
||||
CalculateHash(ReadSQLUpdate(availableQuery.first));
|
||||
// Calculate a Sha1 hash based on query content.
|
||||
std::string const hash = CalculateSHA1Hash(ReadSQLUpdate(availableQuery.first));
|
||||
|
||||
UpdateMode mode = MODE_APPLY;
|
||||
|
||||
@@ -334,15 +333,6 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
|
||||
return UpdateResult(importedUpdates, countRecentUpdates, countArchivedUpdates);
|
||||
}
|
||||
|
||||
std::string UpdateFetcher::CalculateHash(std::string const& query) const
|
||||
{
|
||||
// Calculate a Sha1 hash based on query content.
|
||||
unsigned char digest[SHA_DIGEST_LENGTH];
|
||||
SHA1((unsigned char*)query.c_str(), query.length(), (unsigned char*)&digest);
|
||||
|
||||
return ByteArrayToHexStr(digest, SHA_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
uint32 UpdateFetcher::Apply(Path const& path) const
|
||||
{
|
||||
using Time = std::chrono::high_resolution_clock;
|
||||
|
||||
@@ -112,7 +112,6 @@ private:
|
||||
AppliedFileStorage ReceiveAppliedFiles() const;
|
||||
|
||||
std::string ReadSQLUpdate(Path const& file) const;
|
||||
std::string CalculateHash(std::string const& query) const;
|
||||
|
||||
uint32 Apply(Path const& path) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user