diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-12 14:43:40 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-12 14:43:40 -0400 |
commit | a1fc3c5cfe2ff1fa01c488d4e130b6592be1f111 (patch) | |
tree | 2e8d66584569fa7ef278695ddb78d11676375fff | |
parent | 0fb6bf4189c57802fafb611f18f419cd6b588ac4 (diff) | |
download | fork-ledger-a1fc3c5cfe2ff1fa01c488d4e130b6592be1f111.tar.gz fork-ledger-a1fc3c5cfe2ff1fa01c488d4e130b6592be1f111.tar.bz2 fork-ledger-a1fc3c5cfe2ff1fa01c488d4e130b6592be1f111.zip |
The --anon option now randomizes its effect
-rw-r--r-- | src/filters.cc | 13 | ||||
-rw-r--r-- | src/filters.h | 12 | ||||
-rw-r--r-- | test/baseline/opt-anon.test | 11 |
3 files changed, 19 insertions, 17 deletions
diff --git a/src/filters.cc b/src/filters.cc index 819e3d97..86386f58 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -270,8 +270,12 @@ void anonymize_posts::operator()(post_t& post) if (copy_xact_details) { xact.copy_details(*post.xact); + std::ostringstream buf; + buf << reinterpret_cast<uintmax_t>(post.xact->payee.c_str()) + << integer_gen() << post.xact->payee.c_str(); + sha.Reset(); - sha << post.xact->payee.c_str(); + sha << buf.str().c_str(); sha.Result(message_digest); xact.payee = to_hex(message_digest); @@ -283,8 +287,11 @@ void anonymize_posts::operator()(post_t& post) for (account_t * acct = post.account; acct; acct = acct->parent) { + std::ostringstream buf; + buf << integer_gen() << acct << acct->fullname(); + sha.Reset(); - sha << acct->name.c_str(); + sha << buf.str().c_str(); sha.Result(message_digest); account_names.push_front(to_hex(message_digest)); @@ -296,9 +303,7 @@ void anonymize_posts::operator()(post_t& post) temp.note = none; temp.add_flags(POST_ANONYMIZED); - DEBUG("foo", "1.rendering amount: " << temp.amount); render_commodity(temp.amount); - DEBUG("foo", "2.rendering amount: " << temp.amount); if (temp.amount.has_annotation()) { temp.amount.annotation().tag = none; if (temp.amount.annotation().price) diff --git a/src/filters.h b/src/filters.h index e981dcd4..0f414151 100644 --- a/src/filters.h +++ b/src/filters.h @@ -334,18 +334,26 @@ public: class anonymize_posts : public item_handler<post_t> { - typedef std::map<commodity_t *, std::size_t> commodity_index_map; + typedef std::map<commodity_t *, std::size_t> commodity_index_map; + typedef variate_generator<mt19937&, uniform_int<> > int_generator_t; temporaries_t temps; commodity_index_map comms; std::size_t next_comm_id; xact_t * last_xact; + mt19937 rnd_gen; + uniform_int<> integer_range; + int_generator_t integer_gen; anonymize_posts(); public: anonymize_posts(post_handler_ptr handler) - : item_handler<post_t>(handler), next_comm_id(0), last_xact(NULL) { + : item_handler<post_t>(handler), next_comm_id(0), last_xact(NULL), + rnd_gen(static_cast<unsigned int>(reinterpret_cast<uintmax_t>(this) + + static_cast<uintmax_t>(std::time(0)))), + integer_range(1, 2000000000L), + integer_gen(rnd_gen, integer_range) { TRACE_CTOR(anonymize_posts, "post_handler_ptr"); } virtual ~anonymize_posts() { diff --git a/test/baseline/opt-anon.test b/test/baseline/opt-anon.test deleted file mode 100644 index 345d981f..00000000 --- a/test/baseline/opt-anon.test +++ /dev/null @@ -1,11 +0,0 @@ -reg --anon -<<< -2007/02/02 RD VMMXX - Assets:Investments:Vanguard:VMMXX 0.350 VMMXX @ $1.00 - Income:Dividends:Vanguard:VMMXX $-0.35 ->>>1 -07-Feb-02 6a93dcb3 da:20:5d:27:988a9c3a 0.350 A 0.350 A - da:1c:b6:27:988a9c3a B-0.35 0.350 A - B-0.35 ->>>2 -=== 0 |