The unified diff between revisions [258e319e..] and [b773b0a7..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'src/config.cpp'
#
#
# patch "src/config.cpp"
# from [cb5e6f5108247da86e71cfbb2e553cfc755d4c9a]
# to [371b5e52da741c35e70f61841faa85ff4d7c22b7]
#
============================================================
--- src/config.cpp cb5e6f5108247da86e71cfbb2e553cfc755d4c9a
+++ src/config.cpp 371b5e52da741c35e70f61841faa85ff4d7c22b7
@@ -1,15 +1,12 @@
/*************************************************
* Configuration Handling Source File *
-* (C) 1999-2007 The Botan Project *
+* (C) 1999-2007 Jack Lloyd *
*************************************************/
#include <botan/config.h>
#include <botan/libstate.h>
-#include <botan/lookup.h>
-#include <botan/charset.h>
-#include <botan/parsing.h>
+#include <botan/mutex.h>
#include <botan/stl_util.h>
-#include <botan/mutex.h>
#include <string>
namespace Botan {
@@ -23,12 +20,36 @@ Config& global_config()
}
/*************************************************
+* 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
{
- Named_Mutex_Holder lock("config");
+ Mutex_Holder lock(mutex);
return search_map<std::string, std::string>(settings,
section + "/" + key, "");
@@ -40,7 +61,7 @@ bool Config::is_set(const std::string& s
bool Config::is_set(const std::string& section,
const std::string& key) const
{
- Named_Mutex_Holder lock("config");
+ Mutex_Holder lock(mutex);
return search_map(settings, section + "/" + key, false, true);
}
@@ -51,7 +72,7 @@ void Config::set(const std::string& sect
void Config::set(const std::string& section, const std::string& key,
const std::string& value, bool overwrite)
{
- Named_Mutex_Holder lock("config");
+ Mutex_Holder lock(mutex);
std::string full_key = section + "/" + key;
@@ -97,107 +118,4 @@ std::string Config::option(const std::st
return get("conf", key);
}
-/*************************************************
-* Get the config setting as a list of strings *
-*************************************************/
-std::vector<std::string> Config::option_as_list(const std::string& key) const
- {
- return split_on(option(key), ':');
- }
-
-/*************************************************
-* Get the config setting as a u32bit *
-*************************************************/
-u32bit Config::option_as_u32bit(const std::string& key) const
- {
- return parse_expr(option(key));
- }
-
-/*************************************************
-* Get the config setting as a time *
-*************************************************/
-u32bit Config::option_as_time(const std::string& key) const
- {
- const std::string timespec = option(key);
- if(timespec == "")
- return 0;
-
- const char suffix = timespec[timespec.size()-1];
- std::string value = timespec.substr(0, timespec.size()-1);
-
- u32bit scale = 1;
-
- if(Charset::is_digit(suffix))
- value += suffix;
- else if(suffix == 's')
- scale = 1;
- else if(suffix == 'm')
- scale = 60;
- else if(suffix == 'h')
- scale = 60 * 60;
- else if(suffix == 'd')
- scale = 24 * 60 * 60;
- else if(suffix == 'y')
- scale = 365 * 24 * 60 * 60;
- else
- throw Decoding_Error(
- "Config::option_as_time: Unknown time value " + value
- );
-
- return scale * to_u32bit(value);
- }
-
-/*************************************************
-* Get the config setting as a boolean *
-*************************************************/
-bool Config::option_as_bool(const std::string& key) const
- {
- const std::string value = option(key);
- if(value == "0" || value == "false")
- return false;
- if(value == "1" || value == "true")
- return true;
-
- throw Decoding_Error(
- "Config::option_as_bool: Unknown boolean value " + value
- );
- }
-
-/*************************************************
-* Choose the signature format for a PK algorithm *
-*************************************************/
-void Config::choose_sig_format(const std::string& algo_name,
- std::string& padding,
- Signature_Format& format)
- {
- if(algo_name == "RSA")
- {
- std::string hash = global_state().config().option("x509/ca/rsa_hash");
-
- if(hash == "")
- throw Invalid_State("No value set for x509/ca/rsa_hash");
-
- hash = global_state().config().deref_alias(hash);
-
- padding = "EMSA3(" + hash + ")";
- format = IEEE_1363;
- }
- else if(algo_name == "DSA")
- {
- std::string hash = global_state().config().deref_alias("SHA-1");
- padding = "EMSA1(" + hash + ")";
- format = DER_SEQUENCE;
- }
- else
- throw Invalid_Argument("Unknown X.509 signing key type: " + algo_name);
- }
-
-/*************************************************
-* Dereference an alias *
-*************************************************/
-std::string deref_alias(const std::string& name)
- {
- return global_config().deref_alias(name);
- }
-
}