Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fb71964

Browse filesBrowse files
jasnelltargos
authored andcommitted
src: remove redundant OpenSSLBuffer
Replace the OpenSSLBuffer utility with ByteSource and remove OpenSSLBuffer. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #35663 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 1cdfaa8 commit fb71964
Copy full SHA for fb71964

File tree

Expand file treeCollapse file tree

3 files changed

+11
-13
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+11
-13
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_common.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_common.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ MaybeLocal<Value> GetSerialNumber(Environment* env, X509* cert) {
499499
if (ASN1_INTEGER* serial_number = X509_get_serialNumber(cert)) {
500500
BignumPointer bn(ASN1_INTEGER_to_BN(serial_number, nullptr));
501501
if (bn) {
502-
OpenSSLBuffer buf(BN_bn2hex(bn.get()));
502+
char* data = BN_bn2hex(bn.get());
503+
ByteSource buf = ByteSource::Allocated(data, strlen(data));
503504
if (buf)
504505
return OneByteString(env->isolate(), buf.get());
505506
}
Collapse file

‎src/crypto/crypto_common.h‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_common.h
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313

1414
namespace node {
1515
namespace crypto {
16-
// OPENSSL_free is a macro, so we need a wrapper function.
17-
struct OpenSSLBufferDeleter {
18-
void operator()(char* pointer) const { OPENSSL_free(pointer); }
19-
};
20-
using OpenSSLBuffer = std::unique_ptr<char[], OpenSSLBufferDeleter>;
2116

2217
struct StackOfX509Deleter {
2318
void operator()(STACK_OF(X509)* p) const { sk_X509_pop_free(p, X509_free); }
Collapse file

‎src/crypto/crypto_spkac.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_spkac.cc
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,18 @@ void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
8585
args.GetReturnValue().Set(pkey.ToBuffer().FromMaybe(Local<Value>()));
8686
}
8787

88-
OpenSSLBuffer ExportChallenge(const ArrayBufferOrViewContents<char>& input) {
88+
ByteSource ExportChallenge(const ArrayBufferOrViewContents<char>& input) {
8989
NetscapeSPKIPointer sp(
9090
NETSCAPE_SPKI_b64_decode(input.data(), input.size()));
9191
if (!sp)
92-
return nullptr;
92+
return ByteSource();
9393

94-
unsigned char* buf = nullptr;
95-
ASN1_STRING_to_UTF8(&buf, sp->spkac->challenge);
94+
char* buf = nullptr;
95+
ASN1_STRING_to_UTF8(
96+
reinterpret_cast<unsigned char**>(&buf),
97+
sp->spkac->challenge);
9698

97-
return OpenSSLBuffer(reinterpret_cast<char*>(buf));
99+
return ByteSource::Allocated(buf, strlen(buf));
98100
}
99101

100102
void ExportChallenge(const FunctionCallbackInfo<Value>& args) {
@@ -107,12 +109,12 @@ void ExportChallenge(const FunctionCallbackInfo<Value>& args) {
107109
if (UNLIKELY(!input.CheckSizeInt32()))
108110
return THROW_ERR_OUT_OF_RANGE(env, "spkac is too large");
109111

110-
OpenSSLBuffer cert = ExportChallenge(input);
112+
ByteSource cert = ExportChallenge(input);
111113
if (!cert)
112114
return args.GetReturnValue().SetEmptyString();
113115

114116
Local<Value> outString =
115-
Encode(env->isolate(), cert.get(), strlen(cert.get()), BUFFER);
117+
Encode(env->isolate(), cert.get(), cert.size(), BUFFER);
116118

117119
args.GetReturnValue().Set(outString);
118120
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.