Botan  2.13.0
Crypto and TLS for C++11
p11_module.cpp
Go to the documentation of this file.
1 /*
2 * PKCS#11 Module
3 * (C) 2016 Daniel Neus, Sirrix AG
4 * (C) 2016 Philipp Weber, Sirrix AG
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #include <botan/p11_module.h>
10 
11 namespace Botan {
12 
13 namespace PKCS11 {
14 
15 Module::Module(const std::string& file_path, C_InitializeArgs init_args)
16  : m_file_path(file_path)
17  {
18  if(file_path.empty())
19  throw Invalid_Argument("PKCS11 no module path specified");
20  reload(init_args);
21  }
22 
23 Module::~Module() noexcept
24  {
25  try
26  {
27  m_low_level->C_Finalize(nullptr, nullptr);
28  }
29  catch(...)
30  {
31  // we are noexcept and must swallow any exception here
32  }
33  }
34 
36  {
37  if(m_low_level)
38  {
39  m_low_level->C_Finalize(nullptr);
40  }
41 
42  m_library.reset(new Dynamically_Loaded_Library(m_file_path));
43  LowLevel::C_GetFunctionList(*m_library, &m_func_list);
44  m_low_level.reset(new LowLevel(m_func_list));
45 
46  m_low_level->C_Initialize(&init_args);
47  }
48 
49 }
50 }
static bool C_GetFunctionList(Dynamically_Loaded_Library &pkcs11_module, FunctionListPtr *function_list_ptr_ptr, ReturnValue *return_value=ThrowException)
Definition: p11.cpp:102
Provides access to all PKCS#11 functions.
Definition: p11.h:901
Definition: alg_id.cpp:13
Module(const std::string &file_path, C_InitializeArgs init_args={ nullptr, nullptr, nullptr, nullptr, static_cast< CK_FLAGS >(Flag::OsLockingOk), nullptr })
Definition: p11_module.cpp:15
void reload(C_InitializeArgs init_args={ nullptr, nullptr, nullptr, nullptr, static_cast< CK_FLAGS >(Flag::OsLockingOk), nullptr })
Definition: p11_module.cpp:35
~Module() noexcept
Calls C_Finalize()
Definition: p11_module.cpp:23