Botan 3.0.0-alpha0
Crypto and TLS for C&
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
15namespace Botan {
16
17/**
18A class encapsulating a SCAN name (similar to JCE conventions)
19http://www.users.zetnet.co.uk/hopwood/crypto/scan/
20*/
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(const 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 /**
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 * @param i which argument
81 * @return ith argument as an integer
82 */
83 size_t arg_as_integer(size_t i) const;
84
85 /**
86 * @return cipher mode (if any)
87 */
88 std::string cipher_mode() const
89 { return (m_mode_info.size() >= 1) ? m_mode_info[0] : ""; }
90
91 /**
92 * @return cipher mode padding (if any)
93 */
94 std::string cipher_mode_pad() const
95 { return (m_mode_info.size() >= 2) ? m_mode_info[1] : ""; }
96
97 private:
98 std::string m_orig_algo_spec;
99 std::string m_alg_name;
100 std::vector<std::string> m_args;
101 std::vector<std::string> m_mode_info;
102 };
103
104// This is unrelated but it is convenient to stash it here
105template<typename T>
106std::vector<std::string> probe_providers_of(const std::string& algo_spec,
107 const std::vector<std::string>& possible = { "base" })
108 {
109 std::vector<std::string> providers;
110 for(auto&& prov : possible)
111 {
112 std::unique_ptr<T> o(T::create(algo_spec, prov));
113 if(o)
114 {
115 providers.push_back(prov); // available
116 }
117 }
118 return providers;
119 }
120
121}
122
123#endif
std::string arg(size_t i) const
Definition: scan_name.cpp:129
const std::string & to_string() const
Definition: scan_name.h:39
size_t arg_count() const
Definition: scan_name.h:49
SCAN_Name(const char *algo_spec)
Definition: scan_name.cpp:59
const std::string & algo_name() const
Definition: scan_name.h:44
std::string cipher_mode_pad() const
Definition: scan_name.h:94
std::string cipher_mode() const
Definition: scan_name.h:88
size_t arg_as_integer(size_t i, size_t def_value) const
Definition: scan_name.cpp:144
bool arg_count_between(size_t lower, size_t upper) const
Definition: scan_name.h:56
int(* final)(unsigned char *, CTX *)
Definition: alg_id.cpp:13
std::vector< std::string > probe_providers_of(const std::string &algo_spec, const std::vector< std::string > &possible={ "base" })
Definition: scan_name.h:106