Skip to content

Commit

Permalink
promote compatability with Boost <1.86.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dbear496 committed Sep 14, 2024
1 parent ad93c18 commit 4f4cc16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/filters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void anonymize_posts::render_commodity(amount_t& amt)
void anonymize_posts::operator()(post_t& post)
{
boost::uuids::detail::sha1 sha;
unsigned char message_digest[20];
boost::uuids::detail::sha1::digest_type message_digest;
bool copy_xact_details = false;

if (last_xact != post.xact) {
Expand All @@ -260,7 +260,7 @@ void anonymize_posts::operator()(post_t& post)
sha.process_bytes(buf.str().c_str(), buf.str().length());
sha.get_digest(message_digest);

xact.payee = to_hex(message_digest);
xact.payee = digest_to_hex(message_digest, 8);
xact.note = none;
} else {
xact.journal = post.xact->journal;
Expand All @@ -278,7 +278,7 @@ void anonymize_posts::operator()(post_t& post)
sha.process_bytes(buf.str().c_str(), buf.str().length());
sha.get_digest(message_digest);

account_names.push_front(to_hex(message_digest));
account_names.push_front(digest_to_hex(message_digest, 8));
}

account_t * new_account =
Expand Down
40 changes: 25 additions & 15 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,29 +578,39 @@ inline int peek_next_nonws(std::istream& in) {
*_p = '\0'; \
}

inline string to_hex(unsigned char * message_digest, const int len = 4)
{
inline string digest_to_hex(
const boost::uuids::detail::sha1::digest_type& message_digest,
size_t len = sizeof(boost::uuids::detail::sha1::digest_type) * 2
) {
std::ostringstream buf;

for(int i = 0; i < 20 ; i++) {
buf.width(2);
buf.fill('0');
buf << std::hex << (int)message_digest[i];
if (i + 1 >= len)
break; // only output the first LEN dwords
buf.setf(std::ios_base::hex, std::ios_base::basefield);
buf.fill('0');

// sha1::digest_type is an array type and may change between Boost versions
const size_t count = std::min(
sizeof(message_digest) / sizeof(message_digest[0]),
(len - 1) / (sizeof(message_digest[0]) * 2) + 1
);
for(size_t i = 0; i < count; i++) {
buf.width(sizeof(message_digest[i]) * 2);
buf << (unsigned int)message_digest[i];
}
return buf.str();
string hex = buf.str();
hex.resize(len, '0'); // in case a partial element is requested
return hex;
}

inline string sha1sum(const string& str)
{
inline string sha1sum(
const string& str,
size_t len = sizeof(boost::uuids::detail::sha1::digest_type) * 2
) {
boost::uuids::detail::sha1 sha;
boost::uuids::detail::sha1::digest_type message_digest;

sha.reset();
sha.process_bytes(str.c_str(), str.length());

unsigned char message_digest[20];
sha.get_digest(message_digest);
return to_hex(message_digest, 20);
return digest_to_hex(message_digest, len);
}

extern const string version;
Expand Down

0 comments on commit 4f4cc16

Please sign in to comment.