File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments