Botan
1.11.15
|
00001 /* 00002 * SCAN Name Abstraction 00003 * (C) 2008,2015 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_SCAN_NAME_H__ 00009 #define BOTAN_SCAN_NAME_H__ 00010 00011 #include <botan/types.h> 00012 #include <string> 00013 #include <vector> 00014 #include <mutex> 00015 #include <map> 00016 00017 namespace Botan { 00018 00019 /** 00020 A class encapsulating a SCAN name (similar to JCE conventions) 00021 http://www.users.zetnet.co.uk/hopwood/crypto/scan/ 00022 */ 00023 class BOTAN_DLL SCAN_Name 00024 { 00025 public: 00026 /** 00027 * @param algo_spec A SCAN-format name 00028 */ 00029 SCAN_Name(const char* algo_spec); 00030 00031 /** 00032 * @param algo_spec A SCAN-format name 00033 */ 00034 SCAN_Name(std::string algo_spec); 00035 00036 /** 00037 * @param algo_spec A SCAN-format name 00038 */ 00039 SCAN_Name(std::string algo_spec, const std::string& extra); 00040 00041 /** 00042 * @return original input string 00043 */ 00044 const std::string& as_string() const { return orig_algo_spec; } 00045 00046 /** 00047 * @return algorithm name 00048 */ 00049 const std::string& algo_name() const { return alg_name; } 00050 00051 /** 00052 * @return algorithm name plus any arguments 00053 */ 00054 std::string algo_name_and_args() const { return algo_name() + all_arguments(); } 00055 00056 /** 00057 * @return all arguments 00058 */ 00059 std::string all_arguments() const; 00060 00061 /** 00062 * @return number of arguments 00063 */ 00064 size_t arg_count() const { return args.size(); } 00065 00066 /** 00067 * @param lower is the lower bound 00068 * @param upper is the upper bound 00069 * @return if the number of arguments is between lower and upper 00070 */ 00071 bool arg_count_between(size_t lower, size_t upper) const 00072 { return ((arg_count() >= lower) && (arg_count() <= upper)); } 00073 00074 /** 00075 * @param i which argument 00076 * @return ith argument 00077 */ 00078 std::string arg(size_t i) const; 00079 00080 /** 00081 * @param i which argument 00082 * @param def_value the default value 00083 * @return ith argument or the default value 00084 */ 00085 std::string arg(size_t i, const std::string& def_value) const; 00086 00087 /** 00088 * @param i which argument 00089 * @param def_value the default value 00090 * @return ith argument as an integer, or the default value 00091 */ 00092 size_t arg_as_integer(size_t i, size_t def_value) const; 00093 00094 /** 00095 * @return cipher mode (if any) 00096 */ 00097 std::string cipher_mode() const 00098 { return (mode_info.size() >= 1) ? mode_info[0] : ""; } 00099 00100 /** 00101 * @return cipher mode padding (if any) 00102 */ 00103 std::string cipher_mode_pad() const 00104 { return (mode_info.size() >= 2) ? mode_info[1] : ""; } 00105 00106 static void add_alias(const std::string& alias, const std::string& basename); 00107 00108 static std::string deref_alias(const std::string& alias); 00109 private: 00110 static std::mutex g_alias_map_mutex; 00111 static std::map<std::string, std::string> g_alias_map; 00112 00113 std::string orig_algo_spec; 00114 std::string alg_name; 00115 std::vector<std::string> args; 00116 std::vector<std::string> mode_info; 00117 }; 00118 00119 } 00120 00121 #endif