Skip to content

Commit

Permalink
src: move GetOpenSSLVersion into node_metadata.cc
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
joyeecheung authored and addaleax committed Jan 14, 2019
1 parent e93dd4d commit 64c713a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
15 changes: 0 additions & 15 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 20 additions & 3 deletions src/node_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -39,7 +56,7 @@ Metadata::Versions::Versions() {
std::to_string(BrotliEncoderVersion() & 0xFFF);

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

Expand Down

0 comments on commit 64c713a

Please sign in to comment.