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/README.md +43 -1
- package/binding.gyp +51 -4
- package/dist/lib/card-wrapper.d.ts.map +1 -1
- package/dist/lib/card-wrapper.js +37 -1
- package/dist/lib/card-wrapper.js.map +1 -1
- package/dist/lib/devices.d.ts +26 -5
- package/dist/lib/devices.d.ts.map +1 -1
- package/dist/lib/devices.js +187 -55
- package/dist/lib/devices.js.map +1 -1
- package/dist/lib/errors.d.ts +24 -2
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +66 -7
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +25 -11
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/t0-handler.d.ts.map +1 -1
- package/dist/lib/t0-handler.js +60 -12
- package/dist/lib/t0-handler.js.map +1 -1
- package/dist/lib/types.d.ts +11 -5
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +15 -2
- package/src/addon.cpp +23 -0
- package/src/addon_data.h +23 -0
- package/src/async_workers.cpp +182 -24
- package/src/async_workers.h +104 -14
- package/src/pcsc_card.cpp +27 -24
- package/src/pcsc_card.h +11 -5
- package/src/pcsc_context.cpp +53 -59
- package/src/pcsc_context.h +12 -7
- package/src/pcsc_context_handle.h +39 -0
- package/src/pcsc_errors.h +35 -0
- package/src/pcsc_napi_error.h +36 -0
- package/src/pcsc_reader.cpp +15 -9
- package/src/pcsc_reader.h +7 -5
- package/src/platform/pcsc.h +22 -0
- package/src/reader_monitor.cpp +487 -244
- package/src/reader_monitor.h +48 -7
- package/src/reader_state_utils.h +64 -0
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,
|
|
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
|
-
|
|
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
|
|
package/src/platform/pcsc.h
CHANGED
|
@@ -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)
|