Botan  2.1.0
Crypto and TLS for C++11
scan_name.h
Go to the documentation of this file.
1 /*
2 * SCAN Name Abstraction
3 * (C) 2008,2015 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_SCAN_NAME_H__
9 #define BOTAN_SCAN_NAME_H__
10 
11 #include <botan/exceptn.h>
12 #include <string>
13 #include <vector>
14 #include <map>
15 
16 namespace Botan {
17 
18 /**
19 A class encapsulating a SCAN name (similar to JCE conventions)
20 http://www.users.zetnet.co.uk/hopwood/crypto/scan/
21 */
22 class BOTAN_DLL SCAN_Name
23  {
24  public:
25  /**
26  * Create a SCAN_Name
27  * @param algo_spec A SCAN-format name
28  */
29  explicit SCAN_Name(const char* algo_spec);
30 
31  /**
32  * Create a SCAN_Name
33  * @param algo_spec A SCAN-format name
34  */
35  explicit SCAN_Name(std::string algo_spec);
36 
37  /**
38  * @return original input string
39  */
40  const std::string& as_string() const { return m_orig_algo_spec; }
41 
42  /**
43  * @return algorithm name
44  */
45  const std::string& algo_name() const { return m_alg_name; }
46 
47  /**
48  * @return number of arguments
49  */
50  size_t arg_count() const { return m_args.size(); }
51 
52  /**
53  * @param lower is the lower bound
54  * @param upper is the upper bound
55  * @return if the number of arguments is between lower and upper
56  */
57  bool arg_count_between(size_t lower, size_t upper) const
58  { return ((arg_count() >= lower) && (arg_count() <= upper)); }
59 
60  /**
61  * @param i which argument
62  * @return ith argument
63  */
64  std::string arg(size_t i) const;
65 
66  /**
67  * @param i which argument
68  * @param def_value the default value
69  * @return ith argument or the default value
70  */
71  std::string arg(size_t i, const std::string& def_value) const;
72 
73  /**
74  * @param i which argument
75  * @param def_value the default value
76  * @return ith argument as an integer, or the default value
77  */
78  size_t arg_as_integer(size_t i, size_t def_value) const;
79 
80  /**
81  * @return cipher mode (if any)
82  */
83  std::string cipher_mode() const
84  { return (m_mode_info.size() >= 1) ? m_mode_info[0] : ""; }
85 
86  /**
87  * @return cipher mode padding (if any)
88  */
89  std::string cipher_mode_pad() const
90  { return (m_mode_info.size() >= 2) ? m_mode_info[1] : ""; }
91 
92  private:
93  std::string m_orig_algo_spec;
94  std::string m_alg_name;
95  std::vector<std::string> m_args;
96  std::vector<std::string> m_mode_info;
97  };
98 
99 // This is unrelated but it is convenient to stash it here
100 template<typename T>
101 std::vector<std::string> probe_providers_of(const std::string& algo_spec,
102  const std::vector<std::string>& possible)
103  {
104  std::vector<std::string> providers;
105  for(auto&& prov : possible)
106  {
107  std::unique_ptr<T> o(T::create(algo_spec, prov));
108  if(o)
109  {
110  providers.push_back(prov); // available
111  }
112  }
113  return providers;
114  }
115 
116 }
117 
118 #endif
std::string cipher_mode() const
Definition: scan_name.h:83
size_t arg_count() const
Definition: scan_name.h:50
const std::string & as_string() const
Definition: scan_name.h:40
std::string cipher_mode_pad() const
Definition: scan_name.h:89
bool arg_count_between(size_t lower, size_t upper) const
Definition: scan_name.h:57
std::vector< std::string > probe_providers_of(const std::string &algo_spec, const std::vector< std::string > &possible)
Definition: scan_name.h:101
Definition: alg_id.cpp:13
const std::string & algo_name() const
Definition: scan_name.h:45