#include "botan-1.6/include/init.h"
#include "botan-1.6/include/parsing.h"
#include "botan-1.6/include/stl_util.h"
#include "botan-1.6/include/exceptn.h"
namespace Enctain {
namespace Botan {
namespace {
bool boolean_arg(const std::map<std::string, std::string>& args,
const std::string& key, bool not_found = false)
{
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 + "'");
}
}
bool InitializerOptions::thread_safe() const
{
return boolean_arg(args, "thread_safe");
}
bool InitializerOptions::secure_memory() const
{
return boolean_arg(args, "secure_memory");
}
bool InitializerOptions::use_engines() const
{
return boolean_arg(args, "use_engines");
}
bool InitializerOptions::seed_rng() const
{
return boolean_arg(args, "seed_rng", true);
}
bool InitializerOptions::fips_mode() const
{
return boolean_arg(args, "fips140");
}
bool InitializerOptions::self_test() const
{
return boolean_arg(args, "selftest", true);
}
std::string InitializerOptions::config_file() const
{
std::map<std::string, std::string>::const_iterator i = args.find("config");
return (i != args.end()) ? i->second : "";
}
InitializerOptions::InitializerOptions(const std::string& 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]] = "true";
else
{
std::vector<std::string> name_and_value = split_on(arg_list[j], '=');
args[name_and_value[0]] = name_and_value[1];
}
}
}
}
}