Skip to content

Commit e970361

Browse files
committed
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: nodejs#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]>
1 parent 3438f4b commit e970361

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

src/node_crypto.cc

-15
Original file line numberDiff line numberDiff line change
@@ -5842,21 +5842,6 @@ void Initialize(Local<Object> target,
58425842
#endif // OPENSSL_NO_SCRYPT
58435843
}
58445844

5845-
constexpr int search(const char* s, int n, int c) {
5846-
return *s == c ? n : search(s + 1, n + 1, c);
5847-
}
5848-
5849-
std::string GetOpenSSLVersion() {
5850-
// sample openssl version string format
5851-
// for reference: "OpenSSL 1.1.0i 14 Aug 2018"
5852-
char buf[128];
5853-
const int start = search(OPENSSL_VERSION_TEXT, 0, ' ') + 1;
5854-
const int end = search(OPENSSL_VERSION_TEXT + start, start, ' ');
5855-
const int len = end - start;
5856-
snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]);
5857-
return std::string(buf);
5858-
}
5859-
58605845
} // namespace crypto
58615846
} // namespace node
58625847

src/node_crypto.h

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ extern int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx);
9494
extern void UseExtraCaCerts(const std::string& file);
9595

9696
void InitCryptoOnce();
97-
std::string GetOpenSSLVersion();
9897

9998
class SecureContext : public BaseObject {
10099
public:

src/node_metadata.cc

+20-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,32 @@
99
#include "zlib.h"
1010

1111
#if HAVE_OPENSSL
12-
#include "node_crypto.h"
13-
#endif
12+
#include <openssl/opensslv.h>
13+
#endif // HAVE_OPENSSL
1414

1515
namespace node {
1616

1717
namespace per_process {
1818
Metadata metadata;
1919
}
2020

21+
#if HAVE_OPENSSL
22+
constexpr int search(const char* s, int n, int c) {
23+
return *s == c ? n : search(s + 1, n + 1, c);
24+
}
25+
26+
std::string GetOpenSSLVersion() {
27+
// sample openssl version string format
28+
// for reference: "OpenSSL 1.1.0i 14 Aug 2018"
29+
char buf[128];
30+
const int start = search(OPENSSL_VERSION_TEXT, 0, ' ') + 1;
31+
const int end = search(OPENSSL_VERSION_TEXT + start, start, ' ');
32+
const int len = end - start;
33+
snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]);
34+
return std::string(buf);
35+
}
36+
#endif // HAVE_OPENSSL
37+
2138
Metadata::Versions::Versions() {
2239
node = NODE_VERSION_STRING;
2340
v8 = v8::V8::GetVersion();
@@ -31,7 +48,7 @@ Metadata::Versions::Versions() {
3148
http_parser = http_parser_version;
3249

3350
#if HAVE_OPENSSL
34-
openssl = crypto::GetOpenSSLVersion();
51+
openssl = GetOpenSSLVersion();
3552
#endif
3653
}
3754

0 commit comments

Comments
 (0)