Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash-util: make the code work with boost-1.86 #200

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/lib/hash-util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <vector>

#include <boost/algorithm/hex.hpp>
#include <boost/algorithm/string.hpp>

/// compute TEng hash of `src` and return it as hex-encoded string
template <typename TEng, typename TSrc>
Expand All @@ -31,19 +30,18 @@ std::string hexHashStr(const TSrc &src)
TEng eng;
eng.process_bytes(src.data(), src.size());

// export the hash as an array of unsigned int
typename TEng::digest_type dst;
// export the hash as an array
using TDst = typename TEng::digest_type;
TDst dst;
eng.get_digest(dst);

// convert the hash to a vector of unsigned int
// convert the hash to a vector
static const size_t len = sizeof(dst) / sizeof(dst[0]);
const std::vector<unsigned> hash(dst, dst + len);
using TElem = typename std::remove_extent<TDst>::type;
const std::vector<TElem> hash(dst, dst + len);

// convert the hash to a hex string
std::string result;
boost::algorithm::hex(hash.begin(), hash.end(), back_inserter(result));

// convert uppercase letters to lowercase
boost::algorithm::to_lower(result);
boost::algorithm::hex_lower(hash.begin(), hash.end(), back_inserter(result));
return result;
}