diff options
author | John Wiegley <johnw@newartisans.com> | 2023-11-23 15:42:44 -0800 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2024-08-05 08:35:56 -0700 |
commit | a2df9c48870ee3fb25051c3473476f91e8d467d8 (patch) | |
tree | cb3653226eba7d8814c01b79deeb470a8c1c1a0f /src | |
parent | db0661dbb51e9082e47926c31e93bdc97b491bf9 (diff) | |
download | fork-ledger-a2df9c48870ee3fb25051c3473476f91e8d467d8.tar.gz fork-ledger-a2df9c48870ee3fb25051c3473476f91e8d467d8.tar.bz2 fork-ledger-a2df9c48870ee3fb25051c3473476f91e8d467d8.zip |
--hashes option requires an argument to specify the algorithm
At the moment only "sha512" or "SHA512" is accepted, but this could extend to
more algorithms in the future.
Diffstat (limited to 'src')
-rw-r--r-- | src/session.cc | 8 | ||||
-rw-r--r-- | src/session.h | 19 |
2 files changed, 21 insertions, 6 deletions
diff --git a/src/session.cc b/src/session.cc index 6958603e..4587f24a 100644 --- a/src/session.cc +++ b/src/session.cc @@ -134,7 +134,7 @@ std::size_t session_t::read_data(const string& master_account) parsing_context.push(*price_db_path); parsing_context.get_current().journal = journal.get(); try { - if (journal->read(parsing_context, HANDLED(hashes)) > 0) + if (journal->read(parsing_context, HANDLED(hashes_)) > 0) throw_(parse_error, _("Transactions not allowed in price history file")); } catch (...) { @@ -169,7 +169,7 @@ std::size_t session_t::read_data(const string& master_account) parsing_context.get_current().journal = journal.get(); parsing_context.get_current().master = acct; try { - xact_count += journal->read(parsing_context, HANDLED(hashes)); + xact_count += journal->read(parsing_context, HANDLED(hashes_)); } catch (...) { parsing_context.pop(); @@ -230,7 +230,7 @@ journal_t * session_t::read_journal_from_string(const string& data) parsing_context.get_current().journal = journal.get(); parsing_context.get_current().master = journal->master; try { - journal->read(parsing_context, HANDLED(hashes)); + journal->read(parsing_context, HANDLED(hashes_)); } catch (...) { parsing_context.pop(); @@ -332,7 +332,7 @@ option_t<session_t> * session_t::lookup_option(const char * p) OPT_(file_); // -f break; case 'h': - OPT(hashes); + OPT(hashes_); break; case 'i': OPT(input_date_format_); diff --git a/src/session.h b/src/session.h index dcb554eb..ce1b69a3 100644 --- a/src/session.h +++ b/src/session.h @@ -112,7 +112,7 @@ public: HANDLER(decimal_comma).report(out); HANDLER(time_colon).report(out); HANDLER(file_).report(out); - HANDLER(hashes).report(out); + HANDLER(hashes_).report(out); HANDLER(input_date_format_).report(out); HANDLER(explicit).report(out); HANDLER(master_account_).report(out); @@ -163,7 +163,22 @@ public: data_files.push_back(str); }); - OPTION(session_t, hashes); + enum hash_type_t { + NO_HASHES = 0, + HASH_SHA512 = 1 + }; + + OPTION__ + (session_t, hashes_, + hash_type_t hash_type = NO_HASHES; + CTOR(session_t, hashes_) {} + DO_(str) { + if (str == "sha512" || str == "SHA512") { + hash_type = HASH_SHA512; + } else { + throw_(std::invalid_argument, _f("Unrecognized hash type")); + } + }); OPTION_(session_t, input_date_format_, DO_(str) { // This changes static variables inside times.h, which affects the |