|
1 | 1 | #include "crypto/crypto_spkac.h"
|
2 | 2 | #include "crypto/crypto_common.h"
|
3 | 3 | #include "crypto/crypto_util.h"
|
4 |
| -#include "allocated_buffer-inl.h" |
5 | 4 | #include "env-inl.h"
|
6 | 5 | #include "memory_tracker-inl.h"
|
7 | 6 | #include "node.h"
|
@@ -41,48 +40,36 @@ void VerifySpkac(const FunctionCallbackInfo<Value>& args) {
|
41 | 40 | args.GetReturnValue().Set(VerifySpkac(input));
|
42 | 41 | }
|
43 | 42 |
|
44 |
| -AllocatedBuffer ExportPublicKey(Environment* env, |
45 |
| - const ArrayBufferOrViewContents<char>& input, |
46 |
| - size_t* size) { |
| 43 | +ByteSource ExportPublicKey(Environment* env, |
| 44 | + const ArrayBufferOrViewContents<char>& input) { |
47 | 45 | BIOPointer bio(BIO_new(BIO_s_mem()));
|
48 |
| - if (!bio) return AllocatedBuffer(); |
| 46 | + if (!bio) return ByteSource(); |
49 | 47 |
|
50 | 48 | NetscapeSPKIPointer spki(
|
51 | 49 | NETSCAPE_SPKI_b64_decode(input.data(), input.size()));
|
52 |
| - if (!spki) return AllocatedBuffer(); |
| 50 | + if (!spki) return ByteSource(); |
53 | 51 |
|
54 | 52 | EVPKeyPointer pkey(NETSCAPE_SPKI_get_pubkey(spki.get()));
|
55 |
| - if (!pkey) return AllocatedBuffer(); |
| 53 | + if (!pkey) return ByteSource(); |
56 | 54 |
|
57 |
| - if (PEM_write_bio_PUBKEY(bio.get(), pkey.get()) <= 0) |
58 |
| - return AllocatedBuffer(); |
| 55 | + if (PEM_write_bio_PUBKEY(bio.get(), pkey.get()) <= 0) return ByteSource(); |
59 | 56 |
|
60 |
| - BUF_MEM* ptr; |
61 |
| - BIO_get_mem_ptr(bio.get(), &ptr); |
62 |
| - |
63 |
| - *size = ptr->length; |
64 |
| - AllocatedBuffer buf = AllocatedBuffer::AllocateManaged(env, *size); |
65 |
| - memcpy(buf.data(), ptr->data, *size); |
66 |
| - |
67 |
| - return buf; |
| 57 | + return ByteSource::FromBIO(bio); |
68 | 58 | }
|
69 | 59 |
|
70 | 60 | void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
|
71 | 61 | Environment* env = Environment::GetCurrent(args);
|
72 | 62 |
|
73 | 63 | ArrayBufferOrViewContents<char> input(args[0]);
|
74 |
| - if (input.size() == 0) |
75 |
| - return args.GetReturnValue().SetEmptyString(); |
| 64 | + if (input.size() == 0) return args.GetReturnValue().SetEmptyString(); |
76 | 65 |
|
77 | 66 | if (UNLIKELY(!input.CheckSizeInt32()))
|
78 | 67 | return THROW_ERR_OUT_OF_RANGE(env, "spkac is too large");
|
79 | 68 |
|
80 |
| - size_t pkey_size; |
81 |
| - AllocatedBuffer pkey = ExportPublicKey(env, input, &pkey_size); |
82 |
| - if (pkey.data() == nullptr) |
83 |
| - return args.GetReturnValue().SetEmptyString(); |
| 69 | + ByteSource pkey = ExportPublicKey(env, input); |
| 70 | + if (!pkey) return args.GetReturnValue().SetEmptyString(); |
84 | 71 |
|
85 |
| - args.GetReturnValue().Set(pkey.ToBuffer().FromMaybe(Local<Value>())); |
| 72 | + args.GetReturnValue().Set(pkey.ToBuffer(env).FromMaybe(Local<Value>())); |
86 | 73 | }
|
87 | 74 |
|
88 | 75 | ByteSource ExportChallenge(const ArrayBufferOrViewContents<char>& input) {
|
|
0 commit comments