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