diff options
Diffstat (limited to 'src/libstate')
-rw-r--r-- | src/libstate/info.txt | 33 | ||||
-rw-r--r-- | src/libstate/oid_lookup/info.txt | 9 | ||||
-rw-r--r-- | src/libstate/scan_name.cpp | 75 | ||||
-rw-r--r-- | src/libstate/scan_name.h | 77 |
4 files changed, 180 insertions, 14 deletions
diff --git a/src/libstate/info.txt b/src/libstate/info.txt index f3111a31e..7ca35c5a4 100644 --- a/src/libstate/info.txt +++ b/src/libstate/info.txt @@ -4,15 +4,6 @@ load_on auto define LIBSTATE_MODULE -<requires> -algo_factory -def_engine -mode_pad -pk_pad -s2k -system_alloc -</requires> - <add> botan.h get_enc.cpp @@ -27,4 +18,28 @@ lookup.h pk_engine.cpp pk_engine.h policy.cpp +scan_name.cpp +scan_name.h </add> + +<requires> +algo_factory +alloc +bigint +block +def_engine +engine +filters +hash +kdf +mac +mode_pad +mutex +noop_mutex +pk_pad +pubkey +rng +s2k +stream +system_alloc +</requires> diff --git a/src/libstate/oid_lookup/info.txt b/src/libstate/oid_lookup/info.txt index b5f4ef21f..609eb9199 100644 --- a/src/libstate/oid_lookup/info.txt +++ b/src/libstate/oid_lookup/info.txt @@ -4,12 +4,11 @@ load_on dep define OID_LOOKUP -<requires> -#libstate -#asn1 -</requires> - <add> oids.cpp oids.h </add> + +<requires> +asn1 +</requires> diff --git a/src/libstate/scan_name.cpp b/src/libstate/scan_name.cpp new file mode 100644 index 000000000..4ca6e6d59 --- /dev/null +++ b/src/libstate/scan_name.cpp @@ -0,0 +1,75 @@ +/** +SCAN Name Abstraction +(C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/scan_name.h> +#include <botan/parsing.h> +#include <botan/libstate.h> +#include <botan/exceptn.h> +#include <stdexcept> + +namespace Botan { + +namespace { + +std::vector<std::string> +parse_and_deref_aliases(const std::string& algo_spec) + { + std::vector<std::string> parts = parse_algorithm_name(algo_spec); + std::vector<std::string> out; + + for(size_t i = 0; i != parts.size(); ++i) + { + std::string part_i = global_state().deref_alias(parts[i]); + + if(i == 0 && part_i.find_first_of(",()") != std::string::npos) + { + std::vector<std::string> parts_i = parse_and_deref_aliases(part_i); + + for(size_t j = 0; j != parts_i.size(); ++j) + out.push_back(parts_i[j]); + } + else + out.push_back(part_i); + } + + return out; + } + +} + +SCAN_Name::SCAN_Name(const std::string& algo_spec) + { + orig_algo_spec = algo_spec; + + name = parse_and_deref_aliases(algo_spec); + + if(name.size() == 0) + throw Decoding_Error("Bad SCAN name " + algo_spec); + } + +std::string SCAN_Name::arg(u32bit i) const + { + if(i >= arg_count()) + throw std::range_error("SCAN_Name::argument"); + return name[i+1]; + } + +std::string SCAN_Name::arg(u32bit i, const std::string& def_value) const + { + if(i >= arg_count()) + return def_value; + return name[i+1]; + } + +u32bit SCAN_Name::arg_as_u32bit(u32bit i, u32bit def_value) const + { + if(i >= arg_count()) + return def_value; + return to_u32bit(name[i+1]); + } + +} diff --git a/src/libstate/scan_name.h b/src/libstate/scan_name.h new file mode 100644 index 000000000..9e7af40d6 --- /dev/null +++ b/src/libstate/scan_name.h @@ -0,0 +1,77 @@ +/** +SCAN Name Abstraction +(C) 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_SCAN_NAME_H__ +#define BOTAN_SCAN_NAME_H__ + +#include <botan/types.h> +#include <string> +#include <vector> +#include <set> + +namespace Botan { + +/** +A class encapsulating a SCAN name (similar to JCE conventions) +http://www.users.zetnet.co.uk/hopwood/crypto/scan/ +*/ +class SCAN_Name + { + public: + /** + @param algo_spec A SCAN name + */ + SCAN_Name(const std::string& algo_spec); + + /** + @return the original input string + */ + std::string as_string() const { return orig_algo_spec; } + + /** + @return the algorithm name + */ + std::string algo_name() const { return name[0]; } + + /** + @return the number of arguments + */ + u32bit arg_count() const { return name.size() - 1; } + + /** + @return if the number of arguments is between lower and upper + */ + bool arg_count_between(u32bit lower, u32bit upper) const + { return ((arg_count() >= lower) && (arg_count() <= upper)); } + + /** + @param i which argument + @return the ith argument + */ + std::string arg(u32bit i) const; + + /** + @param i which argument + @param def_value the default value + @return the ith argument or the default value + */ + std::string arg(u32bit i, const std::string& def_value) const; + + /** + @param i which argument + @param def_value the default value + @return the ith argument as a u32bit, or the default value + */ + u32bit arg_as_u32bit(u32bit i, u32bit def_value) const; + private: + std::string orig_algo_spec; + std::vector<std::string> name; + }; + +} + +#endif |