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 <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
bnoordhuis authored and Myles Borins committed Jul 14, 2016
1 parent e103044 commit 38baf6a
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 @@ -3320,17 +3320,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 @@ -3461,12 +3461,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 @@ -3599,13 +3599,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 @@ -3799,13 +3799,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 @@ -495,14 +495,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 @@ -526,14 +524,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_;
};

Expand All @@ -551,7 +547,6 @@ class SignBase : public BaseObject {

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

Expand All @@ -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_;
};

Expand Down

0 comments on commit 38baf6a

Please sign in to comment.