Botan: src/engine/dyn_engine/dyn_engine.cpp Source File

Botan 1.10.17

dyn_engine.cpp
Go to the documentation of this file.
1 /**
2 * Dynamically Loaded Engine
3 * (C) 2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/dyn_engine.h>
9 #include <botan/internal/dyn_load.h>
10
11 namespace Botan {
12
13 namespace {
14
15 extern "C" {
16 typedef Engine* (*creator_func)(void);
17 typedef u32bit (*module_version_func)(void);
18 }
19
20 }
21
22 Dynamically_Loaded_Engine::Dynamically_Loaded_Engine(
23 const std::string& library_path) :
24 engine(0)
25 {
26 lib = new Dynamically_Loaded_Library(library_path);
27
28 try
29 {
30 module_version_func get_version =
31 lib->resolve<module_version_func>("module_version");
32
33 const u32bit mod_version = get_version();
34
35 if(mod_version != 20101003)
36 throw std::runtime_error("Incompatible version in " +
37 library_path + " of " +
38 to_string(mod_version));
39
40 creator_func creator =
41 lib->resolve<creator_func>("create_engine");
42
43 engine = creator();
44
45 if(!engine)
46 throw std::runtime_error("Creator function in " +
47 library_path + " failed");
48 }
49 catch(...)
50 {
51 delete lib;
52 lib = 0;
53 throw;
54 }
55 }
56
57 Dynamically_Loaded_Engine::~Dynamically_Loaded_Engine()
58 {
59 delete engine;
60 delete lib;
61 }
62
63 }
Botan::Dynamically_Loaded_Library::resolve
T resolve(const std::string &symbol)
Definition: dyn_load.h:52
Botan::Dynamically_Loaded_Engine::Dynamically_Loaded_Engine
Dynamically_Loaded_Engine(const std::string &lib_path)
Definition: dyn_engine.cpp:22
Botan::Dynamically_Loaded_Engine::~Dynamically_Loaded_Engine
~Dynamically_Loaded_Engine()
Definition: dyn_engine.cpp:57
Botan
Definition: algo_base.h:14
Botan::Dynamically_Loaded_Library
Definition: dyn_load.h:18
Botan::to_string
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42
Botan::u32bit
unsigned int u32bit
Definition: types.h:32