diff options
author | lloyd <[email protected]> | 2006-07-13 15:20:17 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-07-13 15:20:17 +0000 |
commit | 3be48a22da97d908429e35340713f17535d8225b (patch) | |
tree | 40ba6c7aa0fbe40a678d414740e6ca0a035e795b | |
parent | 7457026a184011809dbfaf39fd45983784fda20d (diff) |
Extend the language offered by InitializerOptions a bit, so that
boolean options can be explicitly turned off.
Add support for checking the documented "fips140" argument
-rw-r--r-- | include/init.h | 3 | ||||
-rw-r--r-- | src/init_opt.cpp | 57 |
2 files changed, 46 insertions, 14 deletions
diff --git a/include/init.h b/include/init.h index 958cddda7..d98537231 100644 --- a/include/init.h +++ b/include/init.h @@ -21,11 +21,12 @@ class InitializerOptions bool use_engines() const; bool seed_rng() const; bool secure_memory() const; + bool fips_mode() const; + std::string config_file() const; InitializerOptions(const std::string&); private: - bool boolean_arg(const std::string&) const; std::map<std::string, std::string> args; }; diff --git a/src/init_opt.cpp b/src/init_opt.cpp index bfd7f075a..0494976d6 100644 --- a/src/init_opt.cpp +++ b/src/init_opt.cpp @@ -5,31 +5,52 @@ #include <botan/init.h> #include <botan/parsing.h> +#include <botan/stl_util.h> +#include <botan/exceptn.h> namespace Botan { +namespace { + /************************************************* * Check for an arbitrary boolean-valued option * *************************************************/ -bool InitializerOptions::boolean_arg(const std::string& option_name) const +bool boolean_arg(const std::map<std::string, std::string>& args, + const std::string& key, bool not_found = false) { - return (args.find(option_name) != args.end()); + std::map<std::string, std::string>::const_iterator i = args.find(key); + if(i == args.end()) + return not_found; + + std::string value = i->second; + + if(value == "1" || value == "true" || value == "yes" || value == "on") + return true; + if(value == "0" || value == "false" || value == "no" || value == "off") + return false; + if(value == "default") + return not_found; + + throw Invalid_Argument("InitializerOptions: Bad argument for boolean " + + key + " of '" + value + "'"); } +} + /************************************************* * Check if thread safety was requested * *************************************************/ bool InitializerOptions::thread_safe() const { - return boolean_arg("thread_safe"); + return boolean_arg(args, "thread_safe"); } /************************************************* -* Check if thread safety was requested * +* Check if secure allocation was requested * *************************************************/ bool InitializerOptions::secure_memory() const { - return boolean_arg("secure_memory"); + return boolean_arg(args, "secure_memory"); } /************************************************* @@ -37,15 +58,23 @@ bool InitializerOptions::secure_memory() const *************************************************/ bool InitializerOptions::use_engines() const { - return boolean_arg("use_engines"); + return boolean_arg(args, "use_engines"); } /************************************************* -* Check if RNG seeding should be disabled * +* Check if RNG seeding should be enabled * *************************************************/ bool InitializerOptions::seed_rng() const { - return !boolean_arg("no_rng_seed"); + return boolean_arg(args, "seed_rng", true); + } + +/************************************************* +* Check if FIPS mode was requested * +*************************************************/ +bool InitializerOptions::fips_mode() const + { + return boolean_arg(args, "fips140"); } /************************************************* @@ -53,9 +82,7 @@ bool InitializerOptions::seed_rng() const *************************************************/ std::string InitializerOptions::config_file() const { - std::map<std::string, std::string>::const_iterator i = - args.find("config"); - + std::map<std::string, std::string>::const_iterator i = args.find("config"); return (i != args.end()) ? i->second : ""; } @@ -64,11 +91,15 @@ std::string InitializerOptions::config_file() const *************************************************/ InitializerOptions::InitializerOptions(const std::string& arg_string) { - std::vector<std::string> arg_list = split_on(arg_string, ' '); + const std::vector<std::string> arg_list = split_on(arg_string, ' '); + for(u32bit j = 0; j != arg_list.size(); ++j) { + if(arg_list[j].size() == 0) + continue; + if(arg_list[j].find('=') == std::string::npos) - args[arg_list[j]] = ""; + args[arg_list[j]] = "true"; else { std::vector<std::string> name_and_value = split_on(arg_list[j], '='); |