diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 2d508d2cc3d527..1593d9a92b96f0 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3320,17 +3320,17 @@ void Hmac::New(const FunctionCallbackInfo& args) { void Hmac::HmacInit(const char* hash_type, const char* key, int key_len) { HandleScope scope(env()->isolate()); - CHECK_EQ(md_, nullptr); - md_ = EVP_get_digestbyname(hash_type); - if (md_ == nullptr) { + CHECK_EQ(initialised_, false); + const EVP_MD* md = EVP_get_digestbyname(hash_type); + if (md == nullptr) { return env()->ThrowError("Unknown message digest"); } HMAC_CTX_init(&ctx_); int result = 0; if (key_len == 0) { - result = HMAC_Init(&ctx_, "", 0, md_); + result = HMAC_Init(&ctx_, "", 0, md); } else { - result = HMAC_Init(&ctx_, key, key_len, md_); + result = HMAC_Init(&ctx_, key, key_len, md); } if (!result) { return ThrowCryptoError(env(), ERR_get_error()); @@ -3461,12 +3461,12 @@ void Hash::New(const FunctionCallbackInfo& args) { bool Hash::HashInit(const char* hash_type) { - CHECK_EQ(md_, nullptr); - md_ = EVP_get_digestbyname(hash_type); - if (md_ == nullptr) + CHECK_EQ(initialised_, false); + const EVP_MD* md = EVP_get_digestbyname(hash_type); + if (md == nullptr) return false; EVP_MD_CTX_init(&mdctx_); - if (EVP_DigestInit_ex(&mdctx_, md_, nullptr) <= 0) { + if (EVP_DigestInit_ex(&mdctx_, md, nullptr) <= 0) { return false; } initialised_ = true; @@ -3599,13 +3599,13 @@ void Sign::New(const FunctionCallbackInfo& args) { SignBase::Error Sign::SignInit(const char* sign_type) { - CHECK_EQ(md_, nullptr); - md_ = EVP_get_digestbyname(sign_type); - if (!md_) + CHECK_EQ(initialised_, false); + const EVP_MD* md = EVP_get_digestbyname(sign_type); + if (md == nullptr) return kSignUnknownDigest; EVP_MD_CTX_init(&mdctx_); - if (!EVP_SignInit_ex(&mdctx_, md_, nullptr)) + if (!EVP_SignInit_ex(&mdctx_, md, nullptr)) return kSignInit; initialised_ = true; @@ -3799,13 +3799,13 @@ void Verify::New(const FunctionCallbackInfo& args) { SignBase::Error Verify::VerifyInit(const char* verify_type) { - CHECK_EQ(md_, nullptr); - md_ = EVP_get_digestbyname(verify_type); - if (md_ == nullptr) + CHECK_EQ(initialised_, false); + const EVP_MD* md = EVP_get_digestbyname(verify_type); + if (md == nullptr) return kSignUnknownDigest; EVP_MD_CTX_init(&mdctx_); - if (!EVP_VerifyInit_ex(&mdctx_, md_, nullptr)) + if (!EVP_VerifyInit_ex(&mdctx_, md, nullptr)) return kSignInit; initialised_ = true; diff --git a/src/node_crypto.h b/src/node_crypto.h index cb94650e0735d0..d9105fd11a5721 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -495,14 +495,12 @@ class Hmac : public BaseObject { Hmac(Environment* env, v8::Local wrap) : BaseObject(env, wrap), - md_(nullptr), initialised_(false) { MakeWeak(this); } private: HMAC_CTX ctx_; /* coverity[member_decl] */ - const EVP_MD* md_; /* coverity[member_decl] */ bool initialised_; }; @@ -526,14 +524,12 @@ class Hash : public BaseObject { Hash(Environment* env, v8::Local wrap) : BaseObject(env, wrap), - md_(nullptr), initialised_(false) { MakeWeak(this); } private: EVP_MD_CTX mdctx_; /* coverity[member_decl] */ - const EVP_MD* md_; /* coverity[member_decl] */ bool initialised_; }; @@ -551,7 +547,6 @@ class SignBase : public BaseObject { SignBase(Environment* env, v8::Local wrap) : BaseObject(env, wrap), - md_(nullptr), initialised_(false) { } @@ -565,7 +560,6 @@ class SignBase : public BaseObject { void CheckThrow(Error error); EVP_MD_CTX mdctx_; /* coverity[member_decl] */ - const EVP_MD* md_; /* coverity[member_decl] */ bool initialised_; };