Botan  2.10.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& to_string() const { return m_orig_algo_spec; }
40 
41  BOTAN_DEPRECATED("Use SCAN_Name::to_string") const std::string& as_string() const
42  {
43  return this->to_string();
44  }
45 
46  /**
47  * @return algorithm name
48  */
49  const std::string& algo_name() const { return m_alg_name; }
50 
51  /**
52  * @return number of arguments
53  */
54  size_t arg_count() const { return m_args.size(); }
55 
56  /**
57  * @param lower is the lower bound
58  * @param upper is the upper bound
59  * @return if the number of arguments is between lower and upper
60  */
61  bool arg_count_between(size_t lower, size_t upper) const
62  { return ((arg_count() >= lower) && (arg_count() <= upper)); }
63 
64  /**
65  * @param i which argument
66  * @return ith argument
67  */
68  std::string arg(size_t i) const;
69 
70  /**
71  * @param i which argument
72  * @param def_value the default value
73  * @return ith argument or the default value
74  */
75  std::string arg(size_t i, const std::string& def_value) const;
76 
77  /**
78  * @param i which argument
79  * @param def_value the default value
80  * @return ith argument as an integer, or the default value
81  */
82  size_t arg_as_integer(size_t i, size_t def_value) const;
83 
84  /**
85  * @return cipher mode (if any)
86  */
87  std::string cipher_mode() const
88  { return (m_mode_info.size() >= 1) ? m_mode_info[0] : ""; }
89 
90  /**
91  * @return cipher mode padding (if any)
92  */
93  std::string cipher_mode_pad() const
94  { return (m_mode_info.size() >= 2) ? m_mode_info[1] : ""; }
95 
96  private:
97  std::string m_orig_algo_spec;
98  std::string m_alg_name;
99  std::vector<std::string> m_args;
100  std::vector<std::string> m_mode_info;
101  };
102 
103 // This is unrelated but it is convenient to stash it here
104 template<typename T>
105 std::vector<std::string> probe_providers_of(const std::string& algo_spec,
106  const std::vector<std::string>& possible)
107  {
108  std::vector<std::string> providers;
109  for(auto&& prov : possible)
110  {
111  std::unique_ptr<T> o(T::create(algo_spec, prov));
112  if(o)
113  {
114  providers.push_back(prov); // available
115  }
116  }
117  return providers;
118  }
119 
120 }
121 
122 #endif
int(* final)(unsigned char *, CTX *)
Definition: bigint.h:1136
const char * algo_name
Definition: ffi.h:932
std::vector< std::string > probe_providers_of(const std::string &algo_spec, const std::vector< std::string > &possible)
Definition: scan_name.h:105
Definition: alg_id.cpp:13
class BOTAN_PUBLIC_API(2, 0) AlgorithmIdentifier final bool BOTAN_PUBLIC_API(2, 0) operator
Name Constraints.
Definition: asn1_obj.h:65
std::string to_string(const secure_vector< uint8_t > &bytes)
Definition: stl_util.h:25