Core/Cryptography: Move the SHA1 calculate helper to the SHA1 header
This commit is contained in:
1 parent
8289ed64d6
commit
7a827fe435
4 files changed
+15
-15
No files matched your search
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "SHA1.h"
|
#include "SHA1.h"
|
||||||
#include "BigNumber.h"
|
#include "BigNumber.h"
|
||||||
|
#include "Util.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
@@ -67,3 +68,10 @@ void SHA1Hash::Finalize(void)
|
|||||||
SHA1_Final(mDigest, &mC);
|
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;
|
SHA_CTX mC;
|
||||||
uint8 mDigest[SHA_DIGEST_LENGTH];
|
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 "UpdateFetcher.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "SHA1.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -25,7 +26,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <openssl/sha.h>
|
|
||||||
|
|
||||||
using namespace boost::filesystem;
|
using namespace boost::filesystem;
|
||||||
|
|
||||||
@@ -209,9 +209,8 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate hash
|
// Calculate a Sha1 hash based on query content.
|
||||||
std::string const hash =
|
std::string const hash = CalculateSHA1Hash(ReadSQLUpdate(availableQuery.first));
|
||||||
CalculateHash(ReadSQLUpdate(availableQuery.first));
|
|
||||||
|
|
||||||
UpdateMode mode = MODE_APPLY;
|
UpdateMode mode = MODE_APPLY;
|
||||||
|
|
||||||
@@ -334,15 +333,6 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
|
|||||||
return UpdateResult(importedUpdates, countRecentUpdates, countArchivedUpdates);
|
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
|
uint32 UpdateFetcher::Apply(Path const& path) const
|
||||||
{
|
{
|
||||||
using Time = std::chrono::high_resolution_clock;
|
using Time = std::chrono::high_resolution_clock;
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ private:
|
|||||||
AppliedFileStorage ReceiveAppliedFiles() const;
|
AppliedFileStorage ReceiveAppliedFiles() const;
|
||||||
|
|
||||||
std::string ReadSQLUpdate(Path const& file) const;
|
std::string ReadSQLUpdate(Path const& file) const;
|
||||||
std::string CalculateHash(std::string const& query) const;
|
|
||||||
|
|
||||||
uint32 Apply(Path const& path) const;
|
uint32 Apply(Path const& path) const;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user