aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-10 22:16:13 +0000
committerlloyd <[email protected]>2008-11-10 22:16:13 +0000
commit675aa7bcc476d8445b6eb2bc3c6b0a2f3ce12958 (patch)
treecdcc9c87a1692d62c6b6559aac8254acfe4dfa18 /src/libstate
parent88b635f50937f926097b76c7834baead3b936dfe (diff)
Remove Modules class from the initializer code - it just wasn't that useful
as an abstraction. Check #ifdef's for engines and such directly in libstate.cpp
Diffstat (limited to 'src/libstate')
-rw-r--r--src/libstate/info.txt2
-rw-r--r--src/libstate/init.h3
-rw-r--r--src/libstate/init_def.cpp25
-rw-r--r--src/libstate/libstate.cpp82
-rw-r--r--src/libstate/libstate.h4
-rw-r--r--src/libstate/modules.cpp136
-rw-r--r--src/libstate/modules.h54
7 files changed, 77 insertions, 229 deletions
diff --git a/src/libstate/info.txt b/src/libstate/info.txt
index ac4a9561e..a0ba687d1 100644
--- a/src/libstate/info.txt
+++ b/src/libstate/info.txt
@@ -25,7 +25,5 @@ libstate.h
look_add.h
lookup.cpp
lookup.h
-modules.cpp
-modules.h
policy.cpp
</add>
diff --git a/src/libstate/init.h b/src/libstate/init.h
index 7963a6fd8..e3eec3ce9 100644
--- a/src/libstate/init.h
+++ b/src/libstate/init.h
@@ -82,7 +82,7 @@ class BOTAN_DLL InitializerOptions
};
/**
-* This class represents the Library Initialization/Shutdown Object. It has to
+* This class represents the Library Initialization/Shutdown Object. It has to
* exceed the lifetime of any Botan object used in an application.
*/
class BOTAN_DLL LibraryInitializer
@@ -90,7 +90,6 @@ class BOTAN_DLL LibraryInitializer
public:
static void initialize(const std::string& = "");
static void initialize(const InitializerOptions&);
- static void initialize(const InitializerOptions&, class Modules&);
static void deinitialize();
/**
diff --git a/src/libstate/init_def.cpp b/src/libstate/init_def.cpp
index 03f97252e..742ca7c0b 100644
--- a/src/libstate/init_def.cpp
+++ b/src/libstate/init_def.cpp
@@ -5,21 +5,25 @@
#include <botan/init.h>
#include <botan/libstate.h>
-#include <botan/modules.h>
namespace Botan {
/*************************************************
* Library Initialization *
*************************************************/
-void LibraryInitializer::initialize(const InitializerOptions& args,
- Modules& modules)
+void LibraryInitializer::initialize(const InitializerOptions& args)
{
try
{
+ /*
+ This two stage initialization process is because Library_State's
+ constructor will implicitly refer to global state through the
+ allocators and so for, so global_state() has to be a valid
+ reference before initialize() can be called. Yeah, gross.
+ */
set_global_state(new Library_State);
- global_state().initialize(args, modules);
+ global_state().initialize(args);
}
catch(...)
{
@@ -42,19 +46,8 @@ void LibraryInitializer::deinitialize()
void LibraryInitializer::initialize(const std::string& arg_string)
{
InitializerOptions args(arg_string);
- Builtin_Modules modules(args);
-
- initialize(args, modules);
- }
-
-/*************************************************
-* Library Initialization *
-*************************************************/
-void LibraryInitializer::initialize(const InitializerOptions& args)
- {
- Builtin_Modules modules(args);
- initialize(args, modules);
+ initialize(args);
}
}
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp
index 626930e81..ebda40121 100644
--- a/src/libstate/libstate.cpp
+++ b/src/libstate/libstate.cpp
@@ -4,13 +4,39 @@
*************************************************/
#include <botan/libstate.h>
-#include <botan/modules.h>
#include <botan/engine.h>
#include <botan/stl_util.h>
#include <botan/mutex.h>
+#include <botan/mux_noop.h>
#include <botan/charset.h>
+#include <botan/defalloc.h>
+#include <botan/def_eng.h>
#include <algorithm>
+#if defined(BOTAN_HAS_MUTEX_PTHREAD)
+ #include <botan/mux_pthr.h>
+#elif defined(BOTAN_HAS_MUTEX_WIN32)
+ #include <botan/mux_win32.h>
+#elif defined(BOTAN_HAS_MUTEX_QT)
+ #include <botan/mux_qt.h>
+#endif
+
+#if defined(BOTAN_HAS_ALLOC_MMAP)
+ #include <botan/mmap_mem.h>
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_ASSEMBLER)
+ #include <botan/asm_engine.h>
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_GNU_MP)
+ #include <botan/eng_gmp.h>
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_OPENSSL)
+ #include <botan/eng_ossl.h>
+#endif
+
#if defined(BOTAN_HAS_SELFTEST)
#include <botan/selftest.h>
#endif
@@ -202,35 +228,59 @@ Algorithm_Factory& Library_State::algo_factory()
/*************************************************
* Load a set of modules *
*************************************************/
-void Library_State::initialize(const InitializerOptions& args,
- Modules& modules)
+void Library_State::initialize(const InitializerOptions& args)
{
if(mutex_factory)
throw Invalid_State("Library_State has already been initialized");
- mutex_factory = modules.mutex_factory(args.thread_safe());
-
- if(!mutex_factory)
- throw Invalid_State("Could not acquire a mutex module at init");
+ if(args.thread_safe() == false)
+ {
+ mutex_factory = new Noop_Mutex_Factory;
+ }
+ else
+ {
+#if defined(BOTAN_HAS_MUTEX_PTHREAD)
+ mutex_factory = new Pthread_Mutex_Factory;
+#elif defined(BOTAN_HAS_MUTEX_WIN32)
+ mutex_factory = new Win32_Mutex_Factory;
+#elif defined(BOTAN_HAS_MUTEX_QT)
+ mutex_factory Qt_Mutex_Factory;
+#else
+ throw Invalid_State("Could not find a thread-safe mutex object to use");
+#endif
+ }
- allocator_lock = get_mutex();
- config_lock = get_mutex();
+ allocator_lock = mutex_factory->make();
+ config_lock = mutex_factory->make();
cached_default_allocator = 0;
- std::vector<Allocator*> mod_allocs = modules.allocators(mutex_factory);
- for(u32bit j = 0; j != mod_allocs.size(); ++j)
- add_allocator(mod_allocs[j]);
+ add_allocator(new Locking_Allocator(mutex_factory->make()));
+ add_allocator(new Malloc_Allocator);
+ set_default_allocator("locking");
- set_default_allocator(modules.default_allocator());
+#if defined(BOTAN_HAS_ALLOC_MMAP)
+ add_allocator(new MemoryMapping_Allocator(mutex_factory->make()));
+ set_default_allocator("mmap");
+#endif
load_default_config();
algorithm_factory = new Algorithm_Factory;
- std::vector<Engine*> mod_engines = modules.engines();
- for(u32bit j = 0; j != mod_engines.size(); ++j)
- algorithm_factory->add_engine(mod_engines[j]);
+#if defined(BOTAN_HAS_ENGINE_GNU_MP)
+ algorithm_factory->add_engine(new GMP_Engine);
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_OPENSSL)
+ algorithm_factory->add_engine(new OpenSSL_Engine);
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_ASSEMBLER)
+ algorithm_factory->add_engine(new Assembler_Engine);
+#endif
+
+ algorithm_factory->add_engine(new Default_Engine);
#if defined(BOTAN_HAS_SELFTEST)
if(args.fips_mode() || args.self_test())
diff --git a/src/libstate/libstate.h b/src/libstate/libstate.h
index db0198923..f6ad70564 100644
--- a/src/libstate/libstate.h
+++ b/src/libstate/libstate.h
@@ -26,9 +26,7 @@ class BOTAN_DLL Library_State
Library_State();
~Library_State();
- void initialize(const InitializerOptions&, Modules&);
-
- void load(Modules&);
+ void initialize(const InitializerOptions&);
Algorithm_Factory& algo_factory();
diff --git a/src/libstate/modules.cpp b/src/libstate/modules.cpp
deleted file mode 100644
index 81508116d..000000000
--- a/src/libstate/modules.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/*************************************************
-* Module Factory Source File *
-* (C) 1999-2008 Jack Lloyd *
-*************************************************/
-
-#include <botan/modules.h>
-#include <botan/defalloc.h>
-#include <botan/parsing.h>
-
-#if defined(BOTAN_HAS_MUTEX_PTHREAD)
- #include <botan/mux_pthr.h>
-#elif defined(BOTAN_HAS_MUTEX_WIN32)
- #include <botan/mux_win32.h>
-#elif defined(BOTAN_HAS_MUTEX_QT)
- #include <botan/mux_qt.h>
-#endif
-
-#if defined(BOTAN_HAS_MUTEX_NOOP)
- #include <botan/mux_noop.h>
-#endif
-
-#if defined(BOTAN_HAS_ALLOC_MMAP)
- #include <botan/mmap_mem.h>
-#endif
-
-// Default engine
-#include <botan/def_eng.h>
-
-#if defined(BOTAN_HAS_ENGINE_ASSEMBLER)
- #include <botan/asm_engine.h>
-#endif
-
-#if defined(BOTAN_HAS_ENGINE_GNU_MP)
- #include <botan/eng_gmp.h>
-#endif
-
-#if defined(BOTAN_HAS_ENGINE_OPENSSL)
- #include <botan/eng_ossl.h>
-#endif
-
-namespace Botan {
-
-/*************************************************
-* Return a mutex factory, if available *
-*************************************************/
-Mutex_Factory* Builtin_Modules::mutex_factory(bool thread_safe) const
- {
- if(!thread_safe)
- {
-#if defined(BOTAN_HAS_MUTEX_NOOP)
- return new Noop_Mutex_Factory;
-#endif
- }
-
-#if defined(BOTAN_HAS_MUTEX_PTHREAD)
- return new Pthread_Mutex_Factory;
-#elif defined(BOTAN_HAS_MUTEX_WIN32)
- return new Win32_Mutex_Factory;
-#elif defined(BOTAN_HAS_MUTEX_QT)
- return new Qt_Mutex_Factory;
-#else
- return 0;
-#endif
- }
-
-/*************************************************
-* Find any usable allocators *
-*************************************************/
-std::vector<Allocator*> Builtin_Modules::allocators(Mutex_Factory* mf) const
- {
- std::vector<Allocator*> allocators;
-
-#if defined(BOTAN_HAS_ALLOC_MMAP)
- allocators.push_back(new MemoryMapping_Allocator(mf->make()));
-#endif
-
- allocators.push_back(new Locking_Allocator(mf->make()));
- allocators.push_back(new Malloc_Allocator);
-
- return allocators;
- }
-
-/*************************************************
-* Return the default allocator *
-*************************************************/
-std::string Builtin_Modules::default_allocator() const
- {
- if(should_lock)
- {
-#if defined(BOTAN_HAS_ALLOC_MMAP)
- return "mmap";
-#else
- return "locking";
-#endif
- }
- else
- return "malloc";
- }
-
-/*************************************************
-* Find any usable engines *
-*************************************************/
-std::vector<Engine*> Builtin_Modules::engines() const
- {
- std::vector<Engine*> engines;
-
- if(use_engines)
- {
-#if defined(BOTAN_HAS_ENGINE_GNU_MP)
- engines.push_back(new GMP_Engine);
-#endif
-
-#if defined(BOTAN_HAS_ENGINE_OPENSSL)
- engines.push_back(new OpenSSL_Engine);
-#endif
-
-#if defined(BOTAN_HAS_ENGINE_ASSEMBLER)
- engines.push_back(new Assembler_Engine);
-#endif
- }
-
- engines.push_back(new Default_Engine);
-
- return engines;
- }
-
-/*************************************************
-* Builtin_Modules Constructor *
-*************************************************/
-Builtin_Modules::Builtin_Modules(const InitializerOptions& args) :
- should_lock(args.secure_memory()),
- use_engines(args.use_engines())
- {
- }
-
-}
diff --git a/src/libstate/modules.h b/src/libstate/modules.h
deleted file mode 100644
index abbfbb2c6..000000000
--- a/src/libstate/modules.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*************************************************
-* Module Factory Header File *
-* (C) 1999-2008 Jack Lloyd *
-*************************************************/
-
-#ifndef BOTAN_MODULE_FACTORIES_H__
-#define BOTAN_MODULE_FACTORIES_H__
-
-#include <botan/init.h>
-#include <botan/mutex.h>
-#include <string>
-#include <vector>
-
-namespace Botan {
-
-/*************************************************
-* Module Builder Interface *
-*************************************************/
-class BOTAN_DLL Modules
- {
- public:
- virtual class Mutex_Factory* mutex_factory(bool) const = 0;
-
- virtual std::string default_allocator() const = 0;
-
- virtual std::vector<class Allocator*>
- allocators(Mutex_Factory*) const = 0;
-
- virtual std::vector<class Engine*> engines() const = 0;
-
- virtual ~Modules() {}
- };
-
-/*************************************************
-* Built In Modules *
-*************************************************/
-class BOTAN_DLL Builtin_Modules : public Modules
- {
- public:
- class Mutex_Factory* mutex_factory(bool) const;
-
- std::string default_allocator() const;
-
- std::vector<class Allocator*> allocators(Mutex_Factory*) const;
- std::vector<class Engine*> engines() const;
-
- Builtin_Modules(const InitializerOptions&);
- private:
- const bool should_lock, use_engines;
- };
-
-}
-
-#endif