diff options
author | James M Snell <jasnell@gmail.com> | 2020-02-29 04:13:08 +0300 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2020-03-05 00:30:29 +0300 |
commit | 755da035ceff4fd3f347efba1d731fce0038f968 (patch) | |
tree | f510c9b94e77d65f338ea476a796be3b925b3ca2 /src/node_crypto.h | |
parent | 1539928ed915f54f5c2c1a1cafdb29d3b898f897 (diff) |
src: add node_crypto_common and refactor
Two things in one on this commit:
(a) For the QUIC implementation, we need to separate out various bits
from node_crypto.cc to allow them to be reused. That's where this
commit starts.
(b) Quite a bit of the node_crypto.cc code was just messy in terms of
it's organization and lack of error handling and use of Local vs.
MaybeLocal. This cleans that up a bit and hopefully makes certain
parts a bit more manageable also.
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/32016
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'src/node_crypto.h')
-rw-r--r-- | src/node_crypto.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/node_crypto.h b/src/node_crypto.h index 655605290b0..772a34a7da7 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -90,6 +90,8 @@ class SecureContext final : public BaseObject { static void Initialize(Environment* env, v8::Local<v8::Object> target); + SSL_CTX* operator*() const { return ctx_.get(); } + // TODO(joyeecheung): track the memory used by OpenSSL types SET_NO_MEMORY_INFO() SET_MEMORY_INFO_NAME(SecureContext) @@ -779,6 +781,17 @@ void SetEngine(const v8::FunctionCallbackInfo<v8::Value>& args); #endif // !OPENSSL_NO_ENGINE void InitCrypto(v8::Local<v8::Object> target); +void ThrowCryptoError(Environment* env, + unsigned long err, // NOLINT(runtime/int) + const char* message = nullptr); + +template <typename T> +inline T* MallocOpenSSL(size_t count) { + void* mem = OPENSSL_malloc(MultiplyWithOverflowCheck(count, sizeof(T))); + CHECK_IMPLIES(mem == nullptr, count == 0); + return static_cast<T*>(mem); +} + } // namespace crypto } // namespace node |