From db0661dbb51e9082e47926c31e93bdc97b491bf9 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 22 Nov 2023 16:47:21 -0800 Subject: Add support for hash chaining to detect modifications in postings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following details of a posting contribute to its hash: fullname of account string representation of amount Each posting hashes contributes to the transaction hash, which is compromised of: previous transaction’s hash (as encountered in parsing order) actual date optional auxiliary date optional code payee hashes of all postings Note that this means that changes in the “code” or any of the comments --- src/xact.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/xact.cc') diff --git a/src/xact.cc b/src/xact.cc index 55e816cb..0b9bd9cd 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -581,6 +581,21 @@ bool xact_t::valid() const return true; } +string xact_t::hash(string nonce) const { + std::ostringstream repr; + repr << nonce; + repr << date(); + repr << aux_date(); + repr << code; + repr << payee; + string hash(repr.str()); + posts_list all_posts(posts.begin(), posts.end()); + foreach (post_t * post, all_posts) { + hash = post->hash(hash); + } + return hash; +} + namespace { bool post_pred(expr_t::ptr_op_t op, post_t& post) { -- cgit v1.2.3