Skip to content

Commit 6975639

Browse files
tniessenjasnell
authored andcommitted
crypto: simplify internal state handling
Uninitialized instances are not exposed to users, so this condition should always be true. PR-URL: #23648 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent b2b4808 commit 6975639

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/node_crypto.cc

+5-14
Original file line numberDiff line numberDiff line change
@@ -4105,10 +4105,7 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) {
41054105

41064106
DiffieHellman* diffieHellman;
41074107
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4108-
4109-
if (!diffieHellman->initialised_) {
4110-
return ThrowCryptoError(env, ERR_get_error(), "Not initialized");
4111-
}
4108+
CHECK(diffieHellman->initialised_);
41124109

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

41314128
DiffieHellman* dh;
41324129
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4133-
if (!dh->initialised_) return env->ThrowError("Not initialized");
4130+
CHECK(dh->initialised_);
41344131

41354132
const BIGNUM* num = get_field(dh->dh_.get());
41364133
if (num == nullptr) return env->ThrowError(err_if_null);
@@ -4182,10 +4179,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
41824179

41834180
DiffieHellman* diffieHellman;
41844181
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4185-
4186-
if (!diffieHellman->initialised_) {
4187-
return ThrowCryptoError(env, ERR_get_error(), "Not initialized");
4188-
}
4182+
CHECK(diffieHellman->initialised_);
41894183

41904184
ClearErrorOnReturn clear_error_on_return;
41914185

@@ -4253,7 +4247,7 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<Value>& args,
42534247

42544248
DiffieHellman* dh;
42554249
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4256-
if (!dh->initialised_) return env->ThrowError("Not initialized");
4250+
CHECK(dh->initialised_);
42574251

42584252
char errmsg[64];
42594253

@@ -4299,10 +4293,7 @@ void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
42994293

43004294
DiffieHellman* diffieHellman;
43014295
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4302-
4303-
if (!diffieHellman->initialised_)
4304-
return ThrowCryptoError(diffieHellman->env(), ERR_get_error(),
4305-
"Not initialized");
4296+
CHECK(diffieHellman->initialised_);
43064297

43074298
args.GetReturnValue().Set(diffieHellman->verifyError_);
43084299
}

0 commit comments

Comments
 (0)