Skip to content

Commit

Permalink
src: remove unused md_ data members
Browse files Browse the repository at this point in the history
The code assigned the result of EVP_get_digestbyname() to data members
called md_ that were not used outside the initialization functions.

PR-URL: #7374
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
bnoordhuis authored and Fishrock123 committed Jul 5, 2016
1 parent 2228a65 commit 25bc7fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
34 changes: 17 additions & 17 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3585,17 +3585,17 @@ void Hmac::New(const FunctionCallbackInfo<Value>& 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());
Expand Down Expand Up @@ -3730,12 +3730,12 @@ void Hash::New(const FunctionCallbackInfo<Value>& 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;
Expand Down Expand Up @@ -3881,13 +3881,13 @@ void Sign::New(const FunctionCallbackInfo<Value>& 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;

Expand Down Expand Up @@ -4087,13 +4087,13 @@ void Verify::New(const FunctionCallbackInfo<Value>& 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;

Expand Down
6 changes: 0 additions & 6 deletions src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,12 @@ class Hmac : public BaseObject {

Hmac(Environment* env, v8::Local<v8::Object> wrap)
: BaseObject(env, wrap),
md_(nullptr),
initialised_(false) {
MakeWeak<Hmac>(this);
}

private:
HMAC_CTX ctx_; /* coverity[member_decl] */
const EVP_MD* md_; /* coverity[member_decl] */
bool initialised_;
};

Expand All @@ -531,14 +529,12 @@ class Hash : public BaseObject {

Hash(Environment* env, v8::Local<v8::Object> wrap)
: BaseObject(env, wrap),
md_(nullptr),
initialised_(false) {
MakeWeak<Hash>(this);
}

private:
EVP_MD_CTX mdctx_; /* coverity[member_decl] */
const EVP_MD* md_; /* coverity[member_decl] */
bool initialised_;
bool finalized_;
};
Expand All @@ -557,7 +553,6 @@ class SignBase : public BaseObject {

SignBase(Environment* env, v8::Local<v8::Object> wrap)
: BaseObject(env, wrap),
md_(nullptr),
initialised_(false) {
}

Expand All @@ -571,7 +566,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_;
};

Expand Down

0 comments on commit 25bc7fe

Please sign in to comment.