Botan 1.10.17
Botan::Algorithm_Cache< T > Class Template Reference

#include <algo_cache.h>

Public Member Functions

void add (T *algo, const std::string &requested_name, const std::string &provider_name)
 Algorithm_Cache (Mutex *m)
void clear_cache ()
const T * get (const std::string &algo_spec, const std::string &pref_provider)
std::vector< std::string > providers_of (const std::string &algo_name)
void set_preferred_provider (const std::string &algo_spec, const std::string &provider)
 ~Algorithm_Cache ()

Detailed Description

template<typename T>
class Botan::Algorithm_Cache< T >

Algorithm_Cache (used by Algorithm_Factory)

Definition at line 29 of file algo_cache.h.

Constructor & Destructor Documentation

◆ Algorithm_Cache()

template<typename T>
Botan::Algorithm_Cache< T >::Algorithm_Cache ( Mutex * m)
inline

Constructor

Parameters
ma mutex to serialize internal access

Definition at line 74 of file algo_cache.h.

74: mutex(m) {}

Referenced by Botan::Algorithm_Factory::Algorithm_Factory().

◆ ~Algorithm_Cache()

template<typename T>
Botan::Algorithm_Cache< T >::~Algorithm_Cache ( )
inline

Definition at line 75 of file algo_cache.h.

75{ clear_cache(); delete mutex; }

References clear_cache().

Member Function Documentation

◆ add()

template<typename T>
void Botan::Algorithm_Cache< T >::add ( T * algo,
const std::string & requested_name,
const std::string & provider_name )

Add a new algorithm implementation to the cache

Parameters
algothe algorithm prototype object
requested_namehow this name will be requested
provider_nameis the name of the provider of this prototype

Definition at line 165 of file algo_cache.h.

168 {
169 if(!algo)
170 return;
171
172 Mutex_Holder lock(mutex);
173
174 if(algo->name() != requested_name &&
175 aliases.find(requested_name) == aliases.end())
176 {
177 aliases[requested_name] = algo->name();
178 }
179
180 if(!algorithms[algo->name()][provider])
181 algorithms[algo->name()][provider] = algo;
182 else
183 delete algo;
184 }

◆ clear_cache()

template<typename T>
void Botan::Algorithm_Cache< T >::clear_cache ( )

Clear the cache

Definition at line 228 of file algo_cache.h.

229 {
230 algorithms_iterator algo = algorithms.begin();
231
232 while(algo != algorithms.end())
233 {
234 provider_iterator provider = algo->second.begin();
235
236 while(provider != algo->second.end())
237 {
238 delete provider->second;
239 ++provider;
240 }
241
242 ++algo;
243 }
244
245 algorithms.clear();
246 }

Referenced by ~Algorithm_Cache().

◆ get()

template<typename T>
const T * Botan::Algorithm_Cache< T >::get ( const std::string & algo_spec,
const std::string & pref_provider )
Parameters
algo_specnames the requested algorithm
pref_providersuggests a preferred provider
Returns
prototype object, or NULL

Definition at line 117 of file algo_cache.h.

119 {
120 Mutex_Holder lock(mutex);
121
122 algorithms_iterator algo = find_algorithm(algo_spec);
123 if(algo == algorithms.end()) // algo not found at all (no providers)
124 return 0;
125
126 // If a provider is requested specifically, return it or fail entirely
127 if(requested_provider != "")
128 {
129 provider_iterator prov = algo->second.find(requested_provider);
130 if(prov != algo->second.end())
131 return prov->second;
132 return 0;
133 }
134
135 const T* prototype = 0;
137 size_t prototype_prov_weight = 0;
138
139 const std::string pref_provider = search_map(pref_providers, algo_spec);
140
141 for(provider_iterator i = algo->second.begin(); i != algo->second.end(); ++i)
142 {
143 const std::string prov_name = i->first;
145
146 // preferred prov exists, return immediately
148 return i->second;
149
151 {
152 prototype = i->second;
153 prototype_provider = i->first;
155 }
156 }
157
158 return prototype;
159 }

References Botan::search_map(), and Botan::static_provider_weight().

◆ providers_of()

template<typename T>
std::vector< std::string > Botan::Algorithm_Cache< T >::providers_of ( const std::string & algo_name)

Return the list of providers of this algorithm

Parameters
algo_namenames the algorithm
Returns
list of providers of this algorithm

Definition at line 190 of file algo_cache.h.

191 {
192 Mutex_Holder lock(mutex);
193
195
196 algorithms_iterator algo = find_algorithm(algo_name);
197
198 if(algo != algorithms.end())
199 {
200 provider_iterator provider = algo->second.begin();
201
202 while(provider != algo->second.end())
203 {
204 providers.push_back(provider->first);
205 ++provider;
206 }
207 }
208
209 return providers;
210 }

◆ set_preferred_provider()

template<typename T>
void Botan::Algorithm_Cache< T >::set_preferred_provider ( const std::string & algo_spec,
const std::string & provider )

Set the preferred provider

Parameters
algo_specnames the algorithm
providernames the preferred provider

Definition at line 216 of file algo_cache.h.

218 {
219 Mutex_Holder lock(mutex);
220
221 pref_providers[algo_spec] = provider;
222 }

The documentation for this class was generated from the following file: