Skip to content

Commit a7d0c6b

Browse files
committed
Make the codebase compatible with Boost 1.86.
1 parent a0c5a15 commit a7d0c6b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

util/include/util/hash.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ inline std::string sha1Hash(const std::string& data_)
3636
using namespace boost::uuids::detail;
3737

3838
sha1 hasher;
39-
unsigned int digest[5];
39+
boost::uuids::detail::sha1::digest_type digest;
4040

4141
hasher.process_bytes(data_.c_str(), data_.size());
4242
hasher.get_digest(digest);
@@ -46,8 +46,23 @@ inline std::string sha1Hash(const std::string& data_)
4646
ss.width(8);
4747
ss.fill('0');
4848

49+
// To ensure correct output, especially for newer Boost versions where digest might be treated as 20 bytes,
50+
// we explicitly cast the relevant 4 bytes into a uint32_t.
51+
// For older Boost, digest[i] is already a uint32_t.
52+
// For newer Boost, digest is a uint8_t[20]. We need to reconstruct the 32-bit values.
53+
#if BOOST_VERSION >= 108600 /* 1.86.0 */
54+
for (int i = 0; i < 5; ++i)
55+
{
56+
uint32_t part = (static_cast<uint32_t>(digest[i * 4]) << 24) |
57+
(static_cast<uint32_t>(digest[i * 4 + 1]) << 16) |
58+
(static_cast<uint32_t>(digest[i * 4 + 2]) << 8) |
59+
static_cast<uint32_t>(digest[i * 4 + 3]);
60+
ss << part;
61+
}
62+
#else
4963
for (int i = 0; i < 5; ++i)
5064
ss << digest[i];
65+
#endif
5166

5267
return ss.str();
5368
}

0 commit comments

Comments
 (0)