| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -204,6 +204,9 @@ static int X509_up_ref(X509* cert) { | |||
| 204 | 204 | CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509); | |
| 205 | 205 | return 1; | |
| 206 | 206 | } | |
| 207 | + | ||
| 208 | + #define EVP_MD_CTX_new EVP_MD_CTX_create | ||
| 209 | + #define EVP_MD_CTX_free EVP_MD_CTX_destroy | ||
| 207 | 210 | #endif // OPENSSL_VERSION_NUMBER < 0x10100000L | |
| 208 | 211 | ||
| 209 | 212 | // Subject DER of CNNIC ROOT CA and CNNIC EV ROOT CA are taken from | |
@@ -3937,6 +3940,11 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) { | |||
| 3937 | 3940 | } | |
| 3938 | 3941 | ||
| 3939 | 3942 | ||
| 3943 | + Hash::~Hash() { | ||
| 3944 | + EVP_MD_CTX_free(mdctx_); | ||
| 3945 | + } | ||
| 3946 | + | ||
| 3947 | + | ||
| 3940 | 3948 | void Hash::Initialize(Environment* env, v8::Local<v8::Object> target) { | |
| 3941 | 3949 | Local<FunctionTemplate> t = env->NewFunctionTemplate(New); | |
| 3942 | 3950 | ||
@@ -3966,20 +3974,22 @@ bool Hash::HashInit(const char* hash_type) { | |||
| 3966 | 3974 | const EVP_MD* md = EVP_get_digestbyname(hash_type); | |
| 3967 | 3975 | if (md == nullptr) | |
| 3968 | 3976 | return false; | |
| 3969 | - EVP_MD_CTX_init(&mdctx_); | ||
| 3970 | - if (EVP_DigestInit_ex(&mdctx_, md, nullptr) <= 0) { | ||
| 3977 | + mdctx_ = EVP_MD_CTX_new(); | ||
| 3978 | + if (mdctx_ == nullptr || | ||
| 3979 | + EVP_DigestInit_ex(mdctx_, md, nullptr) <= 0) { | ||
| 3980 | + EVP_MD_CTX_free(mdctx_); | ||
| 3981 | + mdctx_ = nullptr; | ||
| 3971 | 3982 | return false; | |
| 3972 | 3983 | } | |
| 3973 | - initialised_ = true; | ||
| 3974 | 3984 | finalized_ = false; | |
| 3975 | 3985 | return true; | |
| 3976 | 3986 | } | |
| 3977 | 3987 | ||
| 3978 | 3988 | ||
| 3979 | 3989 | bool Hash::HashUpdate(const char* data, int len) { | |
| 3980 | - if (!initialised_) | ||
| 3990 | + if (mdctx_ == nullptr) | ||
| 3981 | 3991 | return false; | |
| 3982 | - EVP_DigestUpdate(&mdctx_, data, len); | ||
| 3992 | + EVP_DigestUpdate(mdctx_, data, len); | ||
| 3983 | 3993 | return true; | |
| 3984 | 3994 | } | |
| 3985 | 3995 | ||
@@ -4023,8 +4033,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) { | |||
| 4023 | 4033 | unsigned char md_value[EVP_MAX_MD_SIZE]; | |
| 4024 | 4034 | unsigned int md_len; | |
| 4025 | 4035 | ||
| 4026 | - EVP_DigestFinal_ex(&hash->mdctx_, md_value, &md_len); | ||
| 4027 | - EVP_MD_CTX_cleanup(&hash->mdctx_); | ||
| 4036 | + EVP_DigestFinal_ex(hash->mdctx_, md_value, &md_len); | ||
| 4028 | 4037 | hash->finalized_ = true; | |
| 4029 | 4038 | ||
| 4030 | 4039 | Local<Value> error; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -524,11 +524,7 @@ class Hmac : public BaseObject { | |||
| 524 | 524 | ||
| 525 | 525 | class Hash : public BaseObject { | |
| 526 | 526 | public: | |
| 527 | - ~Hash() override { | ||
| 528 | - if (!initialised_) | ||
| 529 | - return; | ||
| 530 | - EVP_MD_CTX_cleanup(&mdctx_); | ||
| 531 | - } | ||
| 527 | + ~Hash() override; | ||
| 532 | 528 | ||
| 533 | 529 | static void Initialize(Environment* env, v8::Local<v8::Object> target); | |
| 534 | 530 | ||
@@ -542,13 +538,13 @@ class Hash : public BaseObject { | |||
| 542 | 538 | ||
| 543 | 539 | Hash(Environment* env, v8::Local<v8::Object> wrap) | |
| 544 | 540 | : BaseObject(env, wrap), | |
| 545 | - initialised_(false) { | ||
| 541 | + mdctx_(nullptr), | ||
| 542 | + finalized_(false) { | ||
| 546 | 543 | MakeWeak<Hash>(this); | |
| 547 | 544 | } | |
| 548 | 545 | ||
| 549 | 546 | private: | |
| 550 | - EVP_MD_CTX mdctx_; /* coverity[member_decl] */ | ||
| 551 | - bool initialised_; | ||
| 547 | + EVP_MD_CTX* mdctx_; | ||
| 552 | 548 | bool finalized_; | |
| 553 | 549 | }; | |
| 554 | 550 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments