From 7744e84057db3cd5b3e24b15ff92d8f0ac68a09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 13 Oct 2018 23:08:24 +0200 Subject: [PATCH] crypto: simplify internal state handling Uninitialized instances are not exposed to users, so this condition should always be true. PR-URL: https://github.com/nodejs/node/pull/23648 Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis --- src/node_crypto.cc | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 3e4bdbb1128196..5f69e4f87ef005 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4115,10 +4115,7 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo& 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"); @@ -4140,7 +4137,7 @@ void DiffieHellman::GetField(const FunctionCallbackInfo& 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); @@ -4192,10 +4189,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo& 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; @@ -4263,7 +4257,7 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo& args, DiffieHellman* dh; ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder()); - if (!dh->initialised_) return env->ThrowError("Not initialized"); + CHECK(dh->initialised_); char errmsg[64]; @@ -4309,10 +4303,7 @@ void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo& 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_); }