diff options
author | lloyd <[email protected]> | 2008-11-10 21:14:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-10 21:14:59 +0000 |
commit | 04280f4ff97d842a4af15f2e4ea2b87e6095b126 (patch) | |
tree | bf56e261ab2ef6b033b7e0761868eb0437e9e12d /src/libstate/lookup.cpp | |
parent | 13a012955bf68d028ee0cd515e49137b7d95f5e6 (diff) |
Move MACs also to Algorithm_Factory
Diffstat (limited to 'src/libstate/lookup.cpp')
-rw-r--r-- | src/libstate/lookup.cpp | 91 |
1 files changed, 34 insertions, 57 deletions
diff --git a/src/libstate/lookup.cpp b/src/libstate/lookup.cpp index f53b1a099..501f973b0 100644 --- a/src/libstate/lookup.cpp +++ b/src/libstate/lookup.cpp @@ -43,6 +43,40 @@ bool have_hash(const std::string& algo_spec) } /************************************************* +* Acquire an authentication code * +*************************************************/ +const MessageAuthenticationCode* retrieve_mac(Library_State& libstate, + const std::string& algo_spec) + { + return libstate.algo_factory().prototype_mac(algo_spec); + } + +/************************************************* +* Get a MAC by name * +*************************************************/ +MessageAuthenticationCode* get_mac(const std::string& algo_spec) + { + return global_state().algo_factory().make_mac(algo_spec); + } + +/************************************************* +* Query if Botan has the named MAC * +*************************************************/ +bool have_mac(const std::string& algo_spec) + { + return global_state().algo_factory().prototype_mac(algo_spec); + } + +/************************************************* +* Add a new authentication code * +*************************************************/ +void add_algorithm(Library_State& libstate, + MessageAuthenticationCode* algo) + { + libstate.algo_factory().add_mac(algo); + } + +/************************************************* * Get a block cipher by name * *************************************************/ BlockCipher* get_block_cipher(const std::string& name) @@ -65,17 +99,6 @@ StreamCipher* get_stream_cipher(const std::string& name) } /************************************************* -* Get a MAC by name * -*************************************************/ -MessageAuthenticationCode* get_mac(const std::string& name) - { - const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); - if(mac) - return mac->clone(); - throw Algorithm_Not_Found(name); - } - -/************************************************* * Query if an algorithm exists * *************************************************/ bool have_algorithm(const std::string& name) @@ -108,14 +131,6 @@ bool have_stream_cipher(const std::string& name) } /************************************************* -* Query if Botan has the named MAC * -*************************************************/ -bool have_mac(const std::string& name) - { - return (retrieve_mac(global_state(), name) != 0); - } - -/************************************************* * Query the block size of a cipher or hash * *************************************************/ u32bit block_size_of(const std::string& name) @@ -264,24 +279,6 @@ const StreamCipher* retrieve_stream_cipher(Library_State& libstate, } /************************************************* -* Acquire an authentication code * -*************************************************/ -const MessageAuthenticationCode* retrieve_mac(Library_State& libstate, - const std::string& name) - { - Algorithm_Factory::Engine_Iterator i(libstate.algo_factory()); - - while(const Engine* engine = i.next()) - { - const MessageAuthenticationCode* algo = engine->mac(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* * Add a new block cipher * *************************************************/ void add_algorithm(Library_State& libstate, BlockCipher* algo) @@ -320,26 +317,6 @@ void add_algorithm(Library_State& libstate, StreamCipher* algo) } /************************************************* -* Add a new authentication code * -*************************************************/ -void add_algorithm(Library_State& libstate, - MessageAuthenticationCode* algo) - { - Algorithm_Factory::Engine_Iterator i(libstate.algo_factory()); - - while(Engine* engine = i.next()) - { - if(engine->can_add_algorithms()) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* * Get a cipher object * *************************************************/ Keyed_Filter* get_cipher(const std::string& algo_spec, |