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_)
36
36
using namespace boost ::uuids::detail;
37
37
38
38
sha1 hasher;
39
- unsigned int digest[ 5 ] ;
39
+ boost::uuids::detail::sha1::digest_type digest;
40
40
41
41
hasher.process_bytes (data_.c_str (), data_.size ());
42
42
hasher.get_digest (digest);
@@ -46,8 +46,23 @@ inline std::string sha1Hash(const std::string& data_)
46
46
ss.width (8 );
47
47
ss.fill (' 0' );
48
48
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
49
63
for (int i = 0 ; i < 5 ; ++i)
50
64
ss << digest[i];
65
+ #endif
51
66
52
67
return ss.str ();
53
68
}
You can’t perform that action at this time.
0 commit comments