Botan 3.4.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(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_view 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 /**
61 * @param i which argument
62 * @return ith argument
63 */
64 std::string arg(size_t i) const;
65
66 /**
67 * @param i which argument
68 * @param def_value the default value
69 * @return ith argument or the default value
70 */
71 std::string arg(size_t i, std::string_view def_value) const;
72
73 /**
74 * @param i which argument
75 * @param def_value the default value
76 * @return ith argument as an integer, or the default value
77 */
78 size_t arg_as_integer(size_t i, size_t def_value) const;
79
80 /**
81 * @param i which argument
82 * @return ith argument as an integer
83 */
84 size_t arg_as_integer(size_t i) const;
85
86 /**
87 * @return cipher mode (if any)
88 */
89 std::string cipher_mode() const { return (!m_mode_info.empty()) ? m_mode_info[0] : ""; }
90
91 /**
92 * @return cipher mode padding (if any)
93 */
94 std::string cipher_mode_pad() const { 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
104template <typename T>
105std::vector<std::string> probe_providers_of(std::string_view algo_spec,
106 const std::vector<std::string>& possible = {"base"}) {
107 std::vector<std::string> providers;
108 for(auto&& prov : possible) {
109 auto o = T::create(algo_spec, prov);
110 if(o) {
111 providers.push_back(prov); // available
112 }
113 }
114 return providers;
115}
116
117} // namespace Botan
118
119#endif
std::string arg(size_t i) const
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:56
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:89
size_t arg_as_integer(size_t i, size_t def_value) const
bool arg_count_between(size_t lower, size_t upper) const
Definition scan_name.h:56
int(* final)(unsigned char *, CTX *)
std::vector< std::string > probe_providers_of(std::string_view algo_spec, const std::vector< std::string > &possible={"base"})
Definition scan_name.h:105