smartcard 3.8.0 → 3.10.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 +21 -1
- package/binding.gyp +5 -1
- package/dist/lib/devices.d.ts +18 -1
- package/dist/lib/devices.d.ts.map +1 -1
- package/dist/lib/devices.js +85 -26
- package/dist/lib/devices.js.map +1 -1
- package/dist/lib/types.d.ts +9 -4
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/addon.cpp +4 -1
- package/src/addon_data.h +23 -0
- package/src/async_workers.cpp +208 -16
- package/src/async_workers.h +94 -21
- package/src/pcsc_card.cpp +3 -5
- package/src/pcsc_card.h +0 -2
- package/src/pcsc_context.cpp +79 -53
- package/src/pcsc_context.h +7 -3
- package/src/pcsc_napi_error.h +1 -8
- package/src/pcsc_reader.cpp +3 -5
- package/src/pcsc_reader.h +0 -2
- package/src/platform/pcsc.h +22 -0
- package/src/reader_monitor.cpp +378 -167
- package/src/reader_monitor.h +37 -6
- package/src/reader_state_utils.h +42 -2
package/src/pcsc_napi_error.h
CHANGED
|
@@ -3,14 +3,7 @@
|
|
|
3
3
|
#include <napi.h>
|
|
4
4
|
#include <string>
|
|
5
5
|
#include "pcsc_errors.h"
|
|
6
|
-
|
|
7
|
-
// Per-instance addon state (each worker_thread loads its own instance)
|
|
8
|
-
struct AddonData {
|
|
9
|
-
// (message, code) => Error, registered by lib/index.ts via
|
|
10
|
-
// setErrorFactory() so native failures arrive as the typed PCSCError
|
|
11
|
-
// classes from lib/errors.ts
|
|
12
|
-
Napi::FunctionReference errorFactory;
|
|
13
|
-
};
|
|
6
|
+
#include "addon_data.h"
|
|
14
7
|
|
|
15
8
|
// Build a JS Error for a PC/SC failure. The code is exposed unsigned
|
|
16
9
|
// (e.g. 0x80100069) to match the constants in lib/errors.ts; message
|
package/src/pcsc_reader.cpp
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
#include "pcsc_card.h"
|
|
3
3
|
#include "pcsc_errors.h"
|
|
4
4
|
#include "pcsc_napi_error.h"
|
|
5
|
+
#include "addon_data.h"
|
|
5
6
|
#include "async_workers.h"
|
|
6
7
|
|
|
7
|
-
Napi::FunctionReference PCSCReader::constructor;
|
|
8
|
-
|
|
9
8
|
Napi::Object PCSCReader::Init(Napi::Env env, Napi::Object exports) {
|
|
10
9
|
Napi::Function func = DefineClass(env, "Reader", {
|
|
11
10
|
InstanceAccessor("name", &PCSCReader::GetNameValue, nullptr),
|
|
@@ -14,8 +13,7 @@ Napi::Object PCSCReader::Init(Napi::Env env, Napi::Object exports) {
|
|
|
14
13
|
InstanceMethod("connect", &PCSCReader::Connect),
|
|
15
14
|
});
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
constructor.SuppressDestruct();
|
|
16
|
+
env.GetInstanceData<AddonData>()->readerConstructor = Napi::Persistent(func);
|
|
19
17
|
|
|
20
18
|
exports.Set("Reader", func);
|
|
21
19
|
return exports;
|
|
@@ -24,7 +22,7 @@ Napi::Object PCSCReader::Init(Napi::Env env, Napi::Object exports) {
|
|
|
24
22
|
Napi::Object PCSCReader::NewInstance(Napi::Env env, ContextHandlePtr context,
|
|
25
23
|
const std::string& name, DWORD state,
|
|
26
24
|
const std::vector<uint8_t>& atr) {
|
|
27
|
-
Napi::Object obj =
|
|
25
|
+
Napi::Object obj = env.GetInstanceData<AddonData>()->readerConstructor.New({});
|
|
28
26
|
PCSCReader* reader = Napi::ObjectWrap<PCSCReader>::Unwrap(obj);
|
|
29
27
|
reader->context_ = std::move(context);
|
|
30
28
|
reader->name_ = name;
|
package/src/pcsc_reader.h
CHANGED
|
@@ -25,8 +25,6 @@ public:
|
|
|
25
25
|
void UpdateState(DWORD state, const std::vector<uint8_t>& atr);
|
|
26
26
|
|
|
27
27
|
private:
|
|
28
|
-
static Napi::FunctionReference constructor;
|
|
29
|
-
|
|
30
28
|
std::string name_;
|
|
31
29
|
// Shared with the PCSCContext that created this reader, so the handle
|
|
32
30
|
// outlives the Context object; checked before use, since close() can
|
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)
|