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