Skip to content

Commit fb71964

Browse files
jasnelltargos
authored andcommitted
src: remove redundant OpenSSLBuffer
Replace the OpenSSLBuffer utility with ByteSource and remove OpenSSLBuffer. Signed-off-by: James M Snell <[email protected]> PR-URL: #35663 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 1cdfaa8 commit fb71964

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/crypto/crypto_common.cc

+2-1
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
}

src/crypto/crypto_common.h

-5
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); }

src/crypto/crypto_spkac.cc

+9-7
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)