25
25
#include " crypto/crypto_util.h"
26
26
#include " crypto/crypto_bio.h"
27
27
#include " crypto/crypto_clienthello-inl.h"
28
- #include " allocated_buffer-inl.h"
29
28
#include " async_wrap-inl.h"
30
29
#include " debug_utils-inl.h"
31
30
#include " memory_tracker-inl.h"
@@ -1611,9 +1610,19 @@ void TLSWrap::GetFinished(const FunctionCallbackInfo<Value>& args) {
1611
1610
if (len == 0 )
1612
1611
return ;
1613
1612
1614
- AllocatedBuffer buf = AllocatedBuffer::AllocateManaged (env, len);
1615
- CHECK_EQ (len, SSL_get_finished (w->ssl_ .get (), buf.data (), len));
1616
- args.GetReturnValue ().Set (buf.ToBuffer ().FromMaybe (Local<Value>()));
1613
+ std::unique_ptr<BackingStore> bs;
1614
+ {
1615
+ NoArrayBufferZeroFillScope no_zero_fill_scope (env->isolate_data ());
1616
+ bs = ArrayBuffer::NewBackingStore (env->isolate (), len);
1617
+ }
1618
+
1619
+ CHECK_EQ (bs->ByteLength (),
1620
+ SSL_get_finished (w->ssl_ .get (), bs->Data (), bs->ByteLength ()));
1621
+
1622
+ Local<ArrayBuffer> ab = ArrayBuffer::New (env->isolate (), std::move (bs));
1623
+ Local<Value> buffer;
1624
+ if (!Buffer::New (env, ab, 0 , ab->ByteLength ()).ToLocal (&buffer)) return ;
1625
+ args.GetReturnValue ().Set (buffer);
1617
1626
}
1618
1627
1619
1628
void TLSWrap::GetPeerFinished (const FunctionCallbackInfo<Value>& args) {
@@ -1632,9 +1641,19 @@ void TLSWrap::GetPeerFinished(const FunctionCallbackInfo<Value>& args) {
1632
1641
if (len == 0 )
1633
1642
return ;
1634
1643
1635
- AllocatedBuffer buf = AllocatedBuffer::AllocateManaged (env, len);
1636
- CHECK_EQ (len, SSL_get_peer_finished (w->ssl_ .get (), buf.data (), len));
1637
- args.GetReturnValue ().Set (buf.ToBuffer ().FromMaybe (Local<Value>()));
1644
+ std::unique_ptr<BackingStore> bs;
1645
+ {
1646
+ NoArrayBufferZeroFillScope no_zero_fill_scope (env->isolate_data ());
1647
+ bs = ArrayBuffer::NewBackingStore (env->isolate (), len);
1648
+ }
1649
+
1650
+ CHECK_EQ (bs->ByteLength (),
1651
+ SSL_get_peer_finished (w->ssl_ .get (), bs->Data (), bs->ByteLength ()));
1652
+
1653
+ Local<ArrayBuffer> ab = ArrayBuffer::New (env->isolate (), std::move (bs));
1654
+ Local<Value> buffer;
1655
+ if (!Buffer::New (env, ab, 0 , ab->ByteLength ()).ToLocal (&buffer)) return ;
1656
+ args.GetReturnValue ().Set (buffer);
1638
1657
}
1639
1658
1640
1659
void TLSWrap::GetSession (const FunctionCallbackInfo<Value>& args) {
@@ -1651,10 +1670,19 @@ void TLSWrap::GetSession(const FunctionCallbackInfo<Value>& args) {
1651
1670
if (slen <= 0 )
1652
1671
return ; // Invalid or malformed session.
1653
1672
1654
- AllocatedBuffer sbuf = AllocatedBuffer::AllocateManaged (env, slen);
1655
- unsigned char * p = reinterpret_cast <unsigned char *>(sbuf.data ());
1673
+ std::unique_ptr<BackingStore> bs;
1674
+ {
1675
+ NoArrayBufferZeroFillScope no_zero_fill_scope (env->isolate_data ());
1676
+ bs = ArrayBuffer::NewBackingStore (env->isolate (), slen);
1677
+ }
1678
+
1679
+ unsigned char * p = static_cast <unsigned char *>(bs->Data ());
1656
1680
CHECK_LT (0 , i2d_SSL_SESSION (sess, &p));
1657
- args.GetReturnValue ().Set (sbuf.ToBuffer ().FromMaybe (Local<Value>()));
1681
+
1682
+ Local<ArrayBuffer> ab = ArrayBuffer::New (env->isolate (), std::move (bs));
1683
+ Local<Value> buffer;
1684
+ if (!Buffer::New (env, ab, 0 , ab->ByteLength ()).ToLocal (&buffer)) return ;
1685
+ args.GetReturnValue ().Set (buffer);
1658
1686
}
1659
1687
1660
1688
void TLSWrap::SetSession (const FunctionCallbackInfo<Value>& args) {
@@ -1825,7 +1853,11 @@ void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
1825
1853
uint32_t olen = args[0 ].As <Uint32>()->Value ();
1826
1854
Utf8Value label (env->isolate (), args[1 ]);
1827
1855
1828
- AllocatedBuffer out = AllocatedBuffer::AllocateManaged (env, olen);
1856
+ std::unique_ptr<BackingStore> bs;
1857
+ {
1858
+ NoArrayBufferZeroFillScope no_zero_fill_scope (env->isolate_data ());
1859
+ bs = ArrayBuffer::NewBackingStore (env->isolate (), olen);
1860
+ }
1829
1861
1830
1862
ByteSource context;
1831
1863
bool use_context = !args[2 ]->IsUndefined ();
@@ -1834,11 +1866,11 @@ void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
1834
1866
1835
1867
if (SSL_export_keying_material (
1836
1868
w->ssl_ .get (),
1837
- reinterpret_cast <unsigned char *>(out. data ()),
1869
+ static_cast <unsigned char *>(bs-> Data ()),
1838
1870
olen,
1839
1871
*label,
1840
1872
label.length (),
1841
- reinterpret_cast < const unsigned char *>(context. get () ),
1873
+ context. data < unsigned char >( ),
1842
1874
context.size (),
1843
1875
use_context) != 1 ) {
1844
1876
return ThrowCryptoError (
@@ -1847,7 +1879,10 @@ void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) {
1847
1879
" SSL_export_keying_material" );
1848
1880
}
1849
1881
1850
- args.GetReturnValue ().Set (out.ToBuffer ().FromMaybe (Local<Value>()));
1882
+ Local<ArrayBuffer> ab = ArrayBuffer::New (env->isolate (), std::move (bs));
1883
+ Local<Value> buffer;
1884
+ if (!Buffer::New (env, ab, 0 , ab->ByteLength ()).ToLocal (&buffer)) return ;
1885
+ args.GetReturnValue ().Set (buffer);
1851
1886
}
1852
1887
1853
1888
void TLSWrap::EndParser (const FunctionCallbackInfo<Value>& args) {
0 commit comments