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 <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Tobias Nießen 2018-10-13 23:08:24 +02:00
parent 4e2862ad9e
commit e2f58c71dd
No known key found for this signature in database
GPG Key ID: 718207F8FD156B70

View File

@ -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");
@ -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);
@ -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;
@ -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];
@ -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_);
}