Skip to content

Commit 38baf6a

Browse files
bnoordhuisMyles Borins
authored and
Myles Borins
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: #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]>
1 parent e103044 commit 38baf6a

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

src/node_crypto.cc

+17-17
Original file line numberDiff line numberDiff line change
@@ -3320,17 +3320,17 @@ void Hmac::New(const FunctionCallbackInfo<Value>& args) {
33203320
void Hmac::HmacInit(const char* hash_type, const char* key, int key_len) {
33213321
HandleScope scope(env()->isolate());
33223322

3323-
CHECK_EQ(md_, nullptr);
3324-
md_ = EVP_get_digestbyname(hash_type);
3325-
if (md_ == nullptr) {
3323+
CHECK_EQ(initialised_, false);
3324+
const EVP_MD* md = EVP_get_digestbyname(hash_type);
3325+
if (md == nullptr) {
33263326
return env()->ThrowError("Unknown message digest");
33273327
}
33283328
HMAC_CTX_init(&ctx_);
33293329
int result = 0;
33303330
if (key_len == 0) {
3331-
result = HMAC_Init(&ctx_, "", 0, md_);
3331+
result = HMAC_Init(&ctx_, "", 0, md);
33323332
} else {
3333-
result = HMAC_Init(&ctx_, key, key_len, md_);
3333+
result = HMAC_Init(&ctx_, key, key_len, md);
33343334
}
33353335
if (!result) {
33363336
return ThrowCryptoError(env(), ERR_get_error());
@@ -3461,12 +3461,12 @@ void Hash::New(const FunctionCallbackInfo<Value>& args) {
34613461

34623462

34633463
bool Hash::HashInit(const char* hash_type) {
3464-
CHECK_EQ(md_, nullptr);
3465-
md_ = EVP_get_digestbyname(hash_type);
3466-
if (md_ == nullptr)
3464+
CHECK_EQ(initialised_, false);
3465+
const EVP_MD* md = EVP_get_digestbyname(hash_type);
3466+
if (md == nullptr)
34673467
return false;
34683468
EVP_MD_CTX_init(&mdctx_);
3469-
if (EVP_DigestInit_ex(&mdctx_, md_, nullptr) <= 0) {
3469+
if (EVP_DigestInit_ex(&mdctx_, md, nullptr) <= 0) {
34703470
return false;
34713471
}
34723472
initialised_ = true;
@@ -3599,13 +3599,13 @@ void Sign::New(const FunctionCallbackInfo<Value>& args) {
35993599

36003600

36013601
SignBase::Error Sign::SignInit(const char* sign_type) {
3602-
CHECK_EQ(md_, nullptr);
3603-
md_ = EVP_get_digestbyname(sign_type);
3604-
if (!md_)
3602+
CHECK_EQ(initialised_, false);
3603+
const EVP_MD* md = EVP_get_digestbyname(sign_type);
3604+
if (md == nullptr)
36053605
return kSignUnknownDigest;
36063606

36073607
EVP_MD_CTX_init(&mdctx_);
3608-
if (!EVP_SignInit_ex(&mdctx_, md_, nullptr))
3608+
if (!EVP_SignInit_ex(&mdctx_, md, nullptr))
36093609
return kSignInit;
36103610
initialised_ = true;
36113611

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

38003800

38013801
SignBase::Error Verify::VerifyInit(const char* verify_type) {
3802-
CHECK_EQ(md_, nullptr);
3803-
md_ = EVP_get_digestbyname(verify_type);
3804-
if (md_ == nullptr)
3802+
CHECK_EQ(initialised_, false);
3803+
const EVP_MD* md = EVP_get_digestbyname(verify_type);
3804+
if (md == nullptr)
38053805
return kSignUnknownDigest;
38063806

38073807
EVP_MD_CTX_init(&mdctx_);
3808-
if (!EVP_VerifyInit_ex(&mdctx_, md_, nullptr))
3808+
if (!EVP_VerifyInit_ex(&mdctx_, md, nullptr))
38093809
return kSignInit;
38103810
initialised_ = true;
38113811

src/node_crypto.h

-6
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)