@@ -2750,19 +2750,10 @@ void CipherBase::Update(const FunctionCallbackInfo<Value>& args) {
27502750
27512751 // Only copy the data if we have to, because it's a string
27522752 if (args[0 ]->IsString ()) {
2753- Local<String> string = args[0 ].As <String>();
2754- enum encoding encoding = ParseEncoding (env->isolate (), args[1 ], BINARY);
2755- if (!StringBytes::IsValidString (env->isolate (), string, encoding))
2756- return env->ThrowTypeError (" Bad input string" );
2757- size_t buflen = StringBytes::StorageSize (env->isolate (), string, encoding);
2758- char * buf = new char [buflen];
2759- size_t written = StringBytes::Write (env->isolate (),
2760- buf,
2761- buflen,
2762- string,
2763- encoding);
2764- r = cipher->Update (buf, written, &out, &out_len);
2765- delete[] buf;
2753+ StringBytes::InlineDecoder decoder;
2754+ if (!decoder.Decode (env, args[0 ].As <String>(), args[1 ], BINARY))
2755+ return ;
2756+ r = cipher->Update (decoder.out (), decoder.size (), &out, &out_len);
27662757 } else {
27672758 char * buf = Buffer::Data (args[0 ]);
27682759 size_t buflen = Buffer::Length (args[0 ]);
@@ -2929,19 +2920,10 @@ void Hmac::HmacUpdate(const FunctionCallbackInfo<Value>& args) {
29292920 // Only copy the data if we have to, because it's a string
29302921 bool r;
29312922 if (args[0 ]->IsString ()) {
2932- Local<String> string = args[0 ].As <String>();
2933- enum encoding encoding = ParseEncoding (env->isolate (), args[1 ], BINARY);
2934- if (!StringBytes::IsValidString (env->isolate (), string, encoding))
2935- return env->ThrowTypeError (" Bad input string" );
2936- size_t buflen = StringBytes::StorageSize (env->isolate (), string, encoding);
2937- char * buf = new char [buflen];
2938- size_t written = StringBytes::Write (env->isolate (),
2939- buf,
2940- buflen,
2941- string,
2942- encoding);
2943- r = hmac->HmacUpdate (buf, written);
2944- delete[] buf;
2923+ StringBytes::InlineDecoder decoder;
2924+ if (!decoder.Decode (env, args[0 ].As <String>(), args[1 ], BINARY))
2925+ return ;
2926+ r = hmac->HmacUpdate (decoder.out (), decoder.size ());
29452927 } else {
29462928 char * buf = Buffer::Data (args[0 ]);
29472929 size_t buflen = Buffer::Length (args[0 ]);
@@ -3053,19 +3035,10 @@ void Hash::HashUpdate(const FunctionCallbackInfo<Value>& args) {
30533035 // Only copy the data if we have to, because it's a string
30543036 bool r;
30553037 if (args[0 ]->IsString ()) {
3056- Local<String> string = args[0 ].As <String>();
3057- enum encoding encoding = ParseEncoding (env->isolate (), args[1 ], BINARY);
3058- if (!StringBytes::IsValidString (env->isolate (), string, encoding))
3059- return env->ThrowTypeError (" Bad input string" );
3060- size_t buflen = StringBytes::StorageSize (env->isolate (), string, encoding);
3061- char * buf = new char [buflen];
3062- size_t written = StringBytes::Write (env->isolate (),
3063- buf,
3064- buflen,
3065- string,
3066- encoding);
3067- r = hash->HashUpdate (buf, written);
3068- delete[] buf;
3038+ StringBytes::InlineDecoder decoder;
3039+ if (!decoder.Decode (env, args[0 ].As <String>(), args[1 ], BINARY))
3040+ return ;
3041+ r = hash->HashUpdate (decoder.out (), decoder.size ());
30693042 } else {
30703043 char * buf = Buffer::Data (args[0 ]);
30713044 size_t buflen = Buffer::Length (args[0 ]);
@@ -3214,19 +3187,10 @@ void Sign::SignUpdate(const FunctionCallbackInfo<Value>& args) {
32143187 // Only copy the data if we have to, because it's a string
32153188 Error err;
32163189 if (args[0 ]->IsString ()) {
3217- Local<String> string = args[0 ].As <String>();
3218- enum encoding encoding = ParseEncoding (env->isolate (), args[1 ], BINARY);
3219- if (!StringBytes::IsValidString (env->isolate (), string, encoding))
3220- return env->ThrowTypeError (" Bad input string" );
3221- size_t buflen = StringBytes::StorageSize (env->isolate (), string, encoding);
3222- char * buf = new char [buflen];
3223- size_t written = StringBytes::Write (env->isolate (),
3224- buf,
3225- buflen,
3226- string,
3227- encoding);
3228- err = sign->SignUpdate (buf, written);
3229- delete[] buf;
3190+ StringBytes::InlineDecoder decoder;
3191+ if (!decoder.Decode (env, args[0 ].As <String>(), args[1 ], BINARY))
3192+ return ;
3193+ err = sign->SignUpdate (decoder.out (), decoder.size ());
32303194 } else {
32313195 char * buf = Buffer::Data (args[0 ]);
32323196 size_t buflen = Buffer::Length (args[0 ]);
@@ -3395,19 +3359,10 @@ void Verify::VerifyUpdate(const FunctionCallbackInfo<Value>& args) {
33953359 // Only copy the data if we have to, because it's a string
33963360 Error err;
33973361 if (args[0 ]->IsString ()) {
3398- Local<String> string = args[0 ].As <String>();
3399- enum encoding encoding = ParseEncoding (env->isolate (), args[1 ], BINARY);
3400- if (!StringBytes::IsValidString (env->isolate (), string, encoding))
3401- return env->ThrowTypeError (" Bad input string" );
3402- size_t buflen = StringBytes::StorageSize (env->isolate (), string, encoding);
3403- char * buf = new char [buflen];
3404- size_t written = StringBytes::Write (env->isolate (),
3405- buf,
3406- buflen,
3407- string,
3408- encoding);
3409- err = verify->VerifyUpdate (buf, written);
3410- delete[] buf;
3362+ StringBytes::InlineDecoder decoder;
3363+ if (!decoder.Decode (env, args[0 ].As <String>(), args[1 ], BINARY))
3364+ return ;
3365+ err = verify->VerifyUpdate (decoder.out (), decoder.size ());
34113366 } else {
34123367 char * buf = Buffer::Data (args[0 ]);
34133368 size_t buflen = Buffer::Length (args[0 ]);
0 commit comments