Skip to content

Commit

Permalink
src: remove redundant OpenSSLBuffer
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jasnell authored and targos committed Nov 4, 2020
1 parent 1cdfaa8 commit fb71964
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
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

0 comments on commit fb71964

Please sign in to comment.