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