From 802cda3710610cafc328a82fb7997e3e01bbcf8d Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 8 Nov 2008 21:37:40 +0000 Subject: Add virtual hook to remove dep of Default_Engine on Engine itself --- src/engine/def_engine/eng_def.h | 2 ++ src/engine/engine.cpp | 26 ++++++++++---------------- src/engine/engine.h | 2 ++ 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/engine/def_engine/eng_def.h b/src/engine/def_engine/eng_def.h index 36ef14a69..3d3fba809 100644 --- a/src/engine/def_engine/eng_def.h +++ b/src/engine/def_engine/eng_def.h @@ -55,6 +55,8 @@ class BOTAN_DLL Default_Engine : public Engine Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints) const; + virtual bool can_add_algorithms() { return true; } + Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); private: BlockCipher* find_block_cipher(const std::string&) const; diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index ce32fa3b4..75b49b6a6 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -7,7 +7,6 @@ #include #include #include -#include namespace Botan { @@ -287,10 +286,9 @@ void add_algorithm(Library_State& libstate, BlockCipher* algo) { Library_State::Engine_Iterator i(libstate); - while(Engine* engine_base = i.next()) + while(Engine* engine = i.next()) { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) + if(engine->can_add_algorithms()) { engine->add_algorithm(algo); return; @@ -307,10 +305,9 @@ void add_algorithm(Library_State& libstate, StreamCipher* algo) { Library_State::Engine_Iterator i(libstate); - while(Engine* engine_base = i.next()) + while(Engine* engine = i.next()) { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) + if(engine->can_add_algorithms()) { engine->add_algorithm(algo); return; @@ -327,10 +324,9 @@ void add_algorithm(Library_State& libstate, HashFunction* algo) { Library_State::Engine_Iterator i(libstate); - while(Engine* engine_base = i.next()) + while(Engine* engine = i.next()) { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) + if(engine->can_add_algorithms()) { engine->add_algorithm(algo); return; @@ -348,10 +344,9 @@ void add_algorithm(Library_State& libstate, { Library_State::Engine_Iterator i(libstate); - while(Engine* engine_base = i.next()) + while(Engine* engine = i.next()) { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) + if(engine->can_add_algorithms()) { engine->add_algorithm(algo); return; @@ -369,10 +364,9 @@ void add_algorithm(Library_State& libstate, { Library_State::Engine_Iterator i(libstate); - while(Engine* engine_base = i.next()) + while(Engine* engine = i.next()) { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) + if(engine->can_add_algorithms()) { engine->add_algorithm(algo); return; diff --git a/src/engine/engine.h b/src/engine/engine.h index d7fae2348..f21c67a79 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -122,6 +122,8 @@ class BOTAN_DLL Engine const class BlockCipherModePaddingMethod* bc_pad(const std::string&) const; + virtual bool can_add_algorithms() { return false; } + void add_algorithm(BlockCipher*) const; void add_algorithm(StreamCipher*) const; void add_algorithm(HashFunction*) const; -- cgit v1.2.3