diff options
author | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
commit | 6894dca64c04936d07048c0e8cbf7e25858548c3 (patch) | |
tree | 5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/algo_base/scan_name.h | |
parent | 9efa3be92442afb3d0b69890a36c7f122df18eda (diff) |
Move lib into src
Diffstat (limited to 'src/lib/algo_base/scan_name.h')
-rw-r--r-- | src/lib/algo_base/scan_name.h | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/lib/algo_base/scan_name.h b/src/lib/algo_base/scan_name.h new file mode 100644 index 000000000..f4c4b46e7 --- /dev/null +++ b/src/lib/algo_base/scan_name.h @@ -0,0 +1,108 @@ +/* +* 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 <mutex> +#include <map> + +namespace Botan { + +/** +A class encapsulating a SCAN name (similar to JCE conventions) +http://www.users.zetnet.co.uk/hopwood/crypto/scan/ +*/ +class BOTAN_DLL SCAN_Name + { + public: + /** + * @param algo_spec A SCAN-format name + */ + SCAN_Name(std::string algo_spec); + + /** + * @return original input string + */ + std::string as_string() const { return orig_algo_spec; } + + /** + * @return algorithm name + */ + std::string algo_name() const { return alg_name; } + + /** + * @return algorithm name plus any arguments + */ + std::string algo_name_and_args() const; + + /** + * @return number of arguments + */ + size_t arg_count() const { return args.size(); } + + /** + * @param lower is the lower bound + * @param upper is the upper bound + * @return if the number of arguments is between lower and upper + */ + bool arg_count_between(size_t lower, size_t upper) const + { return ((arg_count() >= lower) && (arg_count() <= upper)); } + + /** + * @param i which argument + * @return ith argument + */ + std::string arg(size_t i) const; + + /** + * @param i which argument + * @param def_value the default value + * @return ith argument or the default value + */ + std::string arg(size_t i, const std::string& def_value) const; + + /** + * @param i which argument + * @param def_value the default value + * @return ith argument as an integer, or the default value + */ + size_t arg_as_integer(size_t i, size_t def_value) const; + + /** + * @return cipher mode (if any) + */ + std::string cipher_mode() const + { return (mode_info.size() >= 1) ? mode_info[0] : ""; } + + /** + * @return cipher mode padding (if any) + */ + std::string cipher_mode_pad() const + { return (mode_info.size() >= 2) ? mode_info[1] : ""; } + + static void add_alias(const std::string& alias, const std::string& basename); + + static std::string deref_alias(const std::string& alias); + + static void set_default_aliases(); + private: + static std::mutex s_alias_map_mutex; + static std::map<std::string, std::string> s_alias_map; + + std::string orig_algo_spec; + std::string alg_name; + std::vector<std::string> args; + std::vector<std::string> mode_info; + }; + +} + +#endif |