3
* (C) 2016 Daniel Neus, Sirrix AG
4
* (C) 2016 Philipp Weber, Sirrix AG
6
* Botan is released under the Simplified BSD License (see license.txt)
9
#ifndef BOTAN_P11_MODULE_H_
10
#define BOTAN_P11_MODULE_H_
15
#include <botan/p11.h>
16
#include <botan/dyn_load.h>
22
* Loads the PKCS#11 shared library
23
* Calls C_Initialize on load and C_Finalize on destruction
25
class BOTAN_PUBLIC_API(2,0) Module final
29
* Loads the shared library and calls C_Initialize
30
* @param file_path the path to the PKCS#11 shared library
31
* @param init_args flags to use for `C_Initialize`
33
Module(const std::string& file_path, C_InitializeArgs init_args = { nullptr, nullptr, nullptr, nullptr, static_cast< CK_FLAGS >(Flag::OsLockingOk), nullptr });
35
/* Microsoft Visual Studio <= 2013 does not support default generated move special member functions.
36
Everything else we target should support it */
37
#if !defined( _MSC_VER ) || ( _MSC_VER >= 1900 )
38
Module(Module&& other) = default;
39
Module& operator=(Module&& other) = default;
42
// Dtor calls C_Finalize(). A copy could be deleted while the origin still exists
43
// Furthermore std::unique_ptr member -> not copyable
44
Module(const Module& other) = delete;
45
Module& operator=(const Module& other) = delete;
47
/// Calls C_Finalize()
48
~Module() BOTAN_NOEXCEPT;
51
* Reloads the module and reinitializes it
52
* @param init_args flags to use for `C_Initialize`
54
void reload(C_InitializeArgs init_args = { nullptr, nullptr, nullptr, nullptr, static_cast< CK_FLAGS >(Flag::OsLockingOk), nullptr });
56
inline LowLevel* operator->() const
58
return m_low_level.get();
61
/// @return general information about Cryptoki
62
inline Info get_info() const
65
m_low_level->C_GetInfo(&info);
70
const std::string m_file_path;
71
FunctionListPtr m_func_list = nullptr;
72
std::unique_ptr<Dynamically_Loaded_Library> m_library = nullptr;
73
std::unique_ptr<LowLevel> m_low_level = nullptr;