aboutsummaryrefslogtreecommitdiffstats
path: root/src/algo_factory
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-11 18:18:03 +0000
committerlloyd <[email protected]>2008-11-11 18:18:03 +0000
commit1befa604ad62332aab1729d023c89556e63332c7 (patch)
treefa0746f956f414d0e844f6711e7762e2e5a1d9fb /src/algo_factory
parent237258e42f4b1b8c01d91518270c4a9c59a0dc47 (diff)
Fix algo_cache to track aliases, all tests pass
Diffstat (limited to 'src/algo_factory')
-rw-r--r--src/algo_factory/algo_cache.h25
-rw-r--r--src/algo_factory/algo_factory.cpp33
2 files changed, 27 insertions, 31 deletions
diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h
index ab6778d14..c6d2ebdac 100644
--- a/src/algo_factory/algo_cache.h
+++ b/src/algo_factory/algo_cache.h
@@ -18,13 +18,17 @@ class Algorithm_Cache
{
public:
const T* get(const SCAN_Name& request);
- void add(T* algo, const std::string& provider);
+ void add(T* algo,
+ const std::string& requested_name,
+ const std::string& provider);
Algorithm_Cache(Mutex* m) : mutex(m) {}
~Algorithm_Cache();
private:
Mutex* mutex;
+ std::map<std::string, std::string> aliases;
std::map<std::string, std::map<std::string, T*> > algorithms;
+
typedef typename std::map<std::string, std::map<std::string, T*> >::iterator algorithms_iterator;
typedef typename std::map<std::string, T*>::iterator provider_iterator;
};
@@ -39,10 +43,20 @@ const T* Algorithm_Cache<T>::get(const SCAN_Name& request)
algorithms_iterator algo = algorithms.find(request.as_string());
+ // Not found? Check if a known alias
+ if(algo == algorithms.end())
+ {
+ std::map<std::string, std::string>::const_iterator alias =
+ aliases.find(request.as_string());
+
+ if(alias != aliases.end())
+ algo = algorithms.find(alias->second);
+ }
+
if(algo == algorithms.end())
return 0;
- const std::string requested_provider = request.providers_string();
+ const std::string requested_provider = request.provider();
if(requested_provider != "")
{
@@ -71,7 +85,9 @@ const T* Algorithm_Cache<T>::get(const SCAN_Name& request)
* Add an implementation to the cache
*/
template<typename T>
-void Algorithm_Cache<T>::add(T* algo, const std::string& provider)
+void Algorithm_Cache<T>::add(T* algo,
+ const std::string& requested_name,
+ const std::string& provider)
{
if(!algo)
return;
@@ -80,6 +96,9 @@ void Algorithm_Cache<T>::add(T* algo, const std::string& provider)
delete algorithms[algo->name()][provider];
algorithms[algo->name()][provider] = algo;
+
+ if(algo->name() != requested_name && aliases.find(requested_name) == aliases.end())
+ aliases[requested_name] = algo->name();
}
/**
diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp
index 1f49a0d48..4f137d636 100644
--- a/src/algo_factory/algo_factory.cpp
+++ b/src/algo_factory/algo_factory.cpp
@@ -178,47 +178,24 @@ void Algorithm_Factory::add_stream_cipher(StreamCipher* hash)
}
/**
-* Return the prototypical object cooresponding to this request
+* Return the prototypical object cooresponding to this request (if found)
*/
const HashFunction*
Algorithm_Factory::prototype_hash_function(const SCAN_Name& request)
{
-#if 1
- for(u32bit i = 0; i != engines.size(); ++i)
- {
- if(request.provider_allowed(engines[i]->provider_name()))
- {
- const HashFunction* algo =
- engines[i]->prototype_hash_function(request, *this);
-
- if(algo)
- return algo;
- }
- }
-
- return 0;
-#else
const HashFunction* cache_hit = hash_cache.get(request);
if(cache_hit)
return cache_hit;
- // Search for all providers of this algorithm and add them to the cache
for(u32bit i = 0; i != engines.size(); ++i)
{
- const std::string provider = engines[i]->provider_name();
- HashFunction* impl = engines[i]->find_hash(request, *this);
-
- if(impl)
- hash_cache.add(impl, provider);
+ if(HashFunction* impl = engines[i]->find_hash(request, *this))
+ {
+ hash_cache.add(impl, request.as_string(), engines[i]->provider_name());
+ }
}
- /* Now try the cache search again (if the providers don't match up
- with ones that exist in this build, this might still fail and
- return 0).
- */
-
return hash_cache.get(request);
-#endif
}
/**