Skip to content

Commit

Permalink
src: test and code review updates [squash]
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jul 12, 2024
1 parent 067c59f commit b4bbcab
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ with-code-cache test-code-cache:
out/Makefile: config.gypi common.gypi node.gyp \
deps/uv/uv.gyp deps/llhttp/llhttp.gyp deps/zlib/zlib.gyp \
deps/simdutf/simdutf.gyp deps/ada/ada.gyp deps/nbytes/nbytes.gyp \
deps/ncrypto/ncrypto.gyp tools/v8_gypfiles/toolchain.gypi \
tools/v8_gypfiles/toolchain.gypi \
tools/v8_gypfiles/features.gypi \
tools/v8_gypfiles/inspector.gypi tools/v8_gypfiles/v8.gyp
$(PYTHON) tools/gyp_node.py -f make
Expand Down
6 changes: 3 additions & 3 deletions deps/ncrypto/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ void EnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) {
if (engine != nullptr) {
if (finish_on_exit) {
// This also does the equivalent of ENGINE_free.
NCRYPTO_ASSERT_EQUAL(ENGINE_finish(engine), 1, "ENGINE_finish");
ENGINE_finish(engine);
} else {
NCRYPTO_ASSERT_EQUAL(ENGINE_free(engine), 1, "ENGINE_finish");
ENGINE_free(engine);
}
}
engine = engine_;
Expand Down Expand Up @@ -70,7 +70,7 @@ bool EnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
bool EnginePointer::init(bool finish_on_exit) {
if (engine == nullptr) return false;
if (finish_on_exit) setFinishOnExit();
return ENGINE_init(engine) != 0;
return ENGINE_init(engine) == 1;
}

EVPKeyPointer EnginePointer::loadPrivateKey(const std::string_view key_name) {
Expand Down
1 change: 1 addition & 0 deletions deps/ncrypto/ncrypto.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ncrypto.h"
#include <algorithm>
#include <cstring>
#include "openssl/bn.h"
#if OPENSSL_VERSION_MAJOR >= 3
#include "openssl/provider.h"
Expand Down
4 changes: 2 additions & 2 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,8 @@
'deps/simdutf/simdutf.gyp:simdutf',
'deps/ada/ada.gyp:ada',
'deps/nbytes/nbytes.gyp:nbytes',
'deps/ncrypto/ncrypto.gyp:ncrypto',
'node_js2c#host',
'deps/ncrypto/ncrypto.gyp:ncrypto',
],

'sources': [
Expand Down Expand Up @@ -1369,9 +1369,9 @@
'deps/sqlite/sqlite.gyp:sqlite',
'deps/ada/ada.gyp:ada',
'deps/nbytes/nbytes.gyp:nbytes',
'deps/ncrypto/ncrypto.gyp:ncrypto',
'deps/simdjson/simdjson.gyp:simdjson',
'deps/simdutf/simdutf.gyp:simdutf',
'deps/ncrypto/ncrypto.gyp:ncrypto',
],

'includes': [
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ void SecureContext::SetEngineKey(const FunctionCallbackInfo<Value>& args) {
return;
}

if (engine.init(true /* finish on exit*/)) {
if (!engine.init(true /* finish on exit*/)) {
return THROW_ERR_CRYPTO_OPERATION_FAILED(
env, "Failure to initialize engine");
}
Expand Down
16 changes: 6 additions & 10 deletions src/crypto/crypto_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ bool CryptoErrorStore::Empty() const {
return errors_.empty();
}

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

Local<Value> exception = Exception::Error(message);
Expand All @@ -277,13 +277,9 @@ v8::MaybeLocal<v8::Value> cryptoErrorListToException(
auto last = errors.end();
last--;
while (current != last) {
Local<String> error;
if (!String::NewFromUtf8(env->isolate(),
current->data(),
NewStringType::kNormal,
current->size())
.ToLocal(&error)) {
return MaybeLocal<Value>();
Local<Value> error;
if (!ToV8Value(env->context(), *current).ToLocal(&error)) {
return {};
}
stack.push_back(error);
++current;
Expand All @@ -295,7 +291,7 @@ v8::MaybeLocal<v8::Value> cryptoErrorListToException(
if (!exception_obj
->Set(env->context(), env->openssl_error_stack(), stackArray)
.IsNothing()) {
return MaybeLocal<Value>();
return {};
}
}
return exception;
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-process-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ if (hasUndici) {

if (common.hasCrypto) {
expected_keys.push('openssl');
expected_keys.push('ncrypto');
}

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

if (common.hasCrypto) {
assert.match(process.versions.ncrypto, commonTemplate);
if (process.config.variables.node_shared_openssl) {
assert.ok(process.versions.openssl);
} else {
Expand Down

0 comments on commit b4bbcab

Please sign in to comment.