From e9703619e0698953ed71e8faf446b61c11ec89fc Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 19 Dec 2018 03:05:49 +0800 Subject: [PATCH] src: move GetOpenSSLVersion into node_metadata.cc Instead of implementing it in node_crypto.cc even though the only place that needs it is the `Metadata::Versions` constructor. PR-URL: https://github.com/nodejs/node/pull/25115 Reviewed-By: Steven R Loomis Reviewed-By: Richard Lau Reviewed-By: Minwoo Jung Reviewed-By: James M Snell --- src/node_crypto.cc | 15 --------------- src/node_crypto.h | 1 - src/node_metadata.cc | 23 ++++++++++++++++++++--- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index c8401bec54b8f1..011506a34eb34e 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5842,21 +5842,6 @@ void Initialize(Local target, #endif // OPENSSL_NO_SCRYPT } -constexpr int search(const char* s, int n, int c) { - return *s == c ? n : search(s + 1, n + 1, c); -} - -std::string GetOpenSSLVersion() { - // sample openssl version string format - // for reference: "OpenSSL 1.1.0i 14 Aug 2018" - char buf[128]; - const int start = search(OPENSSL_VERSION_TEXT, 0, ' ') + 1; - const int end = search(OPENSSL_VERSION_TEXT + start, start, ' '); - const int len = end - start; - snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]); - return std::string(buf); -} - } // namespace crypto } // namespace node diff --git a/src/node_crypto.h b/src/node_crypto.h index 0ee45cf9ea2c02..dd22c9eae4b564 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -94,7 +94,6 @@ extern int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx); extern void UseExtraCaCerts(const std::string& file); void InitCryptoOnce(); -std::string GetOpenSSLVersion(); class SecureContext : public BaseObject { public: diff --git a/src/node_metadata.cc b/src/node_metadata.cc index 822b6a490d13d2..3ddec4b36afc1b 100644 --- a/src/node_metadata.cc +++ b/src/node_metadata.cc @@ -9,8 +9,8 @@ #include "zlib.h" #if HAVE_OPENSSL -#include "node_crypto.h" -#endif +#include +#endif // HAVE_OPENSSL namespace node { @@ -18,6 +18,23 @@ namespace per_process { Metadata metadata; } +#if HAVE_OPENSSL +constexpr int search(const char* s, int n, int c) { + return *s == c ? n : search(s + 1, n + 1, c); +} + +std::string GetOpenSSLVersion() { + // sample openssl version string format + // for reference: "OpenSSL 1.1.0i 14 Aug 2018" + char buf[128]; + const int start = search(OPENSSL_VERSION_TEXT, 0, ' ') + 1; + const int end = search(OPENSSL_VERSION_TEXT + start, start, ' '); + const int len = end - start; + snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]); + return std::string(buf); +} +#endif // HAVE_OPENSSL + Metadata::Versions::Versions() { node = NODE_VERSION_STRING; v8 = v8::V8::GetVersion(); @@ -31,7 +48,7 @@ Metadata::Versions::Versions() { http_parser = http_parser_version; #if HAVE_OPENSSL - openssl = crypto::GetOpenSSLVersion(); + openssl = GetOpenSSLVersion(); #endif }