Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src,crypto: remove redundant OpenSSLBuffer #35663

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ MaybeLocal<Value> GetSerialNumber(Environment* env, X509* cert) {
if (ASN1_INTEGER* serial_number = X509_get_serialNumber(cert)) {
BignumPointer bn(ASN1_INTEGER_to_BN(serial_number, nullptr));
if (bn) {
OpenSSLBuffer buf(BN_bn2hex(bn.get()));
char* data = BN_bn2hex(bn.get());
ByteSource buf = ByteSource::Allocated(data, strlen(data));
if (buf)
return OneByteString(env->isolate(), buf.get());
}
Expand Down
5 changes: 0 additions & 5 deletions src/crypto/crypto_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@

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

struct StackOfX509Deleter {
void operator()(STACK_OF(X509)* p) const { sk_X509_pop_free(p, X509_free); }
Expand Down
16 changes: 9 additions & 7 deletions src/crypto/crypto_spkac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(pkey.ToBuffer().FromMaybe(Local<Value>()));
}

OpenSSLBuffer ExportChallenge(const ArrayBufferOrViewContents<char>& input) {
ByteSource ExportChallenge(const ArrayBufferOrViewContents<char>& input) {
NetscapeSPKIPointer sp(
NETSCAPE_SPKI_b64_decode(input.data(), input.size()));
if (!sp)
return nullptr;
return ByteSource();

unsigned char* buf = nullptr;
ASN1_STRING_to_UTF8(&buf, sp->spkac->challenge);
char* buf = nullptr;
ASN1_STRING_to_UTF8(
reinterpret_cast<unsigned char**>(&buf),
sp->spkac->challenge);

return OpenSSLBuffer(reinterpret_cast<char*>(buf));
return ByteSource::Allocated(buf, strlen(buf));
}

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

OpenSSLBuffer cert = ExportChallenge(input);
ByteSource cert = ExportChallenge(input);
if (!cert)
return args.GetReturnValue().SetEmptyString();

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

args.GetReturnValue().Set(outString);
}
Expand Down