aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-24 13:52:11 +0000
committerlloyd <[email protected]>2010-03-24 13:52:11 +0000
commit550dc44e247dfb5a8cbac0afcfc065fb6990c386 (patch)
tree58eaff59749bfd9130e8de811f5d7f5a036b06d1 /src
parent24aba24f73f1717548b82f1d6bf8e4f773afa015 (diff)
Allow adding engines dynamically
Diffstat (limited to 'src')
-rw-r--r--src/algo_factory/algo_factory.cpp10
-rw-r--r--src/algo_factory/algo_factory.h9
-rw-r--r--src/libstate/libstate.cpp18
3 files changed, 20 insertions, 17 deletions
diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp
index ad8b1215f..030a32b9f 100644
--- a/src/algo_factory/algo_factory.cpp
+++ b/src/algo_factory/algo_factory.cpp
@@ -83,11 +83,8 @@ const T* factory_prototype(const std::string& algo_spec,
/**
* Setup caches
*/
-Algorithm_Factory::Algorithm_Factory(const std::vector<Engine*>& engines_in,
- Mutex_Factory& mf)
+Algorithm_Factory::Algorithm_Factory(Mutex_Factory& mf)
{
- engines = engines_in;
-
block_cipher_cache = new Algorithm_Cache<BlockCipher>(mf.make());
stream_cipher_cache = new Algorithm_Cache<StreamCipher>(mf.make());
hash_cache = new Algorithm_Cache<HashFunction>(mf.make());
@@ -107,6 +104,11 @@ Algorithm_Factory::~Algorithm_Factory()
delete mac_cache;
}
+void Algorithm_Factory::add_engine(Engine* engine)
+ {
+ engines.push_back(engine);
+ }
+
/**
* Set the preferred provider for an algorithm
*/
diff --git a/src/algo_factory/algo_factory.h b/src/algo_factory/algo_factory.h
index 3b479c2d7..0b630c721 100644
--- a/src/algo_factory/algo_factory.h
+++ b/src/algo_factory/algo_factory.h
@@ -35,11 +35,9 @@ class BOTAN_DLL Algorithm_Factory
public:
/**
* Constructor
- * @param engines_in the list of engines to use
* @param mf a mutex factory
*/
- Algorithm_Factory(const std::vector<Engine*>& engines_in,
- Mutex_Factory& mf);
+ Algorithm_Factory(Mutex_Factory& mf);
/**
* Destructor
@@ -47,6 +45,11 @@ class BOTAN_DLL Algorithm_Factory
~Algorithm_Factory();
/**
+ * @param engine to add (Algorithm_Factory takes ownership)
+ */
+ void add_engine(class Engine* engine);
+
+ /**
* @param algo_spec the algorithm we are querying
* @returns list of providers of this algorithm
*/
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp
index 1b09a21ee..1a980b95f 100644
--- a/src/libstate/libstate.cpp
+++ b/src/libstate/libstate.cpp
@@ -278,35 +278,33 @@ void Library_State::initialize(bool thread_safe)
load_default_config();
- std::vector<Engine*> engines;
+ m_algorithm_factory = new Algorithm_Factory(*mutex_factory);
#if defined(BOTAN_HAS_ENGINE_GNU_MP)
- engines.push_back(new GMP_Engine);
+ algorithm_factory().add_engine(new GMP_Engine);
#endif
#if defined(BOTAN_HAS_ENGINE_OPENSSL)
- engines.push_back(new OpenSSL_Engine);
+ algorithm_factory().add_engine(new OpenSSL_Engine);
#endif
#if defined(BOTAN_HAS_ENGINE_AES_ISA)
- engines.push_back(new AES_ISA_Engine);
+ algorithm_factory().add_engine(new AES_ISA_Engine);
#endif
#if defined(BOTAN_HAS_ENGINE_SIMD)
- engines.push_back(new SIMD_Engine);
+ algorithm_factory().add_engine(new SIMD_Engine);
#endif
#if defined(BOTAN_HAS_ENGINE_AMD64_ASSEMBLER)
- engines.push_back(new AMD64_Assembler_Engine);
+ algorithm_factory().add_engine(new AMD64_Assembler_Engine);
#endif
#if defined(BOTAN_HAS_ENGINE_IA32_ASSEMBLER)
- engines.push_back(new IA32_Assembler_Engine);
+ algorithm_factory().add_engine(new IA32_Assembler_Engine);
#endif
- engines.push_back(new Default_Engine);
-
- m_algorithm_factory = new Algorithm_Factory(engines, *mutex_factory);
+ algorithm_factory().add_engine(new Default_Engine);
#if defined(BOTAN_HAS_SELFTESTS)
confirm_startup_self_tests(algorithm_factory());