smartcard 3.7.2 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/pcsc_reader.h CHANGED
@@ -4,11 +4,12 @@
4
4
  #include <string>
5
5
  #include <vector>
6
6
  #include "platform/pcsc.h"
7
+ #include "pcsc_context_handle.h"
7
8
 
8
9
  class PCSCReader : public Napi::ObjectWrap<PCSCReader> {
9
10
  public:
10
11
  static Napi::Object Init(Napi::Env env, Napi::Object exports);
11
- static Napi::Object NewInstance(Napi::Env env, SCARDCONTEXT context,
12
+ static Napi::Object NewInstance(Napi::Env env, ContextHandlePtr context,
12
13
  const std::string& name, DWORD state,
13
14
  const std::vector<uint8_t>& atr);
14
15
 
@@ -18,16 +19,17 @@ public:
18
19
  const std::string& GetName() const { return name_; }
19
20
  DWORD GetState() const { return state_; }
20
21
  const std::vector<uint8_t>& GetAtr() const { return atr_; }
21
- SCARDCONTEXT GetContext() const { return context_; }
22
+ SCARDCONTEXT GetContext() const { return context_ ? context_->Get() : 0; }
22
23
 
23
24
  // Update state (called from monitoring)
24
25
  void UpdateState(DWORD state, const std::vector<uint8_t>& atr);
25
26
 
26
27
  private:
27
- static Napi::FunctionReference constructor;
28
-
29
28
  std::string name_;
30
- SCARDCONTEXT context_;
29
+ // Shared with the PCSCContext that created this reader, so the handle
30
+ // outlives the Context object; checked before use, since close() can
31
+ // still release it
32
+ ContextHandlePtr context_;
31
33
  DWORD state_;
32
34
  std::vector<uint8_t> atr_;
33
35
 
@@ -37,5 +37,27 @@
37
37
  #define MAX_ATR_SIZE 33
38
38
  #endif
39
39
 
40
+ // pcsc-lite keeps a per-reader card insertion/removal counter in the upper
41
+ // 16 bits of dwEventState. Windows and macOS don't document that word for
42
+ // reader entries (Windows uses it for the reader count on the PnP entry),
43
+ // so it is only relied on with pcsc-lite.
44
+ #if defined(_WIN32) || defined(__APPLE__)
45
+ #define SMARTCARD_PCSC_COUNTS_CARD_EVENTS false
46
+ #else
47
+ #define SMARTCARD_PCSC_COUNTS_CARD_EVENTS true
48
+ #endif
49
+
50
+ // pcsc-lite 2.3.0 and later put a count of reader events (readers added or
51
+ // removed) in the upper 16 bits of the "\\?PnP?\Notification" entry's
52
+ // dwEventState. Passed back as its dwCurrentState, the next call returns at
53
+ // once if readers changed in between. Older pcsc-lite leaves the word 0,
54
+ // and a 0 count turns the check off. Windows reports the reader count there
55
+ // instead, untested here; macOS doesn't support the PnP entry.
56
+ #if defined(_WIN32) || defined(__APPLE__)
57
+ #define SMARTCARD_PCSC_PNP_COUNTS_READER_EVENTS false
58
+ #else
59
+ #define SMARTCARD_PCSC_PNP_COUNTS_READER_EVENTS true
60
+ #endif
61
+
40
62
  // Helper macro for unused parameters
41
63
  #define PCSC_UNUSED(x) (void)(x)