From f216699ab42c19050f3278e93b657548ffa6d05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 17 Oct 2018 19:01:15 +0200 Subject: [PATCH] crypto: remove DiffieHellman.initialised_ As pointed out by Ben Noordhuis, this internal field can be removed since all instances are initialized when exposed to users. PR-URL: https://github.com/nodejs/node/pull/23717 Refs: https://github.com/nodejs/node/pull/23648 Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- src/node_crypto.cc | 23 +++-------------------- src/node_crypto.h | 2 -- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5f69e4f87ef005..7d9294d65a53b6 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4001,11 +4001,7 @@ bool DiffieHellman::Init(int primeLength, int g) { dh_.reset(DH_new()); if (!DH_generate_parameters_ex(dh_.get(), primeLength, g, 0)) return false; - bool result = VerifyContext(); - if (!result) - return false; - initialised_ = true; - return true; + return VerifyContext(); } @@ -4020,11 +4016,7 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) { BN_free(bn_g); return false; } - bool result = VerifyContext(); - if (!result) - return false; - initialised_ = true; - return true; + return VerifyContext(); } @@ -4037,11 +4029,7 @@ bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) { BN_free(bn_g); return false; } - bool result = VerifyContext(); - if (!result) - return false; - initialised_ = true; - return true; + return VerifyContext(); } @@ -4115,7 +4103,6 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo& args) { DiffieHellman* diffieHellman; ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder()); - CHECK(diffieHellman->initialised_); if (!DH_generate_key(diffieHellman->dh_.get())) { return ThrowCryptoError(env, ERR_get_error(), "Key generation failed"); @@ -4137,7 +4124,6 @@ void DiffieHellman::GetField(const FunctionCallbackInfo& args, DiffieHellman* dh; ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder()); - CHECK(dh->initialised_); const BIGNUM* num = get_field(dh->dh_.get()); if (num == nullptr) return env->ThrowError(err_if_null); @@ -4189,7 +4175,6 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo& args) { DiffieHellman* diffieHellman; ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder()); - CHECK(diffieHellman->initialised_); ClearErrorOnReturn clear_error_on_return; @@ -4257,7 +4242,6 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo& args, DiffieHellman* dh; ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder()); - CHECK(dh->initialised_); char errmsg[64]; @@ -4303,7 +4287,6 @@ void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo& args) { DiffieHellman* diffieHellman; ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder()); - CHECK(diffieHellman->initialised_); args.GetReturnValue().Set(diffieHellman->verifyError_); } diff --git a/src/node_crypto.h b/src/node_crypto.h index f4afd2fdaf5758..fd865e909d773f 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -615,7 +615,6 @@ class DiffieHellman : public BaseObject { DiffieHellman(Environment* env, v8::Local wrap) : BaseObject(env, wrap), - initialised_(false), verifyError_(0) { MakeWeak(); } @@ -633,7 +632,6 @@ class DiffieHellman : public BaseObject { int (*set_field)(DH*, BIGNUM*), const char* what); bool VerifyContext(); - bool initialised_; int verifyError_; DHPointer dh_; };