GeezerVison is showing github.com — src: update ECGroupPointer in ncrypto · nodejs/node@c008b15
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: deps/ncrypto/ncrypto.cc +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2677,4 +2677,34 @@ Buffer<unsigned char> ECDSASigPointer::encode() const { | 2677 | 2677 | return buf; | 2678 | 2678 | } | 2679 | 2679 |
| | 2680 | +// ============================================================================ | | 2681 | + | | 2682 | +ECGroupPointer::ECGroupPointer() : group_(nullptr) {} | | 2683 | + | | 2684 | +ECGroupPointer::ECGroupPointer(EC_GROUP* group) : group_(group) {} | | 2685 | + | | 2686 | +ECGroupPointer::ECGroupPointer(ECGroupPointer&& other) noexcept | | 2687 | + : group_(other.release()) {} | | 2688 | + | | 2689 | +ECGroupPointer& ECGroupPointer::operator=(ECGroupPointer&& other) noexcept { | | 2690 | + group_.reset(other.release()); | | 2691 | + return *this; | | 2692 | +} | | 2693 | + | | 2694 | +ECGroupPointer::~ECGroupPointer() { | | 2695 | + reset(); | | 2696 | +} | | 2697 | + | | 2698 | +void ECGroupPointer::reset(EC_GROUP* group) { | | 2699 | + group_.reset(); | | 2700 | +} | | 2701 | + | | 2702 | +EC_GROUP* ECGroupPointer::release() { | | 2703 | + return group_.release(); | | 2704 | +} | | 2705 | + | | 2706 | +ECGroupPointer ECGroupPointer::NewByCurveName(int nid) { | | 2707 | + return ECGroupPointer(EC_GROUP_new_by_curve_name(nid)); | | 2708 | +} | | 2709 | + | 2680 | 2710 | } // namespace ncrypto |
Collapse file Copy file name to clipboardExpand all lines: deps/ncrypto/ncrypto.h +22-1Lines changed: 22 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -197,7 +197,6 @@ using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer; | 197 | 197 |
| 198 | 198 | using BignumCtxPointer = DeleteFnPtr<BN_CTX, BN_CTX_free>; | 199 | 199 | using BignumGenCallbackPointer = DeleteFnPtr<BN_GENCB, BN_GENCB_free>; | 200 | | -using ECGroupPointer = DeleteFnPtr<EC_GROUP, EC_GROUP_free>; | 201 | 200 | using ECKeyPointer = DeleteFnPtr<EC_KEY, EC_KEY_free>; | 202 | 201 | using ECPointPointer = DeleteFnPtr<EC_POINT, EC_POINT_free>; | 203 | 202 | using EVPKeyCtxPointer = DeleteFnPtr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>; | @@ -852,6 +851,28 @@ class ECDSASigPointer final { | 852 | 851 | const BIGNUM* ps_ = nullptr; | 853 | 852 | }; | 854 | 853 |
| | 854 | +class ECGroupPointer final { | | 855 | + public: | | 856 | + explicit ECGroupPointer(); | | 857 | + explicit ECGroupPointer(EC_GROUP* group); | | 858 | + ECGroupPointer(ECGroupPointer&& other) noexcept; | | 859 | + ECGroupPointer& operator=(ECGroupPointer&& other) noexcept; | | 860 | + NCRYPTO_DISALLOW_COPY(ECGroupPointer) | | 861 | + ~ECGroupPointer(); | | 862 | + | | 863 | + inline bool operator==(std::nullptr_t) noexcept { return group_ == nullptr; } | | 864 | + inline operator bool() const { return group_ != nullptr; } | | 865 | + inline EC_GROUP* get() const { return group_.get(); } | | 866 | + inline operator EC_GROUP*() const { return group_.get(); } | | 867 | + void reset(EC_GROUP* group = nullptr); | | 868 | + EC_GROUP* release(); | | 869 | + | | 870 | + static ECGroupPointer NewByCurveName(int nid); | | 871 | + | | 872 | + private: | | 873 | + DeleteFnPtr<EC_GROUP, EC_GROUP_free> group_; | | 874 | +}; | | 875 | + | 855 | 876 | #ifndef OPENSSL_NO_ENGINE | 856 | 877 | class EnginePointer final { | 857 | 878 | public: | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_ec.cc +4-8Lines changed: 4 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -399,15 +399,11 @@ void ECDH::ConvertKey(const FunctionCallbackInfo<Value>& args) { | 399 | 399 | if (nid == NID_undef) | 400 | 400 | return THROW_ERR_CRYPTO_INVALID_CURVE(env); | 401 | 401 |
| 402 | | - ECGroupPointer group( | 403 | | - EC_GROUP_new_by_curve_name(nid)); | 404 | | - if (group == nullptr) | | 402 | + auto group = ECGroupPointer::NewByCurveName(nid); | | 403 | + if (!group) | 405 | 404 | return THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Failed to get EC_GROUP"); | 406 | 405 |
| 407 | | - ECPointPointer pub( | 408 | | - ECDH::BufferToPoint(env, | 409 | | - group.get(), | 410 | | - args[0])); | | 406 | + ECPointPointer pub(ECDH::BufferToPoint(env, group, args[0])); | 411 | 407 |
| 412 | 408 | if (pub == nullptr) { | 413 | 409 | return THROW_ERR_CRYPTO_OPERATION_FAILED(env, | @@ -420,7 +416,7 @@ void ECDH::ConvertKey(const FunctionCallbackInfo<Value>& args) { | 420 | 416 |
| 421 | 417 | const char* error; | 422 | 418 | Local<Object> buf; | 423 | | - if (!ECPointToBuffer(env, group.get(), pub.get(), form, &error).ToLocal(&buf)) | | 419 | + if (!ECPointToBuffer(env, group, pub.get(), form, &error).ToLocal(&buf)) | 424 | 420 | return THROW_ERR_CRYPTO_OPERATION_FAILED(env, error); | 425 | 421 | args.GetReturnValue().Set(buf); | 426 | 422 | } | |
|