aboutsummaryrefslogtreecommitdiffstats
path: root/include/engine.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-09-06 00:04:25 +0000
committerlloyd <[email protected]>2006-09-06 00:04:25 +0000
commitd65f9a38be079c52257dff6663b816de206ce99d (patch)
tree28ed7458485f1a29cfde7fa342f73cbb3a8e327a /include/engine.h
parent764889d31e7034ebb8fe4fc879e565b474449564 (diff)
Change Engine to not rely on the existence of an Algorithm base class for
the various types it wants to cache.
Diffstat (limited to 'include/engine.h')
-rw-r--r--include/engine.h33
1 files changed, 27 insertions, 6 deletions
diff --git a/include/engine.h b/include/engine.h
index d28095b71..101138e8a 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -22,6 +22,15 @@ namespace Botan {
class Engine
{
public:
+ template<typename T>
+ class Algorithm_Cache
+ {
+ public:
+ virtual T* get(const std::string&) const = 0;
+ virtual void add(T* algo) const = 0;
+ virtual ~Algorithm_Cache() {}
+ };
+
virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
const BigInt&, const BigInt&, const BigInt&,
const BigInt&, const BigInt&) const;
@@ -64,12 +73,24 @@ class Engine
virtual class BlockCipherModePaddingMethod*
find_bc_pad(const std::string&) const;
- Algorithm* get_algo(const std::string&, const std::string&) const;
- void add_algo(const std::string&, Algorithm*) const;
-
- typedef std::pair<Mutex*, std::map<std::string, Algorithm*> >
- mutex_map_pair;
- mutable std::map<std::string, mutex_map_pair> mappings;
+ template<typename T>
+ T* lookup_algo(const Algorithm_Cache<T>* cache,
+ const std::string& name,
+ const Engine* engine,
+ T* (Engine::*find)(const std::string& name) const) const
+ {
+ T* algo = cache->get(name);
+ if(!algo)
+ cache->add(algo = (engine->*find)(name));
+ return algo;
+ }
+
+ Algorithm_Cache<BlockCipher>* cache_of_bc;
+ Algorithm_Cache<StreamCipher>* cache_of_sc;
+ Algorithm_Cache<HashFunction>* cache_of_hf;
+ Algorithm_Cache<MessageAuthenticationCode>* cache_of_mac;
+ Algorithm_Cache<BlockCipherModePaddingMethod>* cache_of_bc_pad;
+ Algorithm_Cache<S2K>* cache_of_s2k;
};
namespace Engine_Core {