Botan 2.13.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_PUBLIC_API(2,0) 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 Module(Module&& other) = default;
36 Module& operator=(Module&& other) = delete;
37
38 // Dtor calls C_Finalize(). A copy could be deleted while the origin still exists
39 // Furthermore std::unique_ptr member -> not copyable
40 Module(const Module& other) = delete;
41 Module& operator=(const Module& other) = delete;
42
43 /// Calls C_Finalize()
44 ~Module() noexcept;
45
46 /**
47 * Reloads the module and reinitializes it
48 * @param init_args flags to use for `C_Initialize`
49 */
50 void reload(C_InitializeArgs init_args = { nullptr, nullptr, nullptr, nullptr, static_cast< CK_FLAGS >(Flag::OsLockingOk), nullptr });
51
52 inline LowLevel* operator->() const
53 {
54 return m_low_level.get();
55 }
56
57 /// @return general information about Cryptoki
58 inline Info get_info() const
59 {
60 Info info;
61 m_low_level->C_GetInfo(&info);
62 return info;
63 }
64
65 private:
66 const std::string m_file_path;
67 FunctionListPtr m_func_list = nullptr;
68 std::unique_ptr<Dynamically_Loaded_Library> m_library = nullptr;
69 std::unique_ptr<LowLevel> m_low_level = nullptr;
70 };
71
72 }
73 }
74
75 #endif
Botan::PKCS11::Module::operator->
LowLevel * operator->() const
Definition: p11_module.h:52
Botan::PKCS11::Module::get_info
Info get_info() const
Definition: p11_module.h:58
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::PKCS11::Module
Definition: p11_module.h:25
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