Botan  1.10.9
scan_name.h
Go to the documentation of this file.
1 /*
2 * SCAN Name Abstraction
3 * (C) 2008 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
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_DLL SCAN_Name
22  {
23  public:
24  /**
25  * @param algo_spec A SCAN-format name
26  */
27  SCAN_Name(std::string algo_spec);
28 
29  /**
30  * @return original input string
31  */
32  std::string as_string() const { return orig_algo_spec; }
33 
34  /**
35  * @return algorithm name
36  */
37  std::string algo_name() const { return alg_name; }
38 
39  /**
40  * @return algorithm name plus any arguments
41  */
42  std::string algo_name_and_args() const;
43 
44  /**
45  * @return number of arguments
46  */
47  size_t arg_count() const { return args.size(); }
48 
49  /**
50  * @param lower is the lower bound
51  * @param upper is the upper bound
52  * @return if the number of arguments is between lower and upper
53  */
54  bool arg_count_between(size_t lower, size_t upper) const
55  { return ((arg_count() >= lower) && (arg_count() <= upper)); }
56 
57  /**
58  * @param i which argument
59  * @return ith argument
60  */
61  std::string arg(size_t i) const;
62 
63  /**
64  * @param i which argument
65  * @param def_value the default value
66  * @return ith argument or the default value
67  */
68  std::string arg(size_t i, const std::string& def_value) const;
69 
70  /**
71  * @param i which argument
72  * @param def_value the default value
73  * @return ith argument as an integer, or the default value
74  */
75  size_t arg_as_integer(size_t i, size_t def_value) const;
76 
77  /**
78  * @return cipher mode (if any)
79  */
80  std::string cipher_mode() const
81  { return (mode_info.size() >= 1) ? mode_info[0] : ""; }
82 
83  /**
84  * @return cipher mode padding (if any)
85  */
86  std::string cipher_mode_pad() const
87  { return (mode_info.size() >= 2) ? mode_info[1] : ""; }
88 
89  private:
90  std::string orig_algo_spec;
91  std::string alg_name;
92  std::vector<std::string> args;
93  std::vector<std::string> mode_info;
94  };
95 
96 }
97 
98 #endif
std::string cipher_mode() const
Definition: scan_name.h:80
size_t arg_count() const
Definition: scan_name.h:47
std::string algo_name() const
Definition: scan_name.h:37
std::string cipher_mode_pad() const
Definition: scan_name.h:86
bool arg_count_between(size_t lower, size_t upper) const
Definition: scan_name.h:54
std::string as_string() const
Definition: scan_name.h:32