Skip to content

Commit a3ff239

Browse files
jasnellnpaun
authored andcommitted
src: update ECGroupPointer in ncrypto
PR-URL: nodejs/node#56526 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent eec2cca commit a3ff239

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

ncrypto.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,4 +2677,34 @@ Buffer<unsigned char> ECDSASigPointer::encode() const {
26772677
return buf;
26782678
}
26792679

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+
26802710
} // namespace ncrypto

ncrypto.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
197197

198198
using BignumCtxPointer = DeleteFnPtr<BN_CTX, BN_CTX_free>;
199199
using BignumGenCallbackPointer = DeleteFnPtr<BN_GENCB, BN_GENCB_free>;
200-
using ECGroupPointer = DeleteFnPtr<EC_GROUP, EC_GROUP_free>;
201200
using ECKeyPointer = DeleteFnPtr<EC_KEY, EC_KEY_free>;
202201
using ECPointPointer = DeleteFnPtr<EC_POINT, EC_POINT_free>;
203202
using EVPKeyCtxPointer = DeleteFnPtr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
@@ -852,6 +851,28 @@ class ECDSASigPointer final {
852851
const BIGNUM* ps_ = nullptr;
853852
};
854853

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+
855876
#ifndef OPENSSL_NO_ENGINE
856877
class EnginePointer final {
857878
public:

0 commit comments

Comments
 (0)