monotone

monotone Mtn Source Tree

Root/botan/init_opt.cpp

1/*************************************************
2* Initialization Options Source File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#include <botan/init.h>
7#include <botan/parsing.h>
8#include <botan/stl_util.h>
9#include <botan/exceptn.h>
10
11namespace Botan {
12
13namespace {
14
15/*************************************************
16* Check for an arbitrary boolean-valued option *
17*************************************************/
18bool boolean_arg(const std::map<std::string, std::string>& args,
19 const std::string& key, bool not_found = false)
20 {
21 std::map<std::string, std::string>::const_iterator i = args.find(key);
22 if(i == args.end())
23 return not_found;
24
25 std::string value = i->second;
26
27 if(value == "1" || value == "true" || value == "yes" || value == "on")
28 return true;
29 if(value == "0" || value == "false" || value == "no" || value == "off")
30 return false;
31 if(value == "default")
32 return not_found;
33
34 throw Invalid_Argument("InitializerOptions: Bad argument for boolean " +
35 key + " of '" + value + "'");
36 }
37
38}
39
40/*************************************************
41* Check if thread safety was requested *
42*************************************************/
43bool InitializerOptions::thread_safe() const
44 {
45 return boolean_arg(args, "thread_safe");
46 }
47
48/*************************************************
49* Check if secure allocation was requested *
50*************************************************/
51bool InitializerOptions::secure_memory() const
52 {
53 return boolean_arg(args, "secure_memory");
54 }
55
56/*************************************************
57* Check if using engines was requested *
58*************************************************/
59bool InitializerOptions::use_engines() const
60 {
61 return boolean_arg(args, "use_engines");
62 }
63
64/*************************************************
65* Check if RNG seeding should be enabled *
66*************************************************/
67bool InitializerOptions::seed_rng() const
68 {
69 return boolean_arg(args, "seed_rng", true);
70 }
71
72/*************************************************
73* Check if FIPS mode was requested *
74*************************************************/
75bool InitializerOptions::fips_mode() const
76 {
77 return boolean_arg(args, "fips140");
78 }
79
80/*************************************************
81* Check if startup self tests were requested *
82*************************************************/
83bool InitializerOptions::self_test() const
84 {
85 return boolean_arg(args, "selftest", true);
86 }
87
88/*************************************************
89* Return the config file to load, if any *
90*************************************************/
91std::string InitializerOptions::config_file() const
92 {
93 std::map<std::string, std::string>::const_iterator i = args.find("config");
94 return (i != args.end()) ? i->second : "";
95 }
96
97/*************************************************
98* Setup an InitializerOptions *
99*************************************************/
100InitializerOptions::InitializerOptions(const std::string& arg_string)
101 {
102 const std::vector<std::string> arg_list = split_on(arg_string, ' ');
103
104 for(u32bit j = 0; j != arg_list.size(); ++j)
105 {
106 if(arg_list[j].size() == 0)
107 continue;
108
109 if(arg_list[j].find('=') == std::string::npos)
110 args[arg_list[j]] = "true";
111 else
112 {
113 std::vector<std::string> name_and_value = split_on(arg_list[j], '=');
114 args[name_and_value[0]] = name_and_value[1];
115 }
116 }
117 }
118
119}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status