summaryrefslogtreecommitdiff
path: root/src/node_metadata.cc
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-19 03:05:49 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-12-21 07:46:28 +0800
commite9703619e0698953ed71e8faf446b61c11ec89fc (patch)
tree93c1037edc98fa2b00987eeea825a78e8a9f4f90 /src/node_metadata.cc
parent3438f4b2cab572b4e21ed68013f2b25adf911e8b (diff)
downloadnode-new-e9703619e0698953ed71e8faf446b61c11ec89fc.tar.gz
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 <srloomis@us.ibm.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_metadata.cc')
-rw-r--r--src/node_metadata.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/node_metadata.cc b/src/node_metadata.cc
index 822b6a490d..3ddec4b36a 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 <openssl/opensslv.h>
+#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
}