Botan 3.5.0
Crypto and TLS for C&
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_types.h>
10
11#include <botan/internal/dyn_load.h>
12
13namespace Botan::PKCS11 {
14
15Module::Module(std::string_view file_path, C_InitializeArgs init_args) : m_file_path(file_path) {
16 if(file_path.empty()) {
17 throw Invalid_Argument("PKCS11 no module path specified");
18 }
19 reload(init_args);
20}
21
22Module::Module(Module&& other) noexcept = default;
23
24Module::~Module() noexcept {
25 try {
26 m_low_level->C_Finalize(nullptr, nullptr);
27 } catch(...) {
28 // we are noexcept and must swallow any exception here
29 }
30}
31
33 if(m_low_level) {
34 m_low_level->C_Finalize(nullptr);
35 }
36
37 m_library = std::make_unique<Dynamically_Loaded_Library>(m_file_path);
38 LowLevel::C_GetFunctionList(*m_library, &m_func_list);
39 m_low_level = std::make_unique<LowLevel>(m_func_list);
40
41 m_low_level->C_Initialize(&init_args);
42}
43
44} // namespace Botan::PKCS11
static bool C_GetFunctionList(Dynamically_Loaded_Library &pkcs11_module, FunctionListPtr *function_list_ptr_ptr, ReturnValue *return_value=ThrowException)
Definition p11.cpp:84
~Module() noexcept
Calls C_Finalize()
void reload(C_InitializeArgs init_args={ nullptr, nullptr, nullptr, nullptr, static_cast< CK_FLAGS >(Flag::OsLockingOk), nullptr})
Module(std::string_view file_path, C_InitializeArgs init_args={ nullptr, nullptr, nullptr, nullptr, static_cast< CK_FLAGS >(Flag::OsLockingOk), nullptr})