edhoc 1.2.2 → 1.3.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.
Files changed (39) hide show
  1. package/dist/edhoc.d.ts +4 -0
  2. package/dist/edhoc.d.ts.map +1 -1
  3. package/include/{LibEDHOC.h → Binding.h} +60 -40
  4. package/include/EdhocComposeAsyncWorker.h +8 -22
  5. package/include/EdhocCredentialManager.h +9 -25
  6. package/include/EdhocCryptoManager.h +27 -43
  7. package/include/EdhocEadManager.h +3 -4
  8. package/include/EdhocExportOscoreAsyncWorker.h +10 -27
  9. package/include/EdhocKeyExporterAsyncWorker.h +8 -28
  10. package/include/EdhocKeyUpdateAsyncWorker.h +7 -24
  11. package/include/EdhocProcessAsyncWorker.h +11 -36
  12. package/include/RunningContext.h +102 -0
  13. package/include/Utils.h +0 -43
  14. package/package.json +1 -2
  15. package/prebuilds/android-arm/edhoc.armv7.node +0 -0
  16. package/prebuilds/android-arm64/edhoc.armv8.node +0 -0
  17. package/prebuilds/darwin-arm64/edhoc.node +0 -0
  18. package/prebuilds/darwin-x64/edhoc.node +0 -0
  19. package/prebuilds/linux-arm/edhoc.armv6.node +0 -0
  20. package/prebuilds/linux-arm/edhoc.armv7.node +0 -0
  21. package/prebuilds/linux-arm64/edhoc.armv8.node +0 -0
  22. package/prebuilds/linux-x64/edhoc.glibc.node +0 -0
  23. package/prebuilds/linux-x64/edhoc.musl.node +0 -0
  24. package/prebuilds/win32-ia32/edhoc.node +0 -0
  25. package/prebuilds/win32-x64/edhoc.node +0 -0
  26. package/src/Binding.cpp +434 -0
  27. package/src/EdhocComposeAsyncWorker.cpp +15 -26
  28. package/src/EdhocCredentialManager.cpp +50 -69
  29. package/src/EdhocCryptoManager.cpp +158 -332
  30. package/src/EdhocEadManager.cpp +11 -11
  31. package/src/EdhocExportOscoreAsyncWorker.cpp +18 -28
  32. package/src/EdhocKeyExporterAsyncWorker.cpp +11 -21
  33. package/src/EdhocKeyUpdateAsyncWorker.cpp +8 -18
  34. package/src/EdhocProcessAsyncWorker.cpp +28 -35
  35. package/src/RunningContext.cpp +95 -0
  36. package/src/Utils.cpp +1 -38
  37. package/test/basic.test.ts +57 -3
  38. package/include/UserContext.h +0 -77
  39. package/src/LibEDHOC.cpp +0 -408
@@ -1,77 +0,0 @@
1
- #ifndef USER_CONTEXT_H
2
- #define USER_CONTEXT_H
3
-
4
- #include <napi.h>
5
-
6
- #include <memory>
7
-
8
- #include "EdhocCredentialManager.h"
9
- #include "EdhocCryptoManager.h"
10
- #include "EdhocEadManager.h"
11
-
12
- /**
13
- * @class UserContext
14
- * @brief Represents the user context for the Edhoc protocol.
15
- *
16
- * The UserContext class encapsulates the necessary components for the Edhoc
17
- * protocol, including the crypto manager, EAD manager, and credential manager.
18
- * It also provides access to a logger and a parent object reference.
19
- */
20
- class UserContext {
21
- public:
22
- /**
23
- * @brief Constructs a UserContext object with the specified components.
24
- *
25
- * @param cryptoManager The shared pointer to the EdhocCryptoManager.
26
- * @param eadManager The shared pointer to the EdhocEadManager.
27
- * @param credentialManager The shared pointer to the EdhocCredentialManager.
28
- */
29
- UserContext(std::shared_ptr<EdhocCryptoManager> cryptoManager,
30
- std::shared_ptr<EdhocEadManager> eadManager,
31
- std::shared_ptr<EdhocCredentialManager> credentialManager)
32
- : cryptoManager(std::move(cryptoManager)),
33
- eadManager(std::move(eadManager)),
34
- credentialManager(std::move(credentialManager)) {}
35
-
36
- /**
37
- * @brief Destroys the UserContext object.
38
- *
39
- * If a logger is present, it will be released.
40
- */
41
- virtual ~UserContext() {
42
- if (logger) {
43
- logger.Release();
44
- }
45
- }
46
-
47
- /**
48
- * @brief Gets the crypto manager associated with the UserContext.
49
- *
50
- * @return A pointer to the EdhocCryptoManager.
51
- */
52
- EdhocCryptoManager* GetCryptoManager() const { return cryptoManager.get(); }
53
-
54
- /**
55
- * @brief Gets the EAD manager associated with the UserContext.
56
- *
57
- * @return A pointer to the EdhocEadManager.
58
- */
59
- EdhocEadManager* GetEadManager() const { return eadManager.get(); }
60
-
61
- /**
62
- * @brief Gets the credential manager associated with the UserContext.
63
- *
64
- * @return A pointer to the EdhocCredentialManager.
65
- */
66
- EdhocCredentialManager* GetCredentialManager() const { return credentialManager.get(); }
67
-
68
- Napi::ThreadSafeFunction logger; ///< The logger for the UserContext
69
- Napi::ObjectReference parent; ///< The parent object reference for the UserContext
70
-
71
- protected:
72
- std::shared_ptr<EdhocCryptoManager> cryptoManager; ///< The crypto manager
73
- std::shared_ptr<EdhocEadManager> eadManager; ///< The EAD manager
74
- std::shared_ptr<EdhocCredentialManager> credentialManager; ///< The credential manager
75
- };
76
-
77
- #endif // USER_CONTEXT_H
package/src/LibEDHOC.cpp DELETED
@@ -1,408 +0,0 @@
1
- #include "LibEDHOC.h"
2
-
3
- #include <iostream>
4
- #include <thread>
5
-
6
- #include "EdhocComposeAsyncWorker.h"
7
- #include "EdhocExportOscoreAsyncWorker.h"
8
- #include "EdhocKeyExporterAsyncWorker.h"
9
- #include "EdhocKeyUpdateAsyncWorker.h"
10
- #include "EdhocProcessAsyncWorker.h"
11
- #include "Suites.h"
12
- #include "Utils.h"
13
-
14
- static constexpr const char* kErrorFailedToInitializeEdhocContext = "Failed to initialize EDHOC context.";
15
- static constexpr const char* kErrorFailedToSetEdhocConnectionId = "Failed to set EDHOC Connection ID.";
16
- static constexpr const char* kErrorFailedToSetEdhocMethod = "Failed to set EDHOC Method.";
17
- static constexpr const char* kErrorArraySuiteIndexesExpected = "Array of suite indexes expected";
18
- static constexpr const char* kErrorArrayMethodIndexesExpected = "Array of method indexes expected";
19
- static constexpr const char* kErrorInvalidCipherSuiteIndex = "Invalid cipher suite index";
20
- static constexpr const char* kErrorFailedToSetCipherSuites = "Failed to set cipher suites";
21
- static constexpr const char* kErrorExpectedFirstArgumentToBeBuffer = "Expected first argument to be a Buffer";
22
- static constexpr const char* kErrorExpectedArgumentToBeNumber = "Expected argument to be a number";
23
- static constexpr const char* kErrorExpectedAFunction = "Expected a function";
24
- static constexpr const char* kClassNameLibEDHOC = "EDHOC";
25
- static constexpr const char* kMethodComposeMessage1 = "composeMessage1";
26
- static constexpr const char* kMethodProcessMessage1 = "processMessage1";
27
- static constexpr const char* kMethodComposeMessage2 = "composeMessage2";
28
- static constexpr const char* kMethodProcessMessage2 = "processMessage2";
29
- static constexpr const char* kMethodComposeMessage3 = "composeMessage3";
30
- static constexpr const char* kMethodProcessMessage3 = "processMessage3";
31
- static constexpr const char* kMethodComposeMessage4 = "composeMessage4";
32
- static constexpr const char* kMethodProcessMessage4 = "processMessage4";
33
- static constexpr const char* kMethodExportOSCORE = "exportOSCORE";
34
- static constexpr const char* kMethodExportKey = "exportKey";
35
- static constexpr const char* kMethodKeyUpdate = "keyUpdate";
36
- static constexpr const char* kJsPropertyConnectionID = "connectionID";
37
- static constexpr const char* kJsPropertyPeerConnectionID = "peerConnectionID";
38
- static constexpr const char* kJsPropertyMethods = "methods";
39
- static constexpr const char* kJsPropertySelectedMethod = "selectedMethod";
40
- static constexpr const char* kJsPropertyCipherSuites = "cipherSuites";
41
- static constexpr const char* kJsPropertySelectedCipherSuite = "selectedSuite";
42
- static constexpr const char* kJsPropertyLogger = "logger";
43
- static constexpr const char* kLogggerFunctionName = "Logger";
44
-
45
- LibEDHOC::LibEDHOC(const Napi::CallbackInfo& info) : Napi::ObjectWrap<LibEDHOC>(info) {
46
- Napi::Env env = info.Env();
47
- Napi::HandleScope scope(env);
48
-
49
- // Initialize EDHOC context
50
- context = {};
51
- if (edhoc_context_init(&context) != EDHOC_SUCCESS) {
52
- throw Napi::TypeError::New(env, kErrorFailedToInitializeEdhocContext);
53
- }
54
-
55
- // Connection ID, Methods, and Suites
56
- SetCID(info, info[0]);
57
- SetMethods(info, info[1]);
58
- SetCipherSuites(info, info[2]);
59
-
60
- // Crypto Manager
61
- Napi::Object jsCryptoManager = info[4].As<Napi::Object>();
62
- auto cryptoManager = std::make_shared<EdhocCryptoManager>(jsCryptoManager);
63
-
64
- // Credentials
65
- Napi::Object jsCredentialManager = info[3].As<Napi::Object>();
66
- auto credentialManager = std::make_shared<EdhocCredentialManager>(jsCredentialManager);
67
- // EAD
68
- auto eadManager = std::make_shared<EdhocEadManager>();
69
-
70
- // Bind all managers
71
- if (edhoc_bind_keys(&context, &cryptoManager->keys) != EDHOC_SUCCESS ||
72
- edhoc_bind_crypto(&context, &cryptoManager->crypto) != EDHOC_SUCCESS ||
73
- edhoc_bind_credentials(&context, &credentialManager->credentials) != EDHOC_SUCCESS ||
74
- edhoc_bind_ead(&context, &eadManager->ead) != EDHOC_SUCCESS) {
75
- throw Napi::TypeError::New(env, kErrorFailedToInitializeEdhocContext);
76
- }
77
-
78
- // Logger
79
- context.logger = LibEDHOC::Logger;
80
-
81
- // User Context
82
- userContext = std::make_shared<UserContext>(cryptoManager, eadManager, credentialManager);
83
- userContext->parent = Reference<Napi::Object>::New(info.This().As<Napi::Object>());
84
-
85
- if (edhoc_set_user_context(&context, static_cast<void*>(userContext.get())) != EDHOC_SUCCESS) {
86
- throw Napi::TypeError::New(env, kErrorFailedToInitializeEdhocContext);
87
- }
88
- }
89
-
90
- LibEDHOC::~LibEDHOC() {
91
- userContext.reset();
92
- context = {};
93
- }
94
-
95
- Napi::Value LibEDHOC::GetCID(const Napi::CallbackInfo& info) {
96
- return Utils::CreateJsValueFromEdhocCid(info.Env(), cid);
97
- }
98
-
99
- void LibEDHOC::SetCID(const Napi::CallbackInfo& info, const Napi::Value& value) {
100
- cid = Utils::ConvertJsValueToEdhocCid(value);
101
- int result = edhoc_set_connection_id(&context, &cid);
102
- if (result != EDHOC_SUCCESS) {
103
- Napi::TypeError::New(info.Env(), kErrorFailedToSetEdhocConnectionId).ThrowAsJavaScriptException();
104
- }
105
- }
106
-
107
- Napi::Value LibEDHOC::GetPeerCID(const Napi::CallbackInfo& info) {
108
- return Utils::CreateJsValueFromEdhocCid(info.Env(), context.EDHOC_PRIVATE(peer_cid));
109
- }
110
-
111
- Napi::Value LibEDHOC::GetMethods(const Napi::CallbackInfo& info) {
112
- Napi::Env env = info.Env();
113
- Napi::Array result = Napi::Array::New(env, context.EDHOC_PRIVATE(method_len));
114
- for (size_t i = 0; i < context.EDHOC_PRIVATE(method_len); i++) {
115
- result.Set(i, Napi::Number::New(env, context.EDHOC_PRIVATE(method)[i]));
116
- }
117
- return result;
118
- }
119
-
120
- void LibEDHOC::SetMethods(const Napi::CallbackInfo& info, const Napi::Value& value) {
121
- Napi::Env env = info.Env();
122
-
123
- if (!value.IsArray()) {
124
- throw Napi::TypeError::New(env, kErrorArrayMethodIndexesExpected);
125
- }
126
-
127
- const auto jsArray = value.As<Napi::Array>();
128
- std::vector<edhoc_method> methods;
129
- methods.reserve(jsArray.Length());
130
-
131
- for (uint32_t i = 0; i < jsArray.Length(); i++) {
132
- methods.push_back(static_cast<edhoc_method>(jsArray.Get(i).As<Napi::Number>().Int32Value()));
133
- }
134
-
135
- if (edhoc_set_methods(&context, methods.data(), methods.size()) != EDHOC_SUCCESS) {
136
- throw Napi::TypeError::New(env, kErrorFailedToSetEdhocMethod);
137
- }
138
- }
139
-
140
- Napi::Value LibEDHOC::GetSelectedMethod(const Napi::CallbackInfo& info) {
141
- return Napi::Number::New(info.Env(), context.EDHOC_PRIVATE(chosen_method));
142
- }
143
-
144
- void LibEDHOC::SetCipherSuites(const Napi::CallbackInfo& info, const Napi::Value& value) {
145
- Napi::Env env = info.Env();
146
-
147
- if (!value.IsArray()) {
148
- throw Napi::TypeError::New(env, kErrorArraySuiteIndexesExpected);
149
- }
150
-
151
- const auto jsArray = value.As<Napi::Array>();
152
- std::vector<edhoc_cipher_suite> selected_suites;
153
- selected_suites.reserve(jsArray.Length());
154
-
155
- for (uint32_t i = 0; i < jsArray.Length(); i++) {
156
- const uint32_t index = jsArray.Get(i).As<Napi::Number>().Uint32Value();
157
-
158
- if (index >= suite_pointers_count || suite_pointers[index] == nullptr) {
159
- throw Napi::RangeError::New(env, kErrorInvalidCipherSuiteIndex);
160
- }
161
-
162
- selected_suites.push_back(*suite_pointers[index]);
163
- }
164
-
165
- if (edhoc_set_cipher_suites(&context, selected_suites.data(), selected_suites.size()) != 0) {
166
- throw Napi::TypeError::New(env, kErrorFailedToSetCipherSuites);
167
- }
168
- }
169
-
170
- Napi::Value LibEDHOC::GetCipherSuites(const Napi::CallbackInfo& info) {
171
- Napi::Env env = info.Env();
172
- Napi::Array result = Napi::Array::New(env, context.EDHOC_PRIVATE(csuite_len));
173
- for (size_t i = 0; i < context.EDHOC_PRIVATE(csuite_len); i++) {
174
- result.Set(i, Napi::Number::New(env, context.EDHOC_PRIVATE(csuite)[i].value));
175
- }
176
- return result;
177
- }
178
-
179
- Napi::Value LibEDHOC::GetSelectedCipherSuite(const Napi::CallbackInfo& info) {
180
- Napi::Env env = info.Env();
181
- Napi::Number suite =
182
- Napi::Number::New(env, context.EDHOC_PRIVATE(csuite)[context.EDHOC_PRIVATE(chosen_csuite_idx)].value);
183
- return suite;
184
- }
185
-
186
- Napi::Value LibEDHOC::GetLogger(const Napi::CallbackInfo& info) {
187
- return logger.Value();
188
- }
189
-
190
- void LibEDHOC::SetLogger(const Napi::CallbackInfo& info, const Napi::Value& value) {
191
- if (!info[0].IsFunction()) {
192
- Napi::TypeError::New(info.Env(), kErrorExpectedAFunction).ThrowAsJavaScriptException();
193
- }
194
- Napi::Function jsCallback = info[0].As<Napi::Function>();
195
- logger = Napi::Persistent(jsCallback);
196
- userContext->logger = Napi::ThreadSafeFunction::New(info.Env(), jsCallback, kLogggerFunctionName, 0, 1);
197
- }
198
-
199
- void LibEDHOC::Logger(void* usercontext, const char* name, const uint8_t* buffer, size_t buffer_length) {
200
- auto* context = static_cast<UserContext*>(usercontext);
201
- if (!context || !context->logger) {
202
- return;
203
- }
204
-
205
- const std::vector<uint8_t> bufferCopy(buffer, buffer + buffer_length);
206
-
207
- context->logger.NonBlockingCall([name = std::string(name), bufferCopy](Napi::Env env, Napi::Function jsCallback) {
208
- jsCallback.Call(
209
- {Napi::String::New(env, name), Napi::Buffer<uint8_t>::Copy(env, bufferCopy.data(), bufferCopy.size())});
210
- });
211
- }
212
-
213
- Napi::Value LibEDHOC::ComposeMessage(const Napi::CallbackInfo& info, enum edhoc_message messageNumber) {
214
- Napi::Env env = info.Env();
215
- Napi::HandleScope scope(env);
216
-
217
- if (info[0].IsArray()) {
218
- try {
219
- userContext->GetEadManager()->StoreEad(messageNumber, info[0].As<Napi::Array>());
220
- } catch (const Napi::Error& e) {
221
- e.ThrowAsJavaScriptException();
222
- return env.Null();
223
- }
224
- }
225
-
226
- userContext->GetCredentialManager()->SetupAsyncFunctions();
227
- userContext->GetCryptoManager()->SetupAsyncFunctions();
228
-
229
- EdhocComposeAsyncWorker::CallbackType callback = [this, messageNumber](Napi::Env& env) {
230
- userContext->GetEadManager()->ClearEadByMessage(messageNumber);
231
- userContext->GetCredentialManager()->CleanupAsyncFunctions();
232
- userContext->GetCryptoManager()->CleanupAsyncFunctions();
233
- };
234
-
235
- EdhocComposeAsyncWorker* worker = new EdhocComposeAsyncWorker(env, context, messageNumber, callback);
236
- worker->Queue();
237
-
238
- return worker->GetPromise();
239
- }
240
-
241
- Napi::Value LibEDHOC::ProcessMessage(const Napi::CallbackInfo& info, enum edhoc_message messageNumber) {
242
- Napi::Env env = info.Env();
243
- Napi::HandleScope scope(env);
244
-
245
- if (info.Length() < 1 || !info[0].IsBuffer()) {
246
- Napi::TypeError::New(env, kErrorExpectedFirstArgumentToBeBuffer).ThrowAsJavaScriptException();
247
- return env.Null();
248
- }
249
- Napi::Buffer<uint8_t> inputBuffer = info[0].As<Napi::Buffer<uint8_t>>();
250
-
251
- userContext->GetCredentialManager()->SetupAsyncFunctions();
252
- userContext->GetCryptoManager()->SetupAsyncFunctions();
253
-
254
- EdhocProcessAsyncWorker::CallbackType callback = [this, messageNumber](Napi::Env& env) {
255
- Napi::Array EADs = userContext->GetEadManager()->GetEadByMessage(env, messageNumber);
256
- userContext->GetEadManager()->ClearEadByMessage(messageNumber);
257
- userContext->GetCredentialManager()->CleanupAsyncFunctions();
258
- userContext->GetCryptoManager()->CleanupAsyncFunctions();
259
- return EADs;
260
- };
261
-
262
- EdhocProcessAsyncWorker* worker = new EdhocProcessAsyncWorker(env, context, messageNumber, inputBuffer, callback);
263
- worker->Queue();
264
-
265
- return worker->GetPromise();
266
- }
267
-
268
- Napi::Value LibEDHOC::ComposeMessage1(const Napi::CallbackInfo& info) {
269
- return ComposeMessage(info, EDHOC_MSG_1);
270
- }
271
-
272
- Napi::Value LibEDHOC::ProcessMessage1(const Napi::CallbackInfo& info) {
273
- return ProcessMessage(info, EDHOC_MSG_1);
274
- }
275
-
276
- Napi::Value LibEDHOC::ComposeMessage2(const Napi::CallbackInfo& info) {
277
- return ComposeMessage(info, EDHOC_MSG_2);
278
- }
279
-
280
- Napi::Value LibEDHOC::ProcessMessage2(const Napi::CallbackInfo& info) {
281
- return ProcessMessage(info, EDHOC_MSG_2);
282
- }
283
-
284
- Napi::Value LibEDHOC::ComposeMessage3(const Napi::CallbackInfo& info) {
285
- return ComposeMessage(info, EDHOC_MSG_3);
286
- }
287
-
288
- Napi::Value LibEDHOC::ProcessMessage3(const Napi::CallbackInfo& info) {
289
- return ProcessMessage(info, EDHOC_MSG_3);
290
- }
291
-
292
- Napi::Value LibEDHOC::ComposeMessage4(const Napi::CallbackInfo& info) {
293
- return ComposeMessage(info, EDHOC_MSG_4);
294
- }
295
-
296
- Napi::Value LibEDHOC::ProcessMessage4(const Napi::CallbackInfo& info) {
297
- return ProcessMessage(info, EDHOC_MSG_4);
298
- }
299
-
300
- Napi::Value LibEDHOC::ExportOSCORE(const Napi::CallbackInfo& info) {
301
- Napi::Env env = info.Env();
302
- Napi::HandleScope scope(env);
303
-
304
- userContext->GetCredentialManager()->SetupAsyncFunctions();
305
- userContext->GetCryptoManager()->SetupAsyncFunctions();
306
-
307
- EdhocExportOscoreAsyncWorker::CallbackType callback = [this](Napi::Env& env) {
308
- userContext->GetCredentialManager()->CleanupAsyncFunctions();
309
- userContext->GetCryptoManager()->CleanupAsyncFunctions();
310
- };
311
-
312
- EdhocExportOscoreAsyncWorker* worker = new EdhocExportOscoreAsyncWorker(env, context, callback);
313
- worker->Queue();
314
-
315
- return worker->GetPromise();
316
- }
317
-
318
- Napi::Value LibEDHOC::ExportKey(const Napi::CallbackInfo& info) {
319
- Napi::Env env = info.Env();
320
- Napi::HandleScope scope(env);
321
-
322
- if (info.Length() < 1 || !info[0].IsNumber()) {
323
- Napi::TypeError::New(env, kErrorExpectedArgumentToBeNumber).ThrowAsJavaScriptException();
324
- return env.Null();
325
- }
326
-
327
- if (info.Length() < 2 || !info[1].IsNumber()) {
328
- Napi::TypeError::New(env, kErrorExpectedArgumentToBeNumber).ThrowAsJavaScriptException();
329
- return env.Null();
330
- }
331
-
332
- uint16_t label = (uint16_t)info[0].As<Napi::Number>().Uint32Value();
333
- uint8_t desiredLength = (uint8_t)info[1].As<Napi::Number>().Uint32Value();
334
-
335
- userContext->GetCredentialManager()->SetupAsyncFunctions();
336
- userContext->GetCryptoManager()->SetupAsyncFunctions();
337
-
338
- EdhocKeyExporterAsyncWorker::CallbackType callback = [this](Napi::Env& env) {
339
- userContext->GetCredentialManager()->CleanupAsyncFunctions();
340
- userContext->GetCryptoManager()->CleanupAsyncFunctions();
341
- };
342
-
343
- EdhocKeyExporterAsyncWorker* worker = new EdhocKeyExporterAsyncWorker(env, context, label, desiredLength, callback);
344
- worker->Queue();
345
-
346
- return worker->GetPromise();
347
- }
348
-
349
- Napi::Value LibEDHOC::KeyUpdate(const Napi::CallbackInfo& info) {
350
- Napi::Env env = info.Env();
351
- Napi::HandleScope scope(env);
352
-
353
- if (info.Length() < 1 || !info[0].IsBuffer()) {
354
- Napi::TypeError::New(env, kErrorExpectedFirstArgumentToBeBuffer).ThrowAsJavaScriptException();
355
- return env.Null();
356
- }
357
-
358
- Napi::Buffer<uint8_t> contextBuffer = info[0].As<Napi::Buffer<uint8_t>>();
359
- std::vector<uint8_t> contextBufferVector(contextBuffer.Data(), contextBuffer.Data() + contextBuffer.Length());
360
-
361
- userContext->GetCredentialManager()->SetupAsyncFunctions();
362
- userContext->GetCryptoManager()->SetupAsyncFunctions();
363
-
364
- EdhocKeyUpdateAsyncWorker::CallbackType callback = [this](Napi::Env& env) {
365
- userContext->GetCredentialManager()->CleanupAsyncFunctions();
366
- userContext->GetCryptoManager()->CleanupAsyncFunctions();
367
- };
368
-
369
- EdhocKeyUpdateAsyncWorker* worker = new EdhocKeyUpdateAsyncWorker(env, context, contextBufferVector, callback);
370
- worker->Queue();
371
-
372
- return worker->GetPromise();
373
- }
374
-
375
- Napi::Object LibEDHOC::Init(Napi::Env env, Napi::Object exports) {
376
- Napi::HandleScope scope(env);
377
- Napi::Function func =
378
- DefineClass(env, kClassNameLibEDHOC,
379
- {
380
- InstanceAccessor(kJsPropertyConnectionID, &LibEDHOC::GetCID, &LibEDHOC::SetCID),
381
- InstanceAccessor<&LibEDHOC::GetPeerCID>(kJsPropertyPeerConnectionID),
382
- InstanceAccessor(kJsPropertyMethods, &LibEDHOC::GetMethods, &LibEDHOC::SetMethods),
383
- InstanceAccessor<&LibEDHOC::GetSelectedMethod>(kJsPropertySelectedMethod),
384
- InstanceAccessor(kJsPropertyCipherSuites, &LibEDHOC::GetCipherSuites, &LibEDHOC::SetCipherSuites),
385
- InstanceAccessor<&LibEDHOC::GetSelectedCipherSuite>(kJsPropertySelectedCipherSuite),
386
- InstanceAccessor(kJsPropertyLogger, &LibEDHOC::GetLogger, &LibEDHOC::SetLogger),
387
- InstanceMethod(kMethodComposeMessage1, &LibEDHOC::ComposeMessage1),
388
- InstanceMethod(kMethodProcessMessage1, &LibEDHOC::ProcessMessage1),
389
- InstanceMethod(kMethodComposeMessage2, &LibEDHOC::ComposeMessage2),
390
- InstanceMethod(kMethodProcessMessage2, &LibEDHOC::ProcessMessage2),
391
- InstanceMethod(kMethodComposeMessage3, &LibEDHOC::ComposeMessage3),
392
- InstanceMethod(kMethodProcessMessage3, &LibEDHOC::ProcessMessage3),
393
- InstanceMethod(kMethodComposeMessage4, &LibEDHOC::ComposeMessage4),
394
- InstanceMethod(kMethodProcessMessage4, &LibEDHOC::ProcessMessage4),
395
- InstanceMethod(kMethodExportOSCORE, &LibEDHOC::ExportOSCORE),
396
- InstanceMethod(kMethodExportKey, &LibEDHOC::ExportKey),
397
- InstanceMethod(kMethodKeyUpdate, &LibEDHOC::KeyUpdate),
398
- });
399
-
400
- Napi::FunctionReference* constructor = new Napi::FunctionReference();
401
- *constructor = Napi::Persistent(func);
402
- env.SetInstanceData(constructor);
403
-
404
- exports.Set(kClassNameLibEDHOC, func);
405
- return exports;
406
- }
407
-
408
- NODE_API_NAMED_ADDON(addon, LibEDHOC);