aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstate')
-rw-r--r--src/libstate/info.txt3
-rw-r--r--src/libstate/init.cpp (renamed from src/libstate/init_def.cpp)22
-rw-r--r--src/libstate/init.h111
-rw-r--r--src/libstate/init_opt.cpp102
-rw-r--r--src/libstate/libstate.cpp18
-rw-r--r--src/libstate/libstate.h3
6 files changed, 30 insertions, 229 deletions
diff --git a/src/libstate/info.txt b/src/libstate/info.txt
index a0ba687d1..42b5e3e00 100644
--- a/src/libstate/info.txt
+++ b/src/libstate/info.txt
@@ -18,8 +18,7 @@ algo_factory.h
botan.h
get_enc.cpp
init.h
-init_def.cpp
-init_opt.cpp
+init.cpp
libstate.cpp
libstate.h
look_add.h
diff --git a/src/libstate/init_def.cpp b/src/libstate/init.cpp
index 742ca7c0b..0256d70dc 100644
--- a/src/libstate/init_def.cpp
+++ b/src/libstate/init.cpp
@@ -1,7 +1,7 @@
-/*************************************************
-* Default Initialization Function Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/**
+* Default Initialization Function Source File
+* (C) 1999-2007 Jack Lloyd
+*/
#include <botan/init.h>
#include <botan/libstate.h>
@@ -11,7 +11,7 @@ namespace Botan {
/*************************************************
* Library Initialization *
*************************************************/
-void LibraryInitializer::initialize(const InitializerOptions& args)
+void LibraryInitializer::initialize(bool thread_safe)
{
try
{
@@ -23,7 +23,7 @@ void LibraryInitializer::initialize(const InitializerOptions& args)
*/
set_global_state(new Library_State);
- global_state().initialize(args);
+ global_state().initialize(thread_safe);
}
catch(...)
{
@@ -40,14 +40,4 @@ void LibraryInitializer::deinitialize()
set_global_state(0);
}
-/*************************************************
-* Library Initialization *
-*************************************************/
-void LibraryInitializer::initialize(const std::string& arg_string)
- {
- InitializerOptions args(arg_string);
-
- initialize(args);
- }
-
}
diff --git a/src/libstate/init.h b/src/libstate/init.h
index e3eec3ce9..794fbd39e 100644
--- a/src/libstate/init.h
+++ b/src/libstate/init.h
@@ -1,113 +1,36 @@
-/*************************************************
-* Library Initialization Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
-
-#ifndef BOTAN_INIT_H__
-#define BOTAN_INIT_H__
-
-#include <botan/build.h>
-#include <string>
-#include <map>
-
-namespace Botan {
-
/**
-* This class represents options for initializing the library.
+* Library Initialization Header File
+* (C) 1999-2008 Jack Lloyd
*/
-class BOTAN_DLL InitializerOptions
- {
- public:
- /**
- * Check whether this set of options has thread safety enabled.
- * @return true if thread safety is enabled
- */
- bool thread_safe() const;
-
- /**
- * Check whether this set of options has the usage of alternative engines
- * enabled.
- * @return true if the usage of alternative engines
- * is enabled
- */
- bool use_engines() const;
-
- /**
- * Check whether this set of options has enabled the memory
- * locking feature. This is implemented for Unix and Win32, but
- * it only reliably works for Unix. There, all SecureVectors and
- * SecureBuffers are kept from being ever swapped to disk. On
- * Win32 plattforms, the corresponding pages are locked into the
- * working set of the process, reducing the chance of being
- * swapped to disk, but not strictly preventing it.
- * @return true if the memory locking feature is enabled
- */
- bool secure_memory() const;
- /**
- * Check whether this set of options has the self-test-at-startup
- * enabled. Same as self_test().
- * @param return true if the self-test is enabled
- */
- bool fips_mode() const;
-
- /**
- * Check whether this set of options has the self-test-at-startup enabled.
- * Same as fips_mode().
- * @param return true if the self-test is enabled
- */
- bool self_test() const;
+#ifndef BOTAN_LIBRARY_INITIALIZER_H__
+#define BOTAN_LIBRARY_INITIALIZER_H__
- /**
- * Get the full path of the configuration file to be used.
- */
- std::string config_file() const;
+#include <botan/libstate.h>
- /**
- * Create an initializer options object. The option are set based on the
- * input string. The options can be set by building a white space separated
- * list of elements out of the
- * following set of strings:
- * "config=<file name>",
- * "selftest",
- * "fips140",
- * "use_engines",
- * "secure_memory",
- * "thread_safe"
- *
- */
- InitializerOptions(const std::string& options);
- private:
- std::map<std::string, std::string> args;
- };
+namespace Botan {
/**
-* This class represents the Library Initialization/Shutdown Object. It has to
-* exceed the lifetime of any Botan object used in an application.
+* This class represents the Library Initialization/Shutdown Object. It
+* has to exceed the lifetime of any Botan object used in an
+* application. You can call initialize/deinitialize or use
+* LibraryInitializer in the RAII style.
*/
class BOTAN_DLL LibraryInitializer
{
public:
- static void initialize(const std::string& = "");
- static void initialize(const InitializerOptions&);
- static void deinitialize();
+ static void initialize(bool thread_safe);
- /**
- * Construct a library initializer from a string. Does exactly the same
- * as if an InitializerOptions object created with that string was used as
- * the argument.
- * @param args the string determining the desired library configuration
- */
- LibraryInitializer(const std::string& args = "") { initialize(args); }
+ static void deinitialize();
/**
- * Construct a library initializer.
- * @param args the initializer option object specifying the desired
- * library configuration
+ * Initialize the library
+ * @param thread_safe if the library should use a thread-safe mutex
*/
- LibraryInitializer(const InitializerOptions& args) { initialize(args); }
+ LibraryInitializer(bool thread_safe = false)
+ { LibraryInitializer::initialize(thread_safe); }
- ~LibraryInitializer() { deinitialize(); }
+ ~LibraryInitializer() { LibraryInitializer::deinitialize(); }
};
}
diff --git a/src/libstate/init_opt.cpp b/src/libstate/init_opt.cpp
deleted file mode 100644
index 5c4fbee65..000000000
--- a/src/libstate/init_opt.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/*************************************************
-* Initialization Options Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
-
-#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 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 + "'");
- }
-
-}
-
-/*************************************************
-* Check if thread safety was requested *
-*************************************************/
-bool InitializerOptions::thread_safe() const
- {
- return boolean_arg(args, "thread_safe");
- }
-
-/*************************************************
-* Check if secure allocation was requested *
-*************************************************/
-bool InitializerOptions::secure_memory() const
- {
- return boolean_arg(args, "secure_memory");
- }
-
-/*************************************************
-* Check if using engines was requested *
-*************************************************/
-bool InitializerOptions::use_engines() const
- {
- return boolean_arg(args, "use_engines");
- }
-
-/*************************************************
-* Check if FIPS mode was requested *
-*************************************************/
-bool InitializerOptions::fips_mode() const
- {
- return boolean_arg(args, "fips140");
- }
-
-/*************************************************
-* Check if startup self tests were requested *
-*************************************************/
-bool InitializerOptions::self_test() const
- {
- return boolean_arg(args, "selftest", true);
- }
-
-/*************************************************
-* Setup an InitializerOptions *
-*************************************************/
-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];
- }
- }
- }
-
-}
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp
index ebda40121..9096d98e6 100644
--- a/src/libstate/libstate.cpp
+++ b/src/libstate/libstate.cpp
@@ -228,12 +228,12 @@ Algorithm_Factory& Library_State::algo_factory()
/*************************************************
* Load a set of modules *
*************************************************/
-void Library_State::initialize(const InitializerOptions& args)
+void Library_State::initialize(bool thread_safe)
{
if(mutex_factory)
throw Invalid_State("Library_State has already been initialized");
- if(args.thread_safe() == false)
+ if(!thread_safe)
{
mutex_factory = new Noop_Mutex_Factory;
}
@@ -255,15 +255,15 @@ void Library_State::initialize(const InitializerOptions& args)
cached_default_allocator = 0;
- add_allocator(new Locking_Allocator(mutex_factory->make()));
add_allocator(new Malloc_Allocator);
- set_default_allocator("locking");
+ add_allocator(new Locking_Allocator(mutex_factory->make()));
#if defined(BOTAN_HAS_ALLOC_MMAP)
add_allocator(new MemoryMapping_Allocator(mutex_factory->make()));
- set_default_allocator("mmap");
#endif
+ set_default_allocator("locking");
+
load_default_config();
algorithm_factory = new Algorithm_Factory;
@@ -281,14 +281,6 @@ void Library_State::initialize(const InitializerOptions& args)
#endif
algorithm_factory->add_engine(new Default_Engine);
-
-#if defined(BOTAN_HAS_SELFTEST)
- if(args.fips_mode() || args.self_test())
- {
- if(!passes_self_tests())
- throw Self_Test_Failure("Initialization self-tests");
- }
-#endif
}
/*************************************************
diff --git a/src/libstate/libstate.h b/src/libstate/libstate.h
index f6ad70564..b5881dc62 100644
--- a/src/libstate/libstate.h
+++ b/src/libstate/libstate.h
@@ -7,7 +7,6 @@
#define BOTAN_LIB_STATE_H__
#include <botan/types.h>
-#include <botan/init.h>
#include <botan/allocate.h>
#include <botan/algo_factory.h>
@@ -26,7 +25,7 @@ class BOTAN_DLL Library_State
Library_State();
~Library_State();
- void initialize(const InitializerOptions&);
+ void initialize(bool thread_safe);
Algorithm_Factory& algo_factory();