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

« back to all changes in this revision

Viewing changes to src/lib/prov/pkcs11/p11_session.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 Session
 
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_SESSION_H_
 
10
#define BOTAN_P11_SESSION_H_
 
11
 
 
12
#include <botan/p11_slot.h>
 
13
 
 
14
#include <utility>
 
15
 
 
16
namespace Botan {
 
17
namespace PKCS11 {
 
18
class Module;
 
19
 
 
20
/// Represents a PKCS#11 session
 
21
class BOTAN_PUBLIC_API(2,0) Session final
 
22
   {
 
23
   public:
 
24
      /**
 
25
      * @param slot the slot to use
 
26
      * @param read_only true if the session should be read only, false to create a read-write session
 
27
      */
 
28
      Session(Slot& slot, bool read_only);
 
29
 
 
30
      /**
 
31
      * @param slot the slot to use
 
32
      * @param flags the flags to use for the session. Remark: Flag::SerialSession is mandatory
 
33
      * @param callback_data application-defined pointer to be passed to the notification callback
 
34
      * @param notify_callback address of the notification callback function
 
35
      */
 
36
      Session(Slot& slot, Flags flags, VoidPtr callback_data, Notify notify_callback);
 
37
 
 
38
      /// Takes ownership of a session
 
39
      Session(Slot& slot, SessionHandle handle);
 
40
 
 
41
/* Microsoft Visual Studio <= 2013 does not support default generated move special member functions.
 
42
   Everything else we target should support it */
 
43
#if !defined( _MSC_VER ) || ( _MSC_VER >= 1900 )
 
44
      Session(Session&& other) = default;
 
45
      Session& operator=(Session&& other) = default;
 
46
#endif
 
47
 
 
48
      // Dtor calls C_CloseSession() and eventually C_Logout. A copy could close the session while the origin still exists
 
49
      Session(const Session& other) = delete;
 
50
      Session& operator=(const Session& other) = delete;
 
51
 
 
52
      /// Logout user and close the session on destruction
 
53
      ~Session() BOTAN_NOEXCEPT;
 
54
 
 
55
      /// @return a reference to the slot
 
56
      inline const Slot& slot() const
 
57
         {
 
58
         return m_slot;
 
59
         }
 
60
 
 
61
      /// @return the session handle of this session
 
62
      inline SessionHandle handle() const
 
63
         {
 
64
         return m_handle;
 
65
         }
 
66
 
 
67
      /// @return a reference to the used module
 
68
      inline Module& module() const
 
69
         {
 
70
         return m_slot.module();
 
71
         }
 
72
 
 
73
      /// @return the released session handle
 
74
      SessionHandle release();
 
75
 
 
76
      /**
 
77
      * Login to this session
 
78
      * @param userType the user type to use for the login
 
79
      * @param pin the PIN of the user
 
80
      */
 
81
      void login(UserType userType, const secure_string& pin);
 
82
 
 
83
      /// Logout from this session
 
84
      void logoff();
 
85
 
 
86
      /// @return information about this session
 
87
      SessionInfo get_info() const;
 
88
 
 
89
      /// Calls `C_SetPIN` to change the PIN using the old PIN (requires a logged in session)
 
90
      void set_pin(const secure_string& old_pin, const secure_string& new_pin) const;
 
91
 
 
92
      /// Calls `C_InitPIN` to change or initialize the PIN using the SO_PIN (requires a logged in session)
 
93
      void init_pin(const secure_string& new_pin);
 
94
 
 
95
   private:
 
96
      const Slot& m_slot;
 
97
      SessionHandle m_handle;
 
98
      bool m_logged_in;
 
99
   };
 
100
 
 
101
}
 
102
}
 
103
 
 
104
#endif