Skip to content

Commit 31a1016

Browse files
committed
src: remove unused md_ data members
The code assigned the result of EVP_get_digestbyname() to data members called md_ that were not used outside the initialization functions. PR-URL: nodejs#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>
1 parent a3ba357 commit 31a1016

2 files changed

Lines changed: 17 additions & 23 deletions

File tree

src/node_crypto.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,17 +3324,17 @@ void Hmac::New(const FunctionCallbackInfo<Value>& args) {
33243324
void Hmac::HmacInit(const char* hash_type, const char* key, int key_len) {
33253325
HandleScope scope(env()->isolate());
33263326

3327-
CHECK_EQ(md_, nullptr);
3328-
md_ = EVP_get_digestbyname(hash_type);
3329-
if (md_ == nullptr) {
3327+
CHECK_EQ(initialised_, false);
3328+
const EVP_MD* md = EVP_get_digestbyname(hash_type);
3329+
if (md == nullptr) {
33303330
return env()->ThrowError("Unknown message digest");
33313331
}
33323332
HMAC_CTX_init(&ctx_);
33333333
int result = 0;
33343334
if (key_len == 0) {
3335-
result = HMAC_Init(&ctx_, "", 0, md_);
3335+
result = HMAC_Init(&ctx_, "", 0, md);
33363336
} else {
3337-
result = HMAC_Init(&ctx_, key, key_len, md_);
3337+
result = HMAC_Init(&ctx_, key, key_len, md);
33383338
}
33393339
if (!result) {
33403340
return ThrowCryptoError(env(), ERR_get_error());
@@ -3465,12 +3465,12 @@ void Hash::New(const FunctionCallbackInfo<Value>& args) {
34653465

34663466

34673467
bool Hash::HashInit(const char* hash_type) {
3468-
CHECK_EQ(md_, nullptr);
3469-
md_ = EVP_get_digestbyname(hash_type);
3470-
if (md_ == nullptr)
3468+
CHECK_EQ(initialised_, false);
3469+
const EVP_MD* md = EVP_get_digestbyname(hash_type);
3470+
if (md == nullptr)
34713471
return false;
34723472
EVP_MD_CTX_init(&mdctx_);
3473-
if (EVP_DigestInit_ex(&mdctx_, md_, nullptr) <= 0) {
3473+
if (EVP_DigestInit_ex(&mdctx_, md, nullptr) <= 0) {
34743474
return false;
34753475
}
34763476
initialised_ = true;
@@ -3603,13 +3603,13 @@ void Sign::New(const FunctionCallbackInfo<Value>& args) {
36033603

36043604

36053605
SignBase::Error Sign::SignInit(const char* sign_type) {
3606-
CHECK_EQ(md_, nullptr);
3607-
md_ = EVP_get_digestbyname(sign_type);
3608-
if (!md_)
3606+
CHECK_EQ(initialised_, false);
3607+
const EVP_MD* md = EVP_get_digestbyname(sign_type);
3608+
if (md == nullptr)
36093609
return kSignUnknownDigest;
36103610

36113611
EVP_MD_CTX_init(&mdctx_);
3612-
if (!EVP_SignInit_ex(&mdctx_, md_, nullptr))
3612+
if (!EVP_SignInit_ex(&mdctx_, md, nullptr))
36133613
return kSignInit;
36143614
initialised_ = true;
36153615

@@ -3803,13 +3803,13 @@ void Verify::New(const FunctionCallbackInfo<Value>& args) {
38033803

38043804

38053805
SignBase::Error Verify::VerifyInit(const char* verify_type) {
3806-
CHECK_EQ(md_, nullptr);
3807-
md_ = EVP_get_digestbyname(verify_type);
3808-
if (md_ == nullptr)
3806+
CHECK_EQ(initialised_, false);
3807+
const EVP_MD* md = EVP_get_digestbyname(verify_type);
3808+
if (md == nullptr)
38093809
return kSignUnknownDigest;
38103810

38113811
EVP_MD_CTX_init(&mdctx_);
3812-
if (!EVP_VerifyInit_ex(&mdctx_, md_, nullptr))
3812+
if (!EVP_VerifyInit_ex(&mdctx_, md, nullptr))
38133813
return kSignInit;
38143814
initialised_ = true;
38153815

src/node_crypto.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,12 @@ class Hmac : public BaseObject {
495495

496496
Hmac(Environment* env, v8::Local<v8::Object> wrap)
497497
: BaseObject(env, wrap),
498-
md_(nullptr),
499498
initialised_(false) {
500499
MakeWeak<Hmac>(this);
501500
}
502501

503502
private:
504503
HMAC_CTX ctx_; /* coverity[member_decl] */
505-
const EVP_MD* md_; /* coverity[member_decl] */
506504
bool initialised_;
507505
};
508506

@@ -526,14 +524,12 @@ class Hash : public BaseObject {
526524

527525
Hash(Environment* env, v8::Local<v8::Object> wrap)
528526
: BaseObject(env, wrap),
529-
md_(nullptr),
530527
initialised_(false) {
531528
MakeWeak<Hash>(this);
532529
}
533530

534531
private:
535532
EVP_MD_CTX mdctx_; /* coverity[member_decl] */
536-
const EVP_MD* md_; /* coverity[member_decl] */
537533
bool initialised_;
538534
};
539535

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

552548
SignBase(Environment* env, v8::Local<v8::Object> wrap)
553549
: BaseObject(env, wrap),
554-
md_(nullptr),
555550
initialised_(false) {
556551
}
557552

@@ -565,7 +560,6 @@ class SignBase : public BaseObject {
565560
void CheckThrow(Error error);
566561

567562
EVP_MD_CTX mdctx_; /* coverity[member_decl] */
568-
const EVP_MD* md_; /* coverity[member_decl] */
569563
bool initialised_;
570564
};
571565

0 commit comments

Comments
 (0)