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 jasnell committed Oct 17, 2018
1 parent b2b4808 commit 6975639
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/node_crypto.cc
Expand Up @@ -4105,10 +4105,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 @@ -4130,7 +4127,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 @@ -4182,10 +4179,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 @@ -4253,7 +4247,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 @@ -4299,10 +4293,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 6975639

Please sign in to comment.