Skip to content

Commit c154479

Browse files
committed
src: test and code review updates [squash]
1 parent 067c59f commit c154479

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

deps/ncrypto/engine.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool EnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
7070
bool EnginePointer::init(bool finish_on_exit) {
7171
if (engine == nullptr) return false;
7272
if (finish_on_exit) setFinishOnExit();
73-
return ENGINE_init(engine) != 0;
73+
return ENGINE_init(engine) == 1;
7474
}
7575

7676
EVPKeyPointer EnginePointer::loadPrivateKey(const std::string_view key_name) {

deps/ncrypto/ncrypto.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "ncrypto.h"
22
#include <algorithm>
3+
#include <cstring>
34
#include "openssl/bn.h"
45
#if OPENSSL_VERSION_MAJOR >= 3
56
#include "openssl/provider.h"

src/crypto/crypto_context.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ void SecureContext::SetEngineKey(const FunctionCallbackInfo<Value>& args) {
671671
return;
672672
}
673673

674-
if (engine.init(true /* finish on exit*/)) {
674+
if (!engine.init(true /* finish on exit*/)) {
675675
return THROW_ERR_CRYPTO_OPERATION_FAILED(
676676
env, "Failure to initialize engine");
677677
}

src/crypto/crypto_util.cc

+6-10
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ bool CryptoErrorStore::Empty() const {
243243
return errors_.empty();
244244
}
245245

246-
v8::MaybeLocal<v8::Value> cryptoErrorListToException(
246+
MaybeLocal<Value> cryptoErrorListToException(
247247
Environment* env, const ncrypto::CryptoErrorList& errors) {
248248
// The CryptoErrorList contains a listing of zero or more errors.
249249
// If there are no errors, it is likely a bug but we will return
@@ -261,7 +261,7 @@ v8::MaybeLocal<v8::Value> cryptoErrorListToException(
261261
if (!String::NewFromUtf8(
262262
env->isolate(), last.data(), NewStringType::kNormal, last.size())
263263
.ToLocal(&message)) {
264-
return MaybeLocal<Value>();
264+
return {};
265265
}
266266

267267
Local<Value> exception = Exception::Error(message);
@@ -277,13 +277,9 @@ v8::MaybeLocal<v8::Value> cryptoErrorListToException(
277277
auto last = errors.end();
278278
last--;
279279
while (current != last) {
280-
Local<String> error;
281-
if (!String::NewFromUtf8(env->isolate(),
282-
current->data(),
283-
NewStringType::kNormal,
284-
current->size())
285-
.ToLocal(&error)) {
286-
return MaybeLocal<Value>();
280+
Local<Value> error;
281+
if (!ToV8Value(env->context(), *current).ToLocal(&error)) {
282+
return {};
287283
}
288284
stack.push_back(error);
289285
++current;
@@ -295,7 +291,7 @@ v8::MaybeLocal<v8::Value> cryptoErrorListToException(
295291
if (!exception_obj
296292
->Set(env->context(), env->openssl_error_stack(), stackArray)
297293
.IsNothing()) {
298-
return MaybeLocal<Value>();
294+
return {};
299295
}
300296
}
301297
return exception;

test/parallel/test-process-versions.js

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ if (hasUndici) {
3434

3535
if (common.hasCrypto) {
3636
expected_keys.push('openssl');
37+
expected_keys.push('ncrypto');
3738
}
3839

3940
if (common.hasQuic) {
@@ -78,6 +79,7 @@ assert.match(process.versions.modules, /^\d+$/);
7879
assert.match(process.versions.cjs_module_lexer, commonTemplate);
7980

8081
if (common.hasCrypto) {
82+
assert.match(process.versions.ncrypto, commonTemplate);
8183
if (process.config.variables.node_shared_openssl) {
8284
assert.ok(process.versions.openssl);
8385
} else {

0 commit comments

Comments
 (0)