Botan  2.6.0
Crypto and TLS for C++11
dyn_load.h
Go to the documentation of this file.
1 /*
2 * Dynamically Loaded Object
3 * (C) 2010 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_DYNAMIC_LOADER_H_
9 #define BOTAN_DYNAMIC_LOADER_H_
10 
11 #include <botan/types.h>
12 #include <string>
13 
14 namespace Botan {
15 
16 /**
17 * Represents a DLL or shared object
18 */
20  {
21  public:
22  /**
23  * Load a DLL (or fail with an exception)
24  * @param lib_name name or path to a library
25  *
26  * If you don't use a full path, the search order will be defined
27  * by whatever the system linker does by default. Always using fully
28  * qualified pathnames can help prevent code injection attacks (eg
29  * via manipulation of LD_LIBRARY_PATH on Linux)
30  */
31  Dynamically_Loaded_Library(const std::string& lib_name);
32 
33  /**
34  * Unload the DLL
35  * @warning Any pointers returned by resolve()/resolve_symbol()
36  * should not be used after this destructor runs.
37  */
39 
40  /**
41  * Load a symbol (or fail with an exception)
42  * @param symbol names the symbol to load
43  * @return address of the loaded symbol
44  */
45  void* resolve_symbol(const std::string& symbol);
46 
47  /**
48  * Convenience function for casting symbol to the right type
49  * @param symbol names the symbol to load
50  * @return address of the loaded symbol
51  */
52  template<typename T>
53  T resolve(const std::string& symbol)
54  {
55  return reinterpret_cast<T>(resolve_symbol(symbol));
56  }
57 
58  private:
61 
62  std::string m_lib_name;
63  void* m_lib;
64  };
65 
66 }
67 
68 #endif
T resolve(const std::string &symbol)
Definition: dyn_load.h:53
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: alg_id.cpp:13
fe T
Definition: ge.cpp:37