mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
src,crypto: remove AllocatedBuffers from crypto_spkac
Signed-off-by: Darshan Sen <darshan.sen@postman.com> PR-URL: https://github.com/nodejs/node/pull/40752 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
1 parent
c5d0b3cf84
commit
51b86550ae
3 files changed
+18
-24
No files matched your search
+11
-24
@@ -1,7 +1,6 @@
|
||||
#include "crypto/crypto_spkac.h"
|
||||
#include "crypto/crypto_common.h"
|
||||
#include "crypto/crypto_util.h"
|
||||
#include "allocated_buffer-inl.h"
|
||||
#include "env-inl.h"
|
||||
#include "memory_tracker-inl.h"
|
||||
#include "node.h"
|
||||
@@ -41,48 +40,36 @@ void VerifySpkac(const FunctionCallbackInfo<Value>& args) {
|
||||
args.GetReturnValue().Set(VerifySpkac(input));
|
||||
}
|
||||
|
||||
AllocatedBuffer ExportPublicKey(Environment* env,
|
||||
const ArrayBufferOrViewContents<char>& input,
|
||||
size_t* size) {
|
||||
ByteSource ExportPublicKey(Environment* env,
|
||||
const ArrayBufferOrViewContents<char>& input) {
|
||||
BIOPointer bio(BIO_new(BIO_s_mem()));
|
||||
if (!bio) return AllocatedBuffer();
|
||||
if (!bio) return ByteSource();
|
||||
|
||||
NetscapeSPKIPointer spki(
|
||||
NETSCAPE_SPKI_b64_decode(input.data(), input.size()));
|
||||
if (!spki) return AllocatedBuffer();
|
||||
if (!spki) return ByteSource();
|
||||
|
||||
EVPKeyPointer pkey(NETSCAPE_SPKI_get_pubkey(spki.get()));
|
||||
if (!pkey) return AllocatedBuffer();
|
||||
if (!pkey) return ByteSource();
|
||||
|
||||
if (PEM_write_bio_PUBKEY(bio.get(), pkey.get()) <= 0)
|
||||
return AllocatedBuffer();
|
||||
if (PEM_write_bio_PUBKEY(bio.get(), pkey.get()) <= 0) return ByteSource();
|
||||
|
||||
BUF_MEM* ptr;
|
||||
BIO_get_mem_ptr(bio.get(), &ptr);
|
||||
|
||||
*size = ptr->length;
|
||||
AllocatedBuffer buf = AllocatedBuffer::AllocateManaged(env, *size);
|
||||
memcpy(buf.data(), ptr->data, *size);
|
||||
|
||||
return buf;
|
||||
return ByteSource::FromBIO(bio);
|
||||
}
|
||||
|
||||
void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
|
||||
ArrayBufferOrViewContents<char> input(args[0]);
|
||||
if (input.size() == 0)
|
||||
return args.GetReturnValue().SetEmptyString();
|
||||
if (input.size() == 0) return args.GetReturnValue().SetEmptyString();
|
||||
|
||||
if (UNLIKELY(!input.CheckSizeInt32()))
|
||||
return THROW_ERR_OUT_OF_RANGE(env, "spkac is too large");
|
||||
|
||||
size_t pkey_size;
|
||||
AllocatedBuffer pkey = ExportPublicKey(env, input, &pkey_size);
|
||||
if (pkey.data() == nullptr)
|
||||
return args.GetReturnValue().SetEmptyString();
|
||||
ByteSource pkey = ExportPublicKey(env, input);
|
||||
if (!pkey) return args.GetReturnValue().SetEmptyString();
|
||||
|
||||
args.GetReturnValue().Set(pkey.ToBuffer().FromMaybe(Local<Value>()));
|
||||
args.GetReturnValue().Set(pkey.ToBuffer(env).FromMaybe(Local<Value>()));
|
||||
}
|
||||
|
||||
ByteSource ExportChallenge(const ArrayBufferOrViewContents<char>& input) {
|
||||
|
||||
@@ -340,6 +340,11 @@ Local<ArrayBuffer> ByteSource::ToArrayBuffer(Environment* env) {
|
||||
return ArrayBuffer::New(env->isolate(), std::move(store));
|
||||
}
|
||||
|
||||
MaybeLocal<Uint8Array> ByteSource::ToBuffer(Environment* env) {
|
||||
Local<ArrayBuffer> ab = ToArrayBuffer(env);
|
||||
return Buffer::New(env, ab, 0, ab->ByteLength());
|
||||
}
|
||||
|
||||
const char* ByteSource::get() const {
|
||||
return data_;
|
||||
}
|
||||
|
||||
@@ -259,6 +259,8 @@ class ByteSource {
|
||||
|
||||
v8::Local<v8::ArrayBuffer> ToArrayBuffer(Environment* env);
|
||||
|
||||
v8::MaybeLocal<v8::Uint8Array> ToBuffer(Environment* env);
|
||||
|
||||
void reset();
|
||||
|
||||
// Allows an Allocated ByteSource to be truncated.
|
||||
|
||||
Reference in new issue
Block a user