aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-06-30 02:28:47 +0000
committerlloyd <[email protected]>2008-06-30 02:28:47 +0000
commita01d19fd314804f3466737b3c6314bec0d511990 (patch)
tree7d8e24004d0d9c7a8852a2faa1f8c0612eee90dd /src
parent954e01df3c99836d13f2a188193b0bdbf660856a (diff)
Remove the Config class.
In reality, Config was a singleton, with the only owner being the Library_State object. Theoretically one could create and use another Config instance, but in practice it was never done. Reflect the reality and inline the members and public functions of Config in Library_State, removing Config entirely.
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp114
-rw-r--r--src/dl_group.cpp3
-rw-r--r--src/libstate.cpp106
-rw-r--r--src/mem_pool.cpp3
-rw-r--r--src/oids.cpp17
-rw-r--r--src/pk_core.cpp1
-rw-r--r--src/policy.cpp16
-rw-r--r--src/selftest.cpp3
-rw-r--r--src/x509_ca.cpp5
-rw-r--r--src/x509opt.cpp1
-rw-r--r--src/x509self.cpp1
11 files changed, 104 insertions, 166 deletions
diff --git a/src/config.cpp b/src/config.cpp
deleted file mode 100644
index 121335c7d..000000000
--- a/src/config.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/*************************************************
-* Configuration Handling Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
-
-#include <botan/config.h>
-#include <botan/libstate.h>
-#include <botan/mutex.h>
-#include <botan/stl_util.h>
-#include <botan/lookup.h>
-#include <string>
-
-namespace Botan {
-
-/*************************************************
-* Dereference an alias *
-*************************************************/
-std::string deref_alias(const std::string& name)
- {
- return global_state().config().deref_alias(name);
- }
-
-/*************************************************
-* Get a configuration value *
-*************************************************/
-Config::Config()
- {
- mutex = global_state().get_mutex();
- }
-
-/*************************************************
-* Get a configuration value *
-*************************************************/
-Config::~Config()
- {
- delete mutex;
- }
-
-/*************************************************
-* Get a configuration value *
-*************************************************/
-std::string Config::get(const std::string& section,
- const std::string& key) const
- {
- Mutex_Holder lock(mutex);
-
- return search_map<std::string, std::string>(settings,
- section + "/" + key, "");
- }
-
-/*************************************************
-* See if a particular option has been set *
-*************************************************/
-bool Config::is_set(const std::string& section,
- const std::string& key) const
- {
- Mutex_Holder lock(mutex);
-
- return search_map(settings, section + "/" + key, false, true);
- }
-
-/*************************************************
-* Set a configuration value *
-*************************************************/
-void Config::set(const std::string& section, const std::string& key,
- const std::string& value, bool overwrite)
- {
- Mutex_Holder lock(mutex);
-
- std::string full_key = section + "/" + key;
-
- std::map<std::string, std::string>::const_iterator i =
- settings.find(full_key);
-
- if(overwrite || i == settings.end() || i->second == "")
- settings[full_key] = value;
- }
-
-/*************************************************
-* Add an alias *
-*************************************************/
-void Config::add_alias(const std::string& key, const std::string& value)
- {
- set("alias", key, value);
- }
-
-/*************************************************
-* Dereference an alias to a fixed name *
-*************************************************/
-std::string Config::deref_alias(const std::string& key) const
- {
- std::string result = key;
- while(is_set("alias", result))
- result = get("alias", result);
- return result;
- }
-
-/*************************************************
-* Set/Add an option *
-*************************************************/
-void Config::set_option(const std::string key, const std::string& value)
- {
- set("conf", key, value);
- }
-
-/*************************************************
-* Get an option value *
-*************************************************/
-std::string Config::option(const std::string& key) const
- {
- return get("conf", key);
- }
-
-}
diff --git a/src/dl_group.cpp b/src/dl_group.cpp
index 5db2c045b..f1a7cb26e 100644
--- a/src/dl_group.cpp
+++ b/src/dl_group.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/dl_group.h>
-#include <botan/config.h>
#include <botan/libstate.h>
#include <botan/parsing.h>
#include <botan/numthry.h>
@@ -29,7 +28,7 @@ DL_Group::DL_Group()
*************************************************/
DL_Group::DL_Group(const std::string& type)
{
- std::string grp_contents = global_state().config().get("dl", type);
+ std::string grp_contents = global_state().get("dl", type);
if(grp_contents == "")
throw Invalid_Argument("DL_Group: Unknown group " + type);
diff --git a/src/libstate.cpp b/src/libstate.cpp
index d0848b52d..f96a53d19 100644
--- a/src/libstate.cpp
+++ b/src/libstate.cpp
@@ -4,15 +4,13 @@
*************************************************/
#include <botan/libstate.h>
-#include <botan/config.h>
#include <botan/modules.h>
#include <botan/engine.h>
#include <botan/stl_util.h>
#include <botan/mutex.h>
#include <botan/charset.h>
-#include <botan/x931_rng.h>
-#include <botan/randpool.h>
#include <botan/selftest.h>
+#include <botan/lookup.h>
#include <algorithm>
namespace Botan {
@@ -27,6 +25,14 @@ Library_State* global_lib_state = 0;
}
/*************************************************
+* Dereference an alias *
+*************************************************/
+std::string deref_alias(const std::string& name)
+ {
+ return global_state().deref_alias(name);
+ }
+
+/*************************************************
* Access the global state object *
*************************************************/
Library_State& global_state()
@@ -82,7 +88,7 @@ Allocator* Library_State::get_allocator(const std::string& type) const
if(!cached_default_allocator)
{
- std::string chosen = config().option("base/default_allocator");
+ std::string chosen = this->option("base/default_allocator");
if(chosen == "")
chosen = "malloc";
@@ -110,14 +116,14 @@ void Library_State::add_allocator(Allocator* allocator)
/*************************************************
* Set the default allocator type *
*************************************************/
-void Library_State::set_default_allocator(const std::string& type) const
+void Library_State::set_default_allocator(const std::string& type)
{
Mutex_Holder lock(allocator_lock);
if(type == "")
return;
- config().set("conf", "base/default_allocator", type);
+ this->set("conf", "base/default_allocator", type);
cached_default_allocator = 0;
}
@@ -143,25 +149,79 @@ void Library_State::add_engine(Engine* engine)
}
/*************************************************
-* Get the configuration object *
+* Get a configuration value *
*************************************************/
-Config& Library_State::config() const
+std::string Library_State::get(const std::string& section,
+ const std::string& key) const
{
- if(!config_obj)
- {
- config_obj = new Config();
- config_obj->load_defaults();
- }
+ Mutex_Holder lock(config_lock);
+
+ return search_map<std::string, std::string>(config,
+ section + "/" + key, "");
+ }
+
+/*************************************************
+* See if a particular option has been set *
+*************************************************/
+bool Library_State::is_set(const std::string& section,
+ const std::string& key) const
+ {
+ Mutex_Holder lock(config_lock);
+
+ return search_map(config, section + "/" + key, false, true);
+ }
+
+/*************************************************
+* Set a configuration value *
+*************************************************/
+void Library_State::set(const std::string& section, const std::string& key,
+ const std::string& value, bool overwrite)
+ {
+ Mutex_Holder lock(config_lock);
+
+ std::string full_key = section + "/" + key;
+
+ std::map<std::string, std::string>::const_iterator i =
+ config.find(full_key);
- return (*config_obj);
+ if(overwrite || i == config.end() || i->second == "")
+ config[full_key] = value;
}
/*************************************************
-* Set the configuration object *
+* Add an alias *
*************************************************/
-std::string Library_State::option(const std::string& name) const
+void Library_State::add_alias(const std::string& key, const std::string& value)
{
- return config().option(name);
+ set("alias", key, value);
+ }
+
+/*************************************************
+* Dereference an alias to a fixed name *
+*************************************************/
+std::string Library_State::deref_alias(const std::string& key) const
+ {
+ std::string result = key;
+ while(is_set("alias", result))
+ result = get("alias", result);
+ return result;
+ }
+
+/*************************************************
+* Set/Add an option *
+*************************************************/
+void Library_State::set_option(const std::string key,
+ const std::string& value)
+ {
+ set("conf", key, value);
+ }
+
+/*************************************************
+* Get an option value *
+*************************************************/
+std::string Library_State::option(const std::string& key) const
+ {
+ return get("conf", key);
}
/*************************************************
@@ -180,6 +240,7 @@ void Library_State::initialize(const InitializerOptions& args,
allocator_lock = get_mutex();
engine_lock = get_mutex();
+ config_lock = get_mutex();
cached_default_allocator = 0;
@@ -189,6 +250,8 @@ void Library_State::initialize(const InitializerOptions& args,
set_default_allocator(modules.default_allocator());
+ load_default_config();
+
std::vector<Engine*> mod_engines = modules.engines();
for(u32bit j = 0; j != mod_engines.size(); ++j)
engines.push_back(mod_engines[j]);
@@ -206,11 +269,7 @@ void Library_State::initialize(const InitializerOptions& args,
Library_State::Library_State()
{
mutex_factory = 0;
-
- allocator_lock = engine_lock = 0;
-
- config_obj = 0;
-
+ allocator_lock = engine_lock = config_lock = 0;
cached_default_allocator = 0;
}
@@ -219,8 +278,6 @@ Library_State::Library_State()
*************************************************/
Library_State::~Library_State()
{
- delete config_obj;
-
std::for_each(engines.begin(), engines.end(), del_fun<Engine>());
cached_default_allocator = 0;
@@ -234,6 +291,7 @@ Library_State::~Library_State()
delete allocator_lock;
delete engine_lock;
delete mutex_factory;
+ delete config_lock;
}
}
diff --git a/src/mem_pool.cpp b/src/mem_pool.cpp
index 7ab121ffb..4c2c30d25 100644
--- a/src/mem_pool.cpp
+++ b/src/mem_pool.cpp
@@ -1,13 +1,12 @@
/*************************************************
* Pooling Allocator Source File *
-* (C) 1999-2007 Jack Lloyd *
+* (C) 1999-2008 Jack Lloyd *
* 2005 Matthew Gregan *
* 2005-2006 Matt Johnston *
*************************************************/
#include <botan/mem_pool.h>
#include <botan/libstate.h>
-#include <botan/config.h>
#include <botan/util.h>
#include <algorithm>
diff --git a/src/oids.cpp b/src/oids.cpp
index 8402edb18..0823625ea 100644
--- a/src/oids.cpp
+++ b/src/oids.cpp
@@ -1,10 +1,9 @@
/*************************************************
* OID Registry Source File *
-* (C) 1999-2007 Jack Lloyd *
+* (C) 1999-2008 Jack Lloyd *
*************************************************/
#include <botan/oids.h>
-#include <botan/config.h>
#include <botan/libstate.h>
namespace Botan {
@@ -18,10 +17,10 @@ void add_oid(const OID& oid, const std::string& name)
{
const std::string oid_str = oid.as_string();
- if(!global_state().config().is_set("oid2str", oid_str))
- global_state().config().set("oid2str", oid_str, name);
- if(!global_state().config().is_set("str2oid", name))
- global_state().config().set("str2oid", name, oid_str);
+ if(!global_state().is_set("oid2str", oid_str))
+ global_state().set("oid2str", oid_str, name);
+ if(!global_state().is_set("str2oid", name))
+ global_state().set("str2oid", name, oid_str);
}
/*************************************************
@@ -29,7 +28,7 @@ void add_oid(const OID& oid, const std::string& name)
*************************************************/
std::string lookup(const OID& oid)
{
- std::string name = global_state().config().get("oid2str", oid.as_string());
+ std::string name = global_state().get("oid2str", oid.as_string());
if(name == "")
return oid.as_string();
return name;
@@ -40,7 +39,7 @@ std::string lookup(const OID& oid)
*************************************************/
OID lookup(const std::string& name)
{
- std::string value = global_state().config().get("str2oid", name);
+ std::string value = global_state().get("str2oid", name);
if(value != "")
return OID(value);
@@ -59,7 +58,7 @@ OID lookup(const std::string& name)
*************************************************/
bool have_oid(const std::string& name)
{
- return global_state().config().is_set("str2oid", name);
+ return global_state().is_set("str2oid", name);
}
/*************************************************
diff --git a/src/pk_core.cpp b/src/pk_core.cpp
index 939ad1c1f..82fe4c217 100644
--- a/src/pk_core.cpp
+++ b/src/pk_core.cpp
@@ -6,7 +6,6 @@
#include <botan/pk_core.h>
#include <botan/numthry.h>
#include <botan/engine.h>
-#include <botan/config.h>
#include <botan/parsing.h>
#include <algorithm>
diff --git a/src/policy.cpp b/src/policy.cpp
index 306a6bb31..bdd26e6d6 100644
--- a/src/policy.cpp
+++ b/src/policy.cpp
@@ -1,9 +1,9 @@
/*************************************************
* Default Policy Source File *
-* (C) 1999-2007 Jack Lloyd *
+* (C) 1999-2008 Jack Lloyd *
*************************************************/
-#include <botan/config.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -12,7 +12,7 @@ namespace {
/*************************************************
* OID loading helper function *
*************************************************/
-void add_oid(Config& config,
+void add_oid(Library_State& config,
const std::string& oid_str,
const std::string& name)
{
@@ -25,7 +25,7 @@ void add_oid(Config& config,
/*************************************************
* Load all of the default OIDs *
*************************************************/
-void set_default_oids(Config& config)
+void set_default_oids(Library_State& config)
{
add_oid(config, "1.2.840.113549.1.1.1", "RSA");
add_oid(config, "2.5.8.1.1", "RSA");
@@ -166,7 +166,7 @@ void set_default_oids(Config& config)
/*************************************************
* Set the default algorithm aliases *
*************************************************/
-void set_default_aliases(Config& config)
+void set_default_aliases(Library_State& config)
{
config.add_alias("OpenPGP.Cipher.1", "IDEA");
config.add_alias("OpenPGP.Cipher.2", "TripleDES");
@@ -210,7 +210,7 @@ void set_default_aliases(Config& config)
/*************************************************
* Set the default configuration toggles *
*************************************************/
-void set_default_config(Config& config)
+void set_default_config(Library_State& config)
{
config.set_option("base/default_pbe",
"PBE-PKCS5v20(SHA-1,TripleDES/CBC)");
@@ -245,7 +245,7 @@ void set_default_config(Config& config)
/*************************************************
* Set the built-in discrete log groups *
*************************************************/
-void set_default_dl_groups(Config& config)
+void set_default_dl_groups(Library_State& config)
{
config.set("dl", "modp/ietf/768",
"-----BEGIN X942 DH PARAMETERS-----"
@@ -375,7 +375,7 @@ void set_default_dl_groups(Config& config)
/*************************************************
* Set the default policy *
*************************************************/
-void Config::load_defaults()
+void Library_State::load_default_config()
{
set_default_config(*this);
set_default_aliases(*this);
diff --git a/src/selftest.cpp b/src/selftest.cpp
index 3c8185ce0..135317bb7 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -149,8 +149,9 @@ bool passes_self_tests()
"0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"
"0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B");
}
- catch(std::exception)
+ catch(std::exception& e)
{
+ printf("%s\n", e.what());
return false;
}
diff --git a/src/x509_ca.cpp b/src/x509_ca.cpp
index 24cc35a74..d455e4988 100644
--- a/src/x509_ca.cpp
+++ b/src/x509_ca.cpp
@@ -8,7 +8,6 @@
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/libstate.h>
-#include <botan/config.h>
#include <botan/lookup.h>
#include <botan/look_pk.h>
#include <botan/numthry.h>
@@ -258,14 +257,14 @@ PK_Signer* choose_sig_format(const Private_Key& key,
if(hash == "")
throw Invalid_State("No value set for x509/ca/rsa_hash");
- hash = global_state().config().deref_alias(hash);
+ hash = global_state().deref_alias(hash);
padding = "EMSA3(" + hash + ")";
format = IEEE_1363;
}
else if(algo_name == "DSA")
{
- std::string hash = global_state().config().deref_alias("SHA-1");
+ std::string hash = global_state().deref_alias("SHA-1");
padding = "EMSA1(" + hash + ")";
format = DER_SEQUENCE;
}
diff --git a/src/x509opt.cpp b/src/x509opt.cpp
index 36b82de00..716884ed5 100644
--- a/src/x509opt.cpp
+++ b/src/x509opt.cpp
@@ -7,7 +7,6 @@
#include <botan/util.h>
#include <botan/parsing.h>
#include <botan/oids.h>
-#include <botan/config.h>
#include <ctime>
namespace Botan {
diff --git a/src/x509self.cpp b/src/x509self.cpp
index 046ca4c8d..6c3baae9b 100644
--- a/src/x509self.cpp
+++ b/src/x509self.cpp
@@ -7,7 +7,6 @@
#include <botan/x509_ext.h>
#include <botan/x509_ca.h>
#include <botan/der_enc.h>
-#include <botan/config.h>
#include <botan/look_pk.h>
#include <botan/oids.h>
#include <botan/pipe.h>