diff options
author | lloyd <[email protected]> | 2010-02-24 02:18:55 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-02-24 02:18:55 +0000 |
commit | 6e50979c8d2a0635599228a2ae1a20d59b24a0c6 (patch) | |
tree | 587aaf6c20d45a6fa81ee180ca0aa533f51403d1 /src/libstate | |
parent | 888fc3d0f2f6f1dc5e9764e83e9b7fd64da916d8 (diff) | |
parent | 8c951ef2f1e54e1134e8db683662ec881df89c88 (diff) |
propagate from branch 'net.randombit.botan' (head 84baf58b29f3aaaee34e2b873d0040be5a6c4368)
to branch 'net.randombit.botan.gost_3410' (head 63cbe3e357c071d7960bfedc31101eff35895285)
Diffstat (limited to 'src/libstate')
-rw-r--r-- | src/libstate/libstate.cpp | 3 | ||||
-rw-r--r-- | src/libstate/libstate.h | 51 | ||||
-rw-r--r-- | src/libstate/lookup.cpp | 179 | ||||
-rw-r--r-- | src/libstate/lookup.h | 131 | ||||
-rw-r--r-- | src/libstate/policy.cpp | 9 | ||||
-rw-r--r-- | src/libstate/scan_name.cpp | 17 | ||||
-rw-r--r-- | src/libstate/scan_name.h | 4 |
7 files changed, 186 insertions, 208 deletions
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 9ac15e381..919b12494 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -316,8 +316,7 @@ void Library_State::initialize(bool thread_safe) m_algorithm_factory = new Algorithm_Factory(engines, *mutex_factory); #if defined(BOTAN_HAS_SELFTESTS) - if(!passes_self_tests(algorithm_factory())) - throw Self_Test_Failure("Startup self tests failed"); + confirm_startup_self_tests(algorithm_factory()); #endif } diff --git a/src/libstate/libstate.h b/src/libstate/libstate.h index a0421953e..d5c442214 100644 --- a/src/libstate/libstate.h +++ b/src/libstate/libstate.h @@ -18,6 +18,8 @@ namespace Botan { +class Mutex; + /* * Global State Container Base */ @@ -29,11 +31,28 @@ class BOTAN_DLL Library_State void initialize(bool thread_safe); + /** + * @return the global Algorithm_Factory + */ Algorithm_Factory& algorithm_factory(); - Allocator* get_allocator(const std::string& = "") const; - void add_allocator(Allocator*); - void set_default_allocator(const std::string&); + /** + * @param name the name of the allocator + * @return allocator matching this name, or NULL + */ + Allocator* get_allocator(const std::string& name = "") const; + + /** + * Add a new allocator to the list of available ones + * @param alloc the allocator to add + */ + void add_allocator(Allocator* alloc); + + /** + * Set the default allocator + * @param name the name of the allocator to use as the default + */ + void set_default_allocator(const std::string& name); /** * Get a parameter value as std::string. @@ -52,7 +71,8 @@ class BOTAN_DLL Library_State * @result true if the parameters value is set, * false otherwise */ - bool is_set(const std::string& section, const std::string& key) const; + bool is_set(const std::string& section, + const std::string& key) const; /** * Set a configuration parameter. @@ -62,8 +82,10 @@ class BOTAN_DLL Library_State * will be overwritten even if it is already set, otherwise * no existing values will be overwritten. */ - void set(const std::string& section, const std::string& key, - const std::string& value, bool overwrite = true); + void set(const std::string& section, + const std::string& key, + const std::string& value, + bool overwrite = true); /** * Get a parameters value out of the "conf" section ( @@ -77,23 +99,28 @@ class BOTAN_DLL Library_State * @param key the key of the option to set * @param value the value to set */ - void set_option(const std::string& key, const std::string& value); + void set_option(const std::string& key, + const std::string& value); /** * Add a parameter value to the "alias" section. * @param key the name of the parameter which shall have a new alias * @param value the new alias */ - void add_alias(const std::string&, const std::string&); + void add_alias(const std::string& key, + const std::string& value); /** * Resolve an alias. * @param alias the alias to resolve. * @return what the alias stands for */ - std::string deref_alias(const std::string&) const; + std::string deref_alias(const std::string& alias) const; - class Mutex* get_mutex() const; + /** + * @return a newly created Mutex (free with delete) + */ + Mutex* get_mutex() const; private: void load_default_config(); @@ -103,9 +130,9 @@ class BOTAN_DLL Library_State class Mutex_Factory* mutex_factory; std::map<std::string, std::string> config; - class Mutex* config_lock; + Mutex* config_lock; - class Mutex* allocator_lock; + Mutex* allocator_lock; std::map<std::string, Allocator*> alloc_factory; mutable Allocator* cached_default_allocator; std::vector<Allocator*> allocators; diff --git a/src/libstate/lookup.cpp b/src/libstate/lookup.cpp index 9016dbe6e..01f4a3d42 100644 --- a/src/libstate/lookup.cpp +++ b/src/libstate/lookup.cpp @@ -12,138 +12,34 @@ namespace Botan { /** -* Acquire a block cipher -*/ -const BlockCipher* retrieve_block_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.prototype_block_cipher(algo_spec); - } - -/** -* Get a block cipher by name -*/ -BlockCipher* get_block_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.make_block_cipher(algo_spec); - } - -/** -* Acquire a stream cipher -*/ -const StreamCipher* retrieve_stream_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.prototype_stream_cipher(algo_spec); - } - -/** -* Get a stream cipher by name -*/ -StreamCipher* get_stream_cipher(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.make_stream_cipher(algo_spec); - } - -/** -* Acquire a hash function -*/ -const HashFunction* retrieve_hash(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.prototype_hash_function(algo_spec); - } - -/** -* Get a hash function by name -*/ -HashFunction* get_hash(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.make_hash_function(algo_spec); - } - -/** -* Query if Botan has the named hash function -*/ -bool have_hash(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return (af.prototype_hash_function(algo_spec) != 0); - } - -/** -* Acquire an authentication code -*/ -const MessageAuthenticationCode* retrieve_mac(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.prototype_mac(algo_spec); - } - -/** -* Get a MAC by name -*/ -MessageAuthenticationCode* get_mac(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return af.make_mac(algo_spec); - } - -/** -* Query if Botan has the named MAC -*/ -bool have_mac(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - return (af.prototype_mac(algo_spec) != 0); - } - -/** * Query if an algorithm exists */ bool have_algorithm(const std::string& name) { - if(retrieve_block_cipher(name)) + Algorithm_Factory& af = global_state().algorithm_factory(); + + if(af.prototype_block_cipher(name)) return true; - if(retrieve_stream_cipher(name)) + if(af.prototype_stream_cipher(name)) return true; - if(retrieve_hash(name)) + if(af.prototype_hash_function(name)) return true; - if(retrieve_mac(name)) + if(af.prototype_mac(name)) return true; return false; } /** -* Query if Botan has the named block cipher -*/ -bool have_block_cipher(const std::string& name) - { - return (retrieve_block_cipher(name) != 0); - } - -/** -* Query if Botan has the named stream cipher -*/ -bool have_stream_cipher(const std::string& name) - { - return (retrieve_stream_cipher(name) != 0); - } - -/** * Query the block size of a cipher or hash */ u32bit block_size_of(const std::string& name) { - const BlockCipher* cipher = retrieve_block_cipher(name); - if(cipher) + Algorithm_Factory& af = global_state().algorithm_factory(); + + if(const BlockCipher* cipher = af.prototype_block_cipher(name)) return cipher->BLOCK_SIZE; - const HashFunction* hash = retrieve_hash(name); - if(hash) + if(const HashFunction* hash = af.prototype_hash_function(name)) return hash->HASH_BLOCK_SIZE; throw Algorithm_Not_Found(name); @@ -154,12 +50,12 @@ u32bit block_size_of(const std::string& name) */ u32bit output_length_of(const std::string& name) { - const HashFunction* hash = retrieve_hash(name); - if(hash) + Algorithm_Factory& af = global_state().algorithm_factory(); + + if(const HashFunction* hash = af.prototype_hash_function(name)) return hash->OUTPUT_LENGTH; - const MessageAuthenticationCode* mac = retrieve_mac(name); - if(mac) + if(const MessageAuthenticationCode* mac = af.prototype_mac(name)) return mac->OUTPUT_LENGTH; throw Algorithm_Not_Found(name); @@ -170,16 +66,15 @@ u32bit output_length_of(const std::string& name) */ bool valid_keylength_for(u32bit key_len, const std::string& name) { - const BlockCipher* bc = retrieve_block_cipher(name); - if(bc) + Algorithm_Factory& af = global_state().algorithm_factory(); + + if(const BlockCipher* bc = af.prototype_block_cipher(name)) return bc->valid_keylength(key_len); - const StreamCipher* sc = retrieve_stream_cipher(name); - if(sc) + if(const StreamCipher* sc = af.prototype_stream_cipher(name)) return sc->valid_keylength(key_len); - const MessageAuthenticationCode* mac = retrieve_mac(name); - if(mac) + if(const MessageAuthenticationCode* mac = af.prototype_mac(name)) return mac->valid_keylength(key_len); throw Algorithm_Not_Found(name); @@ -190,16 +85,15 @@ bool valid_keylength_for(u32bit key_len, const std::string& name) */ u32bit min_keylength_of(const std::string& name) { - const BlockCipher* bc = retrieve_block_cipher(name); - if(bc) + Algorithm_Factory& af = global_state().algorithm_factory(); + + if(const BlockCipher* bc = af.prototype_block_cipher(name)) return bc->MINIMUM_KEYLENGTH; - const StreamCipher* sc = retrieve_stream_cipher(name); - if(sc) + if(const StreamCipher* sc = af.prototype_stream_cipher(name)) return sc->MINIMUM_KEYLENGTH; - const MessageAuthenticationCode* mac = retrieve_mac(name); - if(mac) + if(const MessageAuthenticationCode* mac = af.prototype_mac(name)) return mac->MINIMUM_KEYLENGTH; throw Algorithm_Not_Found(name); @@ -210,16 +104,15 @@ u32bit min_keylength_of(const std::string& name) */ u32bit max_keylength_of(const std::string& name) { - const BlockCipher* bc = retrieve_block_cipher(name); - if(bc) + Algorithm_Factory& af = global_state().algorithm_factory(); + + if(const BlockCipher* bc = af.prototype_block_cipher(name)) return bc->MAXIMUM_KEYLENGTH; - const StreamCipher* sc = retrieve_stream_cipher(name); - if(sc) + if(const StreamCipher* sc = af.prototype_stream_cipher(name)) return sc->MAXIMUM_KEYLENGTH; - const MessageAuthenticationCode* mac = retrieve_mac(name); - if(mac) + if(const MessageAuthenticationCode* mac = af.prototype_mac(name)) return mac->MAXIMUM_KEYLENGTH; throw Algorithm_Not_Found(name); @@ -230,16 +123,15 @@ u32bit max_keylength_of(const std::string& name) */ u32bit keylength_multiple_of(const std::string& name) { - const BlockCipher* bc = retrieve_block_cipher(name); - if(bc) + Algorithm_Factory& af = global_state().algorithm_factory(); + + if(const BlockCipher* bc = af.prototype_block_cipher(name)) return bc->KEYLENGTH_MULTIPLE; - const StreamCipher* sc = retrieve_stream_cipher(name); - if(sc) + if(const StreamCipher* sc = af.prototype_stream_cipher(name)) return sc->KEYLENGTH_MULTIPLE; - const MessageAuthenticationCode* mac = retrieve_mac(name); - if(mac) + if(const MessageAuthenticationCode* mac = af.prototype_mac(name)) return mac->KEYLENGTH_MULTIPLE; throw Algorithm_Not_Found(name); @@ -257,8 +149,7 @@ Keyed_Filter* get_cipher(const std::string& algo_spec, while(Engine* engine = i.next()) { - Keyed_Filter* algo = engine->get_cipher(algo_spec, direction, af); - if(algo) + if(Keyed_Filter* algo = engine->get_cipher(algo_spec, direction, af)) return algo; } diff --git a/src/libstate/lookup.h b/src/libstate/lookup.h index 0f48dddfb..5f10bb3f8 100644 --- a/src/libstate/lookup.h +++ b/src/libstate/lookup.h @@ -8,17 +8,14 @@ #ifndef BOTAN_LOOKUP_H__ #define BOTAN_LOOKUP_H__ -#include <botan/block_cipher.h> -#include <botan/stream_cipher.h> -#include <botan/hash.h> -#include <botan/mac.h> -#include <botan/s2k.h> - +#include <botan/libstate.h> +#include <botan/engine.h> #include <botan/filters.h> #include <botan/mode_pad.h> #include <botan/kdf.h> #include <botan/eme.h> #include <botan/emsa.h> +#include <botan/s2k.h> namespace Botan { @@ -28,59 +25,90 @@ namespace Botan { // NOTE: these functions return internally stored objects, library // retains ownership -BOTAN_DLL const BlockCipher* -retrieve_block_cipher(const std::string&); - -BOTAN_DLL const StreamCipher* -retrieve_stream_cipher(const std::string&); - -BOTAN_DLL const HashFunction* -retrieve_hash(const std::string&); - -BOTAN_DLL const MessageAuthenticationCode* -retrieve_mac(const std::string&); +inline const BlockCipher* +retrieve_block_cipher(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return af.prototype_block_cipher(algo_spec); + } + +inline const StreamCipher* +retrieve_stream_cipher(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return af.prototype_stream_cipher(algo_spec); + } + +inline const HashFunction* +retrieve_hash(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return af.prototype_hash_function(algo_spec); + } + +inline const MessageAuthenticationCode* +retrieve_mac(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return af.prototype_mac(algo_spec); + } /* * Get an algorithm object +* NOTE: these functions create and return new objects, letting the +* caller assume ownership of them */ -// NOTE: these functions create and return new objects, letting the -// caller assume ownership of them /** * Block cipher factory method. * @param algo_spec the name of the desired block cipher * @return a pointer to the block cipher object */ -BOTAN_DLL BlockCipher* get_block_cipher(const std::string& name); - +inline BlockCipher* get_block_cipher(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return af.make_block_cipher(algo_spec); + } /** * Stream cipher factory method. * @param algo_spec the name of the desired stream cipher * @return a pointer to the stream cipher object */ -BOTAN_DLL StreamCipher* get_stream_cipher(const std::string& name); +inline StreamCipher* get_stream_cipher(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return af.make_stream_cipher(algo_spec); + } /** * Hash function factory method. * @param algo_spec the name of the desired hash function * @return a pointer to the hash function object */ -BOTAN_DLL HashFunction* get_hash(const std::string& name); +inline HashFunction* get_hash(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return af.make_hash_function(algo_spec); + } /** * MAC factory method. * @param algo_spec the name of the desired MAC * @return a pointer to the MAC object */ -BOTAN_DLL MessageAuthenticationCode* get_mac(const std::string& name); +inline MessageAuthenticationCode* get_mac(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return af.make_mac(algo_spec); + } /** * String to key algorithm factory method. * @param name the name of the desired string to key (S2K) algorithm * @return a pointer to the string to key algorithm object */ -BOTAN_DLL S2K* get_s2k(const std::string& name); +BOTAN_DLL S2K* get_s2k(const std::string& algo_spec); /* * Get an EMSA/EME/KDF/MGF function @@ -93,7 +121,7 @@ BOTAN_DLL S2K* get_s2k(const std::string& name); * @param name the name of the EME to create * @return a pointer to the desired EME object */ -BOTAN_DLL EME* get_eme(const std::string& name); +BOTAN_DLL EME* get_eme(const std::string& algo_spec); /** * Factory method for EMSA (message-encoding methods for signatures @@ -101,14 +129,14 @@ BOTAN_DLL EME* get_eme(const std::string& name); * @param name the name of the EME to create * @return a pointer to the desired EME object */ -BOTAN_DLL EMSA* get_emsa(const std::string& name); +BOTAN_DLL EMSA* get_emsa(const std::string& algo_spec); /** * Factory method for KDF (key derivation function) * @param name the name of the KDF to create * @return a pointer to the desired KDF object */ -BOTAN_DLL KDF* get_kdf(const std::string& name); +BOTAN_DLL KDF* get_kdf(const std::string& algo_spec); /* * Get a cipher object @@ -120,8 +148,8 @@ BOTAN_DLL KDF* get_kdf(const std::string& name); * @param key the key to be used for encryption/decryption performed by * the filter * @param iv the initialization vector to be used -* @param direction determines whether the filter will be an encrypting or decrypting -* filter +* @param direction determines whether the filter will be an encrypting +* or decrypting filter * @return a pointer to the encryption or decryption filter */ BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name, @@ -133,8 +161,8 @@ BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name, * @param algo_spec the name of the desired cipher * @param key the key to be used for encryption/decryption performed by * the filter -* @param direction determines whether the filter will be an encrypting or decrypting -* filter +* @param direction determines whether the filter will be an encrypting +* or decrypting filter * @return a pointer to the encryption or decryption filter */ BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name, @@ -156,35 +184,51 @@ BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name, Cipher_Dir dir); * @param name the name of the algorithm to check for * @return true if the algorithm exists, false otherwise */ -BOTAN_DLL bool have_algorithm(const std::string& name); +BOTAN_DLL bool have_algorithm(const std::string& algo_spec); /** * Check if a block cipher algorithm exists. * @param name the name of the algorithm to check for * @return true if the algorithm exists, false otherwise */ -BOTAN_DLL bool have_block_cipher(const std::string& name); +inline bool have_block_cipher(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return (af.prototype_block_cipher(algo_spec) != 0); + } /** * Check if a stream cipher algorithm exists. * @param name the name of the algorithm to check for * @return true if the algorithm exists, false otherwise */ -BOTAN_DLL bool have_stream_cipher(const std::string& name); +inline bool have_stream_cipher(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return (af.prototype_stream_cipher(algo_spec) != 0); + } /** * Check if a hash algorithm exists. * @param algo_spec the name of the algorithm to check for * @return true if the algorithm exists, false otherwise */ -BOTAN_DLL bool have_hash(const std::string& name); +inline bool have_hash(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return (af.prototype_hash_function(algo_spec) != 0); + } /** * Check if a MAC algorithm exists. * @param algo_spec the name of the algorithm to check for * @return true if the algorithm exists, false otherwise */ -BOTAN_DLL bool have_mac(const std::string& name); +inline bool have_mac(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + return (af.prototype_mac(algo_spec) != 0); + } /* * Query information about an algorithm @@ -195,14 +239,14 @@ BOTAN_DLL bool have_mac(const std::string& name); * @param name the name of the algorithm * @return the block size of the specified algorithm */ -BOTAN_DLL u32bit block_size_of(const std::string& name); +BOTAN_DLL u32bit block_size_of(const std::string& algo_spec); /** * Find out the output length of a certain symmetric algorithm. * @param name the name of the algorithm * @return the output length of the specified algorithm */ -BOTAN_DLL u32bit output_length_of(const std::string& name); +BOTAN_DLL u32bit output_length_of(const std::string& algo_spec); /** * Find out the whether a certain key length is allowd for a given @@ -211,28 +255,29 @@ BOTAN_DLL u32bit output_length_of(const std::string& name); * @param name the name of the algorithm * @return true if the key length is valid for that algorithm, false otherwise */ -BOTAN_DLL bool valid_keylength_for(u32bit keylen, const std::string& name); +BOTAN_DLL bool valid_keylength_for(u32bit keylen, + const std::string& algo_spec); /** * Find out the minimum key size of a certain symmetric algorithm. * @param name the name of the algorithm * @return the minimum key length of the specified algorithm */ -BOTAN_DLL u32bit min_keylength_of(const std::string& name); +BOTAN_DLL u32bit min_keylength_of(const std::string& algo_spec); /** * Find out the maximum key size of a certain symmetric algorithm. * @param name the name of the algorithm * @return the maximum key length of the specified algorithm */ -BOTAN_DLL u32bit max_keylength_of(const std::string& name); +BOTAN_DLL u32bit max_keylength_of(const std::string& algo_spec); /** * Find out the size any valid key is a multiple of for a certain algorithm. * @param name the name of the algorithm * @return the size any valid key is a multiple of */ -BOTAN_DLL u32bit keylength_multiple_of(const std::string& name); +BOTAN_DLL u32bit keylength_multiple_of(const std::string& algo_spec); } diff --git a/src/libstate/policy.cpp b/src/libstate/policy.cpp index 45c99e674..3e9c8e122 100644 --- a/src/libstate/policy.cpp +++ b/src/libstate/policy.cpp @@ -48,6 +48,8 @@ void set_default_oids(Library_State& config) add_oid(config, "2.16.840.1.101.3.4.1.2", "AES-128/CBC"); add_oid(config, "2.16.840.1.101.3.4.1.22", "AES-192/CBC"); add_oid(config, "2.16.840.1.101.3.4.1.42", "AES-256/CBC"); + add_oid(config, "1.2.410.200004.1.4", "SEED/CBC"); // RFC 4010 + add_oid(config, "1.3.6.1.4.1.25258.3.1", "Serpent/CBC"); /* Hash Functions */ add_oid(config, "1.2.840.113549.2.5", "MD5"); @@ -59,6 +61,13 @@ void set_default_oids(Library_State& config) add_oid(config, "2.16.840.1.101.3.4.2.2", "SHA-384"); add_oid(config, "2.16.840.1.101.3.4.2.3", "SHA-512"); + /* MACs */ + add_oid(config, "1.2.840.113549.2.7", "HMAC(SHA-1)"); + add_oid(config, "1.2.840.113549.2.8", "HMAC(SHA-224)"); + add_oid(config, "1.2.840.113549.2.9", "HMAC(SHA-256)"); + add_oid(config, "1.2.840.113549.2.10", "HMAC(SHA-384)"); + add_oid(config, "1.2.840.113549.2.11", "HMAC(SHA-512)"); + /* Key Wrap */ add_oid(config, "1.2.840.113549.1.9.16.3.6", "KeyWrap.TripleDES"); add_oid(config, "1.2.840.113549.1.9.16.3.7", "KeyWrap.RC2"); diff --git a/src/libstate/scan_name.cpp b/src/libstate/scan_name.cpp index 9e046e8ea..eccb15565 100644 --- a/src/libstate/scan_name.cpp +++ b/src/libstate/scan_name.cpp @@ -63,7 +63,7 @@ deref_aliases(const std::pair<u32bit, std::string>& in) } -SCAN_Name::SCAN_Name(const std::string& algo_spec) +SCAN_Name::SCAN_Name(std::string algo_spec) { orig_algo_spec = algo_spec; @@ -71,6 +71,10 @@ SCAN_Name::SCAN_Name(const std::string& algo_spec) u32bit level = 0; std::pair<u32bit, std::string> accum = std::make_pair(level, ""); + std::string decoding_error = "Bad SCAN name '" + algo_spec + "': "; + + algo_spec = global_state().deref_alias(algo_spec); + for(u32bit i = 0; i != algo_spec.size(); ++i) { char c = algo_spec[i]; @@ -82,7 +86,7 @@ SCAN_Name::SCAN_Name(const std::string& algo_spec) else if(c == ')') { if(level == 0) - throw Decoding_Error("Bad SCAN name " + algo_spec); + throw Decoding_Error(decoding_error + "Mismatched parens"); --level; } @@ -102,8 +106,11 @@ SCAN_Name::SCAN_Name(const std::string& algo_spec) if(accum.second != "") name.push_back(deref_aliases(accum)); - if(level != 0 || name.size() == 0) - throw Decoding_Error("Bad SCAN name " + algo_spec); + if(level != 0) + throw Decoding_Error(decoding_error + "Missing close paren"); + + if(name.size() == 0) + throw Decoding_Error(decoding_error + "Empty name"); alg_name = name[0].second; @@ -146,7 +153,7 @@ std::string SCAN_Name::algo_name_and_args() const std::string SCAN_Name::arg(u32bit i) const { if(i >= arg_count()) - throw std::range_error("SCAN_Name::argument"); + throw std::range_error("SCAN_Name::argument - i out of range"); return args[i]; } diff --git a/src/libstate/scan_name.h b/src/libstate/scan_name.h index 7992d7498..4350dca86 100644 --- a/src/libstate/scan_name.h +++ b/src/libstate/scan_name.h @@ -23,9 +23,9 @@ class BOTAN_DLL SCAN_Name { public: /** - @param algo_spec A SCAN name + @param algo_spec A SCAN-format name */ - SCAN_Name(const std::string& algo_spec); + SCAN_Name(std::string algo_spec); /** @return the original input string |