Skip to content

Commit 64c713a

Browse files
joyeecheungaddaleax
authored andcommitted
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 <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e93dd4d commit 64c713a

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
@@ -6340,21 +6340,6 @@ void Initialize(Local<Object> target,
63406340
#endif // OPENSSL_NO_SCRYPT
63416341
}
63426342

6343-
constexpr int search(const char* s, int n, int c) {
6344-
return *s == c ? n : search(s + 1, n + 1, c);
6345-
}
6346-
6347-
std::string GetOpenSSLVersion() {
6348-
// sample openssl version string format
6349-
// for reference: "OpenSSL 1.1.0i 14 Aug 2018"
6350-
char buf[128];
6351-
const int start = search(OPENSSL_VERSION_TEXT, 0, ' ') + 1;
6352-
const int end = search(OPENSSL_VERSION_TEXT + start, start, ' ');
6353-
const int len = end - start;
6354-
snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]);
6355-
return std::string(buf);
6356-
}
6357-
63586343
} // namespace crypto
63596344
} // namespace node
63606345

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

1212
#if HAVE_OPENSSL
13-
#include "node_crypto.h"
14-
#endif
13+
#include <openssl/opensslv.h>
14+
#endif // HAVE_OPENSSL
1515

1616
namespace node {
1717

1818
namespace per_process {
1919
Metadata metadata;
2020
}
2121

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

4158
#if HAVE_OPENSSL
42-
openssl = crypto::GetOpenSSLVersion();
59+
openssl = GetOpenSSLVersion();
4360
#endif
4461
}
4562

0 commit comments

Comments
 (0)