@@ -820,10 +820,15 @@ CipherBase::UpdateResult CipherBase::Update(
820
820
len);
821
821
822
822
CHECK_LE (static_cast <size_t >(buf_len), (*out)->ByteLength ());
823
- if (buf_len == 0 )
823
+ if (buf_len == 0 ) {
824
824
*out = ArrayBuffer::NewBackingStore (env ()->isolate (), 0 );
825
- else
826
- *out = BackingStore::Reallocate (env ()->isolate (), std::move (*out), buf_len);
825
+ } else {
826
+ std::unique_ptr<BackingStore> old_out = std::move (*out);
827
+ *out = ArrayBuffer::NewBackingStore (env ()->isolate (), buf_len);
828
+ memcpy (static_cast <char *>((*out)->Data ()),
829
+ static_cast <char *>(old_out->Data ()),
830
+ buf_len);
831
+ }
827
832
828
833
// When in CCM mode, EVP_CipherUpdate will fail if the authentication tag is
829
834
// invalid. In that case, remember the error and throw in final().
@@ -912,8 +917,11 @@ bool CipherBase::Final(std::unique_ptr<BackingStore>* out) {
912
917
913
918
CHECK_LE (static_cast <size_t >(out_len), (*out)->ByteLength ());
914
919
if (out_len > 0 ) {
915
- *out =
916
- BackingStore::Reallocate (env ()->isolate (), std::move (*out), out_len);
920
+ std::unique_ptr<BackingStore> old_out = std::move (*out);
921
+ *out = ArrayBuffer::NewBackingStore (env ()->isolate (), out_len);
922
+ memcpy (static_cast <char *>((*out)->Data ()),
923
+ static_cast <char *>(old_out->Data ()),
924
+ out_len);
917
925
} else {
918
926
*out = ArrayBuffer::NewBackingStore (env ()->isolate (), 0 );
919
927
}
@@ -1015,10 +1023,15 @@ bool PublicKeyCipher::Cipher(
1015
1023
}
1016
1024
1017
1025
CHECK_LE (out_len, (*out)->ByteLength ());
1018
- if (out_len > 0 )
1019
- *out = BackingStore::Reallocate (env->isolate (), std::move (*out), out_len);
1020
- else
1026
+ if (out_len > 0 ) {
1027
+ std::unique_ptr<BackingStore> old_out = std::move (*out);
1028
+ *out = ArrayBuffer::NewBackingStore (env->isolate (), out_len);
1029
+ memcpy (static_cast <char *>((*out)->Data ()),
1030
+ static_cast <char *>(old_out->Data ()),
1031
+ out_len);
1032
+ } else {
1021
1033
*out = ArrayBuffer::NewBackingStore (env->isolate (), 0 );
1034
+ }
1022
1035
1023
1036
return true ;
1024
1037
}
0 commit comments