summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-12 14:43:40 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-12 14:43:40 -0400
commita1fc3c5cfe2ff1fa01c488d4e130b6592be1f111 (patch)
tree2e8d66584569fa7ef278695ddb78d11676375fff /src
parent0fb6bf4189c57802fafb611f18f419cd6b588ac4 (diff)
downloadfork-ledger-a1fc3c5cfe2ff1fa01c488d4e130b6592be1f111.tar.gz
fork-ledger-a1fc3c5cfe2ff1fa01c488d4e130b6592be1f111.tar.bz2
fork-ledger-a1fc3c5cfe2ff1fa01c488d4e130b6592be1f111.zip
The --anon option now randomizes its effect
Diffstat (limited to 'src')
-rw-r--r--src/filters.cc13
-rw-r--r--src/filters.h12
2 files changed, 19 insertions, 6 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() {