aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-11 01:20:07 +0000
committerlloyd <[email protected]>2008-11-11 01:20:07 +0000
commite2d4cb5a9cd046453e79589d6c182bc23975ae4b (patch)
tree625606ebd58d58cfa9a80ee183e631a4fcda9b74 /src/libstate
parentcff0e94bf7fdf16243ed04aa54e613a516fbade9 (diff)
Move Algorithm_Factory from libstate (which it did not depend on) to algo_factory/
Diffstat (limited to 'src/libstate')
-rw-r--r--src/libstate/algo_factory.cpp248
-rw-r--r--src/libstate/algo_factory.h70
-rw-r--r--src/libstate/info.txt3
3 files changed, 1 insertions, 320 deletions
diff --git a/src/libstate/algo_factory.cpp b/src/libstate/algo_factory.cpp
deleted file mode 100644
index e4ddc473e..000000000
--- a/src/libstate/algo_factory.cpp
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
-Algorithm Factory
-(C) 2008 Jack Lloyd
-*/
-
-#include <botan/libstate.h>
-#include <botan/stl_util.h>
-#include <botan/engine.h>
-#include <botan/exceptn.h>
-
-#include <botan/block_cipher.h>
-#include <botan/stream_cipher.h>
-#include <botan/hash.h>
-#include <botan/mac.h>
-
-#include <algorithm>
-
-namespace Botan {
-
-/**
-* Delete all engines
-*/
-Algorithm_Factory::~Algorithm_Factory()
- {
- std::for_each(engines.begin(), engines.end(), del_fun<Engine>());
- engines.clear();
- }
-
-/**
-* Add a new engine to the list
-*/
-void Algorithm_Factory::add_engine(Engine* engine)
- {
- engines.push_back(engine);
- }
-
-/*************************************************
-* Get an engine out of the list *
-*************************************************/
-Engine* Algorithm_Factory::get_engine_n(u32bit n) const
- {
- if(n >= engines.size())
- return 0;
- return engines[n];
- }
-
-/**
-* Return the prototypical object cooresponding to this request
-*/
-const BlockCipher*
-Algorithm_Factory::prototype_block_cipher(const SCAN_Name& request)
- {
- for(u32bit i = 0; i != engines.size(); ++i)
- {
- if(request.provider_allowed(engines[i]->provider_name()))
- {
- const BlockCipher* algo =
- engines[i]->prototype_block_cipher(request, *this);
-
- if(algo)
- return algo;
- }
- }
-
- return 0;
- }
-
-/**
-* Return a new object cooresponding to this request
-*/
-BlockCipher* Algorithm_Factory::make_block_cipher(const SCAN_Name& request)
- {
- const BlockCipher* prototype = prototype_block_cipher(request);
- if(prototype)
- return prototype->clone();
-
- throw Algorithm_Not_Found(request.as_string());
- }
-
-/**
-* Add a new object
-*/
-void Algorithm_Factory::add_block_cipher(BlockCipher* hash)
- {
- for(u32bit i = 0; i != engines.size(); ++i)
- {
- if(engines[i]->can_add_algorithms())
- {
- engines[i]->add_algorithm(hash);
- return;
- }
- }
-
- throw Exception("Algorithm_Factory::add_block_cipher: No engine found");
- }
-
-/**
-* Return the prototypical object cooresponding to this request
-*/
-const StreamCipher*
-Algorithm_Factory::prototype_stream_cipher(const SCAN_Name& request)
- {
- for(u32bit i = 0; i != engines.size(); ++i)
- {
- if(request.provider_allowed(engines[i]->provider_name()))
- {
- const StreamCipher* algo =
- engines[i]->prototype_stream_cipher(request, *this);
-
- if(algo)
- return algo;
- }
- }
-
- return 0;
- }
-
-/**
-* Return a new object cooresponding to this request
-*/
-StreamCipher* Algorithm_Factory::make_stream_cipher(const SCAN_Name& request)
- {
- const StreamCipher* prototype = prototype_stream_cipher(request);
- if(prototype)
- return prototype->clone();
-
- throw Algorithm_Not_Found(request.as_string());
- }
-
-/**
-* Add a new object
-*/
-void Algorithm_Factory::add_stream_cipher(StreamCipher* hash)
- {
- for(u32bit i = 0; i != engines.size(); ++i)
- {
- if(engines[i]->can_add_algorithms())
- {
- engines[i]->add_algorithm(hash);
- return;
- }
- }
-
- throw Exception("Algorithm_Factory::add_stream_cipher: No engine found");
- }
-
-/**
-* Return the prototypical object cooresponding to this request
-*/
-const HashFunction*
-Algorithm_Factory::prototype_hash_function(const SCAN_Name& request)
- {
- 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;
- }
-
-/**
-* Return a new object cooresponding to this request
-*/
-HashFunction* Algorithm_Factory::make_hash_function(const SCAN_Name& request)
- {
- const HashFunction* prototype = prototype_hash_function(request);
- if(prototype)
- return prototype->clone();
-
- throw Algorithm_Not_Found(request.as_string());
- }
-
-/**
-* Add a new object
-*/
-void Algorithm_Factory::add_hash_function(HashFunction* hash)
- {
- for(u32bit i = 0; i != engines.size(); ++i)
- {
- if(engines[i]->can_add_algorithms())
- {
- engines[i]->add_algorithm(hash);
- return;
- }
- }
-
- throw Exception("Algorithm_Factory::add_hash_function: No engine found");
- }
-
-/**
-* Return the prototypical object cooresponding to this request
-*/
-const MessageAuthenticationCode*
-Algorithm_Factory::prototype_mac(const SCAN_Name& request)
- {
- for(u32bit i = 0; i != engines.size(); ++i)
- {
- if(request.provider_allowed(engines[i]->provider_name()))
- {
- const MessageAuthenticationCode* algo =
- engines[i]->prototype_mac(request, *this);
-
- if(algo)
- return algo;
- }
- }
-
- return 0;
- }
-
-/**
-* Return a new object cooresponding to this request
-*/
-MessageAuthenticationCode*
-Algorithm_Factory::make_mac(const SCAN_Name& request)
- {
- const MessageAuthenticationCode* prototype = prototype_mac(request);
- if(prototype)
- return prototype->clone();
-
- throw Algorithm_Not_Found(request.as_string());
- }
-
-/**
-* Add a new object
-*/
-void Algorithm_Factory::add_mac(MessageAuthenticationCode* hash)
- {
- for(u32bit i = 0; i != engines.size(); ++i)
- {
- if(engines[i]->can_add_algorithms())
- {
- engines[i]->add_algorithm(hash);
- return;
- }
- }
-
- throw Exception("Algorithm_Factory::add_mac: No engine found");
- }
-
-}
diff --git a/src/libstate/algo_factory.h b/src/libstate/algo_factory.h
deleted file mode 100644
index 2513c42c9..000000000
--- a/src/libstate/algo_factory.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
-* Algorithm Factory
-* (C) 2008 Jack Lloyd
-*/
-
-#ifndef BOTAN_ALGORITHM_FACTORY_H__
-#define BOTAN_ALGORITHM_FACTORY_H__
-
-#include <botan/scan_name.h>
-#include <botan/mutex.h>
-#include <string>
-#include <vector>
-
-namespace Botan {
-
-class BlockCipher;
-class StreamCipher;
-class HashFunction;
-class MessageAuthenticationCode;
-
-/**
-* Algorithm Factory
-*/
-class BOTAN_DLL Algorithm_Factory
- {
- public:
- ~Algorithm_Factory();
-
- void add_engine(class Engine*);
-
- class BOTAN_DLL Engine_Iterator
- {
- public:
- class Engine* next() { return af.get_engine_n(n++); }
- Engine_Iterator(const Algorithm_Factory& a) : af(a) { n = 0; }
- private:
- const Algorithm_Factory& af;
- u32bit n;
- };
- friend class Engine_Iterator;
-
- // Block cipher operations
- const BlockCipher* prototype_block_cipher(const SCAN_Name& request);
- BlockCipher* make_block_cipher(const SCAN_Name& request);
- void add_block_cipher(BlockCipher* hash);
-
- // Stream cipher operations
- const StreamCipher* prototype_stream_cipher(const SCAN_Name& request);
- StreamCipher* make_stream_cipher(const SCAN_Name& request);
- void add_stream_cipher(StreamCipher* hash);
-
- // Hash function operations
- const HashFunction* prototype_hash_function(const SCAN_Name& request);
- HashFunction* make_hash_function(const SCAN_Name& request);
- void add_hash_function(HashFunction* hash);
-
- // MAC operations
- const MessageAuthenticationCode* prototype_mac(const SCAN_Name& request);
- MessageAuthenticationCode* make_mac(const SCAN_Name& request);
- void add_mac(MessageAuthenticationCode* mac);
-
- private:
- class Engine* get_engine_n(u32bit) const;
-
- std::vector<class Engine*> engines;
- };
-
-}
-
-#endif
diff --git a/src/libstate/info.txt b/src/libstate/info.txt
index e5d591406..409b54343 100644
--- a/src/libstate/info.txt
+++ b/src/libstate/info.txt
@@ -5,6 +5,7 @@ load_on auto
define LIBSTATE_MODULE
<requires>
+algo_factory
def_engine
mode_pad
pk_pad
@@ -13,8 +14,6 @@ system_alloc
</requires>
<add>
-algo_factory.cpp
-algo_factory.h
botan.h
get_enc.cpp
init.h