Skip to content

Commit

Permalink
Add whitespace to xact_t::hash
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiegley committed Aug 5, 2024
1 parent cab357a commit 621eb11
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/xact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,16 @@ namespace {

string xact_t::hash(string nonce, hash_type_t hash_type) const {
std::ostringstream repr;

repr << nonce;
repr << date();
repr << aux_date();
repr << code;
repr << payee;

posts_list all_posts(posts.begin(), posts.end());
std::vector<std::string> strings;

foreach (post_t * post, all_posts) {
std::ostringstream posting;
posting << post->account->fullname();
Expand All @@ -614,13 +617,18 @@ string xact_t::hash(string nonce, hash_type_t hash_type) const {
posting << post->checkout;
strings.push_back(posting.str());
}

std::sort(strings.begin(), strings.end());

foreach (string& str, strings) {
repr << str;
}

unsigned char data[128];
string repr_str(repr.str());

SHA512((void *)repr_str.c_str(), repr_str.length(), data);

return bufferToHex(
data, hash_type == HASH_SHA512 ? 64 : 32 /*SHA512_DIGEST_LENGTH*/);
}
Expand Down

0 comments on commit 621eb11

Please sign in to comment.