Skip to content

Commit d536fa5

Browse files
committed
crypto: remove DiffieHellman.initialised_
As pointed out by Ben Noordhuis, this internal field can be removed since all instances are initialised when exposed to users. Refs: nodejs#23648
1 parent e2f58c7 commit d536fa5

2 files changed

Lines changed: 3 additions & 22 deletions

File tree

src/node_crypto.cc

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3991,11 +3991,7 @@ bool DiffieHellman::Init(int primeLength, int g) {
39913991
dh_.reset(DH_new());
39923992
if (!DH_generate_parameters_ex(dh_.get(), primeLength, g, 0))
39933993
return false;
3994-
bool result = VerifyContext();
3995-
if (!result)
3996-
return false;
3997-
initialised_ = true;
3998-
return true;
3994+
return VerifyContext();
39993995
}
40003996

40013997

@@ -4010,11 +4006,7 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) {
40104006
BN_free(bn_g);
40114007
return false;
40124008
}
4013-
bool result = VerifyContext();
4014-
if (!result)
4015-
return false;
4016-
initialised_ = true;
4017-
return true;
4009+
return VerifyContext();
40184010
}
40194011

40204012

@@ -4027,11 +4019,7 @@ bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) {
40274019
BN_free(bn_g);
40284020
return false;
40294021
}
4030-
bool result = VerifyContext();
4031-
if (!result)
4032-
return false;
4033-
initialised_ = true;
4034-
return true;
4022+
return VerifyContext();
40354023
}
40364024

40374025

@@ -4105,7 +4093,6 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) {
41054093

41064094
DiffieHellman* diffieHellman;
41074095
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4108-
CHECK(diffieHellman->initialised_);
41094096

41104097
if (!DH_generate_key(diffieHellman->dh_.get())) {
41114098
return ThrowCryptoError(env, ERR_get_error(), "Key generation failed");
@@ -4127,7 +4114,6 @@ void DiffieHellman::GetField(const FunctionCallbackInfo<Value>& args,
41274114

41284115
DiffieHellman* dh;
41294116
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4130-
CHECK(dh->initialised_);
41314117

41324118
const BIGNUM* num = get_field(dh->dh_.get());
41334119
if (num == nullptr) return env->ThrowError(err_if_null);
@@ -4179,7 +4165,6 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
41794165

41804166
DiffieHellman* diffieHellman;
41814167
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4182-
CHECK(diffieHellman->initialised_);
41834168

41844169
ClearErrorOnReturn clear_error_on_return;
41854170

@@ -4247,7 +4232,6 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<Value>& args,
42474232

42484233
DiffieHellman* dh;
42494234
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4250-
CHECK(dh->initialised_);
42514235

42524236
char errmsg[64];
42534237

@@ -4293,7 +4277,6 @@ void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
42934277

42944278
DiffieHellman* diffieHellman;
42954279
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4296-
CHECK(diffieHellman->initialised_);
42974280

42984281
args.GetReturnValue().Set(diffieHellman->verifyError_);
42994282
}

src/node_crypto.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ class DiffieHellman : public BaseObject {
615615

616616
DiffieHellman(Environment* env, v8::Local<v8::Object> wrap)
617617
: BaseObject(env, wrap),
618-
initialised_(false),
619618
verifyError_(0) {
620619
MakeWeak();
621620
}
@@ -633,7 +632,6 @@ class DiffieHellman : public BaseObject {
633632
int (*set_field)(DH*, BIGNUM*), const char* what);
634633
bool VerifyContext();
635634

636-
bool initialised_;
637635
int verifyError_;
638636
DHPointer dh_;
639637
};

0 commit comments

Comments
 (0)