Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3ca41dc

Browse filesBrowse files
tniessenMylesBorins
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 4ba8977 commit 3ca41dc
Copy full SHA for 3ca41dc

File tree

Expand file treeCollapse file tree

1 file changed

+5
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-14
lines changed
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+5-14Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4115,10 +4115,7 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) {
41154115

41164116
DiffieHellman* diffieHellman;
41174117
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4118-
4119-
if (!diffieHellman->initialised_) {
4120-
return ThrowCryptoError(env, ERR_get_error(), "Not initialized");
4121-
}
4118+
CHECK(diffieHellman->initialised_);
41224119

41234120
if (!DH_generate_key(diffieHellman->dh_.get())) {
41244121
return ThrowCryptoError(env, ERR_get_error(), "Key generation failed");
@@ -4140,7 +4137,7 @@ void DiffieHellman::GetField(const FunctionCallbackInfo<Value>& args,
41404137

41414138
DiffieHellman* dh;
41424139
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4143-
if (!dh->initialised_) return env->ThrowError("Not initialized");
4140+
CHECK(dh->initialised_);
41444141

41454142
const BIGNUM* num = get_field(dh->dh_.get());
41464143
if (num == nullptr) return env->ThrowError(err_if_null);
@@ -4192,10 +4189,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
41924189

41934190
DiffieHellman* diffieHellman;
41944191
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4195-
4196-
if (!diffieHellman->initialised_) {
4197-
return ThrowCryptoError(env, ERR_get_error(), "Not initialized");
4198-
}
4192+
CHECK(diffieHellman->initialised_);
41994193

42004194
ClearErrorOnReturn clear_error_on_return;
42014195

@@ -4263,7 +4257,7 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<Value>& args,
42634257

42644258
DiffieHellman* dh;
42654259
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4266-
if (!dh->initialised_) return env->ThrowError("Not initialized");
4260+
CHECK(dh->initialised_);
42674261

42684262
char errmsg[64];
42694263

@@ -4309,10 +4303,7 @@ void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
43094303

43104304
DiffieHellman* diffieHellman;
43114305
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4312-
4313-
if (!diffieHellman->initialised_)
4314-
return ThrowCryptoError(diffieHellman->env(), ERR_get_error(),
4315-
"Not initialized");
4306+
CHECK(diffieHellman->initialised_);
43164307

43174308
args.GetReturnValue().Set(diffieHellman->verifyError_);
43184309
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.