Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

p11_module.h
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 #ifndef BOTAN_P11_MODULE_H__
10 #define BOTAN_P11_MODULE_H__
11
12 #include <string>
13 #include <memory>
14
15 #include <botan/p11.h>
16 #include <botan/dyn_load.h>
17
18 namespace Botan {
19 namespace PKCS11 {
20
21 /**
22 * Loads the PKCS#11 shared library
23 * Calls C_Initialize on load and C_Finalize on destruction
24 */
25 class BOTAN_DLL Module final
26 {
27 public:
28 /**
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`
32 */
33 Module(const std::string& file_path, C_InitializeArgs init_args = { nullptr, nullptr, nullptr, nullptr, static_cast< CK_FLAGS >(Flag::OsLockingOk), nullptr });
34
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;
40 #endif
41
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;
46
47 /// Calls C_Finalize()
48 ~Module() BOTAN_NOEXCEPT;
49
50 /**
51 * Reloads the module and reinitializes it
52 * @param init_args flags to use for `C_Initialize`
53 */
54 void reload(C_InitializeArgs init_args = { nullptr, nullptr, nullptr, nullptr, static_cast< CK_FLAGS >(Flag::OsLockingOk), nullptr });
55
56 inline LowLevel* operator->() const
57 {
58 return m_low_level.get();
59 }
60
61 /// @return general information about Cryptoki
62 inline Info get_info() const
63 {
64 Info info;
65 m_low_level->C_GetInfo(&info);
66 return info;
67 }
68
69 private:
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;
74 };
75
76 }
77 }
78
79 #endif
Botan::PKCS11::Module::operator->
LowLevel * operator->() const
Definition: p11_module.h:56
Botan::PKCS11::Module::get_info
Info get_info() const
Definition: p11_module.h:62
Botan::PKCS11::Module
Definition: p11_module.h:25
BOTAN_NOEXCEPT
#define BOTAN_NOEXCEPT
Definition: compiler.h:116
Botan::PKCS11::Flag::OsLockingOk
Botan::PKCS11::FunctionListPtr
CK_FUNCTION_LIST_PTR FunctionListPtr
Definition: p11.h:825
Botan::PKCS11::LowLevel
Provides access to all PKCS#11 functions.
Definition: p11.h:901
Botan
Definition: alg_id.cpp:13
CK_FLAGS
CK_ULONG CK_FLAGS
Definition: pkcs11t.h:54
CK_INFO
Definition: pkcs11t.h:86
CK_C_INITIALIZE_ARGS
Definition: pkcs11t.h:1213