Skip to content
Permalink
Browse files

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: #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>
  • Loading branch information...
joyeecheung authored and addaleax committed Dec 18, 2018
1 parent e93dd4d commit 64c713a2e7ac9cd58516038f11f22d4bbb0e14f1
Showing with 20 additions and 19 deletions.
  1. +0 −15 src/node_crypto.cc
  2. +0 −1 src/node_crypto.h
  3. +20 −3 src/node_metadata.cc
@@ -6340,21 +6340,6 @@ void Initialize(Local<Object> 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

@@ -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:
@@ -10,15 +10,32 @@
#include "zlib.h"

#if HAVE_OPENSSL
#include "node_crypto.h"
#endif
#include <openssl/opensslv.h>
#endif // HAVE_OPENSSL

namespace node {

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();
@@ -39,7 +56,7 @@ Metadata::Versions::Versions() {
std::to_string(BrotliEncoderVersion() & 0xFFF);

#if HAVE_OPENSSL
openssl = crypto::GetOpenSSLVersion();
openssl = GetOpenSSLVersion();
#endif
}

0 comments on commit 64c713a

Please sign in to comment.
You can’t perform that action at this time.