Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: simplify internal state handling #23648

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/node_crypto.cc
Expand Up @@ -4102,10 +4102,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 @@ -4127,7 +4124,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 @@ -4179,10 +4176,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 @@ -4250,7 +4244,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 @@ -4296,10 +4290,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