Botan: src/algo_factory/algo_factory.h Source File

Botan 1.10.17

algo_factory.h
Go to the documentation of this file.
1 /*
2 * Algorithm Factory
3 * (C) 2008 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_ALGORITHM_FACTORY_H__
9 #define BOTAN_ALGORITHM_FACTORY_H__
10
11 #include <botan/types.h>
12 #include <string>
13 #include <vector>
14
15 namespace Botan {
16
17 /**
18 * Forward declarations (don't need full definitions here)
19 */
20 class BlockCipher;
21 class StreamCipher;
22 class HashFunction;
23 class MessageAuthenticationCode;
24 class PBKDF;
25
26 template<typename T> class Algorithm_Cache;
27
28 class Engine;
29 class Mutex_Factory;
30
31 /**
32 * Algorithm Factory
33 */
34 class BOTAN_DLL Algorithm_Factory
35 {
36 public:
37 /**
38 * Constructor
39 * @param mf a mutex factory
40 */
41 Algorithm_Factory(Mutex_Factory& mf);
42
43 /**
44 * Destructor
45 */
46 ~Algorithm_Factory();
47
48 /**
49 * @param engine to add (Algorithm_Factory takes ownership)
50 */
51 void add_engine(Engine* engine);
52
53 /**
54 * Clear out any cached objects
55 */
56 void clear_caches();
57
58 /**
59 * @param algo_spec the algorithm we are querying
60 * @returns list of providers of this algorithm
61 */
62 std::vector<std::string> providers_of(const std::string& algo_spec);
63
64 /**
65 * @param algo_spec the algorithm we are setting a provider for
66 * @param provider the provider we would like to use
67 */
68 void set_preferred_provider(const std::string& algo_spec,
69 const std::string& provider);
70
71 /**
72 * @param algo_spec the algorithm we want
73 * @param provider the provider we would like to use
74 * @returns pointer to const prototype object, ready to clone(), or NULL
75 */
76 const BlockCipher*
77 prototype_block_cipher(const std::string& algo_spec,
78 const std::string& provider = "");
79
80 /**
81 * @param algo_spec the algorithm we want
82 * @param provider the provider we would like to use
83 * @returns pointer to freshly created instance of the request algorithm
84 */
85 BlockCipher* make_block_cipher(const std::string& algo_spec,
86 const std::string& provider = "");
87
88 /**
89 * @param algo the algorithm to add
90 * @param provider the provider of this algorithm
91 */
92 void add_block_cipher(BlockCipher* algo, const std::string& provider);
93
94 /**
95 * @param algo_spec the algorithm we want
96 * @param provider the provider we would like to use
97 * @returns pointer to const prototype object, ready to clone(), or NULL
98 */
99 const StreamCipher*
100 prototype_stream_cipher(const std::string& algo_spec,
101 const std::string& provider = "");
102
103 /**
104 * @param algo_spec the algorithm we want
105 * @param provider the provider we would like to use
106 * @returns pointer to freshly created instance of the request algorithm
107 */
108 StreamCipher* make_stream_cipher(const std::string& algo_spec,
109 const std::string& provider = "");
110
111 /**
112 * @param algo the algorithm to add
113 * @param provider the provider of this algorithm
114 */
115 void add_stream_cipher(StreamCipher* algo, const std::string& provider);
116
117 /**
118 * @param algo_spec the algorithm we want
119 * @param provider the provider we would like to use
120 * @returns pointer to const prototype object, ready to clone(), or NULL
121 */
122 const HashFunction*
123 prototype_hash_function(const std::string& algo_spec,
124 const std::string& provider = "");
125
126 /**
127 * @param algo_spec the algorithm we want
128 * @param provider the provider we would like to use
129 * @returns pointer to freshly created instance of the request algorithm
130 */
131 HashFunction* make_hash_function(const std::string& algo_spec,
132 const std::string& provider = "");
133
134 /**
135 * @param algo the algorithm to add
136 * @param provider the provider of this algorithm
137 */
138 void add_hash_function(HashFunction* algo, const std::string& provider);
139
140 /**
141 * @param algo_spec the algorithm we want
142 * @param provider the provider we would like to use
143 * @returns pointer to const prototype object, ready to clone(), or NULL
144 */
145 const MessageAuthenticationCode*
146 prototype_mac(const std::string& algo_spec,
147 const std::string& provider = "");
148
149 /**
150 * @param algo_spec the algorithm we want
151 * @param provider the provider we would like to use
152 * @returns pointer to freshly created instance of the request algorithm
153 */
154 MessageAuthenticationCode* make_mac(const std::string& algo_spec,
155 const std::string& provider = "");
156
157 /**
158 * @param algo the algorithm to add
159 * @param provider the provider of this algorithm
160 */
161 void add_mac(MessageAuthenticationCode* algo,
162 const std::string& provider);
163
164 /**
165 * @param algo_spec the algorithm we want
166 * @param provider the provider we would like to use
167 * @returns pointer to const prototype object, ready to clone(), or NULL
168 */
169 const PBKDF* prototype_pbkdf(const std::string& algo_spec,
170 const std::string& provider = "");
171
172 /**
173 * @param algo_spec the algorithm we want
174 * @param provider the provider we would like to use
175 * @returns pointer to freshly created instance of the request algorithm
176 */
177 PBKDF* make_pbkdf(const std::string& algo_spec,
178 const std::string& provider = "");
179
180 /**
181 * @param algo the algorithm to add
182 * @param provider the provider of this algorithm
183 */
184 void add_pbkdf(PBKDF* algo, const std::string& provider);
185
186 /**
187 * An iterator for the engines in this factory
188 * @deprecated Avoid in new code
189 */
190 class BOTAN_DLL Engine_Iterator
191 {
192 public:
193 /**
194 * @return next engine in the sequence
195 */
196 Engine* next() { return af.get_engine_n(n++); }
197
198 /**
199 * @param a an algorithm factory
200 */
201 Engine_Iterator(const Algorithm_Factory& a) :
202 af(a) { n = 0; }
203 private:
204 const Algorithm_Factory& af;
205 size_t n;
206 };
207 friend class Engine_Iterator;
208
209 private:
210 Algorithm_Factory(const Algorithm_Factory&) {}
211 Algorithm_Factory& operator=(const Algorithm_Factory&)
212 { return (*this); }
213
214 Engine* get_engine_n(size_t n) const;
215
216 std::vector<Engine*> engines;
217
218 Algorithm_Cache<BlockCipher>* block_cipher_cache;
219 Algorithm_Cache<StreamCipher>* stream_cipher_cache;
220 Algorithm_Cache<HashFunction>* hash_cache;
221 Algorithm_Cache<MessageAuthenticationCode>* mac_cache;
222 Algorithm_Cache<PBKDF>* pbkdf_cache;
223 };
224
225 }
226
227 #endif
Botan::Algorithm_Factory
Definition: algo_factory.h:34
Botan::Mutex_Factory
Definition: mutex.h:36
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::Engine
Definition: engine.h:32
Botan::Algorithm_Factory::Engine_Iterator
Definition: algo_factory.h:190
Botan::StreamCipher
Definition: stream_cipher.h:18
Botan
Definition: algo_base.h:14
Botan::HashFunction
Definition: hash.h:20
Botan::Algorithm_Factory::Engine_Iterator::next
Engine * next()
Definition: algo_factory.h:196
Botan::Algorithm_Factory::Engine_Iterator::Engine_Iterator
Engine_Iterator(const Algorithm_Factory &a)
Definition: algo_factory.h:201
Botan::BlockCipher
Definition: block_cipher.h:18
Botan::PBKDF
Definition: pbkdf.h:21