Skip to content

Commit f4d1d9c

Browse files
tniessenjasnell
authored andcommitted
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: #23717 Refs: #23648 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 1ad660b commit f4d1d9c

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed

src/node_crypto.cc

+3-20
Original file line numberDiff line numberDiff line change
@@ -3974,11 +3974,7 @@ bool DiffieHellman::Init(int primeLength, int g) {
39743974
dh_.reset(DH_new());
39753975
if (!DH_generate_parameters_ex(dh_.get(), primeLength, g, 0))
39763976
return false;
3977-
bool result = VerifyContext();
3978-
if (!result)
3979-
return false;
3980-
initialised_ = true;
3981-
return true;
3977+
return VerifyContext();
39823978
}
39833979

39843980

@@ -3993,11 +3989,7 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) {
39933989
BN_free(bn_g);
39943990
return false;
39953991
}
3996-
bool result = VerifyContext();
3997-
if (!result)
3998-
return false;
3999-
initialised_ = true;
4000-
return true;
3992+
return VerifyContext();
40013993
}
40023994

40033995

@@ -4010,11 +4002,7 @@ bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) {
40104002
BN_free(bn_g);
40114003
return false;
40124004
}
4013-
bool result = VerifyContext();
4014-
if (!result)
4015-
return false;
4016-
initialised_ = true;
4017-
return true;
4005+
return VerifyContext();
40184006
}
40194007

40204008

@@ -4088,7 +4076,6 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) {
40884076

40894077
DiffieHellman* diffieHellman;
40904078
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4091-
CHECK(diffieHellman->initialised_);
40924079

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

41114098
DiffieHellman* dh;
41124099
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4113-
CHECK(dh->initialised_);
41144100

41154101
const BIGNUM* num = get_field(dh->dh_.get());
41164102
if (num == nullptr) return env->ThrowError(err_if_null);
@@ -4162,7 +4148,6 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
41624148

41634149
DiffieHellman* diffieHellman;
41644150
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4165-
CHECK(diffieHellman->initialised_);
41664151

41674152
ClearErrorOnReturn clear_error_on_return;
41684153

@@ -4230,7 +4215,6 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<Value>& args,
42304215

42314216
DiffieHellman* dh;
42324217
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4233-
CHECK(dh->initialised_);
42344218

42354219
char errmsg[64];
42364220

@@ -4276,7 +4260,6 @@ void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
42764260

42774261
DiffieHellman* diffieHellman;
42784262
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4279-
CHECK(diffieHellman->initialised_);
42804263

42814264
args.GetReturnValue().Set(diffieHellman->verifyError_);
42824265
}

src/node_crypto.h

-2
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ class DiffieHellman : public BaseObject {
614614

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

635-
bool initialised_;
636634
int verifyError_;
637635
DHPointer dh_;
638636
};

0 commit comments

Comments
 (0)