~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/lib/prov/pkcs11/p11_module.h

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/* 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