Skip to content

Commit

Permalink
crypto: simplify internal state handling
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tniessen authored and MylesBorins committed Oct 30, 2018
1 parent 4ba8977 commit 3ca41dc
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4115,10 +4115,7 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) {

DiffieHellman* diffieHellman;
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());

if (!diffieHellman->initialised_) {
return ThrowCryptoError(env, ERR_get_error(), "Not initialized");
}
CHECK(diffieHellman->initialised_);

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

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

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

DiffieHellman* diffieHellman;
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());

if (!diffieHellman->initialised_) {
return ThrowCryptoError(env, ERR_get_error(), "Not initialized");
}
CHECK(diffieHellman->initialised_);

ClearErrorOnReturn clear_error_on_return;

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

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

char errmsg[64];

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

DiffieHellman* diffieHellman;
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());

if (!diffieHellman->initialised_)
return ThrowCryptoError(diffieHellman->env(), ERR_get_error(),
"Not initialized");
CHECK(diffieHellman->initialised_);

args.GetReturnValue().Set(diffieHellman->verifyError_);
}
Expand Down

0 comments on commit 3ca41dc

Please sign in to comment.