@@ -231,7 +231,6 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) {
231231
232232 t->InstanceTemplate()->SetInternalFieldCount(CipherBase::kInternalFieldCount);
233233
234- SetProtoMethod(isolate, t, "initiv", InitIv);
235234 SetProtoMethod(isolate, t, "update", Update);
236235 SetProtoMethod(isolate, t, "final", Final);
237236 SetProtoMethod(isolate, t, "setAutoPadding", SetAutoPadding);
@@ -274,7 +273,6 @@ void CipherBase::RegisterExternalReferences(
274273 ExternalReferenceRegistry* registry) {
275274 registry->Register(New);
276275
277- registry->Register(InitIv);
278276 registry->Register(Update);
279277 registry->Register(Final);
280278 registry->Register(SetAutoPadding);
@@ -300,7 +298,39 @@ void CipherBase::RegisterExternalReferences(
300298void CipherBase::New(const FunctionCallbackInfo<Value>& args) {
301299 CHECK(args.IsConstructCall());
302300 Environment* env = Environment::GetCurrent(args);
303- new CipherBase(env, args.This(), args[0]->IsTrue() ? kCipher : kDecipher);
301+ CHECK_EQ(args.Length(), 5);
302+
303+ CipherBase* cipher =
304+ new CipherBase(env, args.This(), args[0]->IsTrue() ? kCipher : kDecipher);
305+
306+ const Utf8Value cipher_type(env->isolate(), args[1]);
307+
308+ // The argument can either be a KeyObjectHandle or a byte source
309+ // (e.g. ArrayBuffer, TypedArray, etc). Whichever it is, grab the
310+ // raw bytes and proceed...
311+ const ByteSource key_buf = ByteSource::FromSecretKeyBytes(env, args[2]);
312+
313+ if (key_buf.size() > INT_MAX) [[unlikely]] {
314+ return THROW_ERR_OUT_OF_RANGE(env, "key is too big");
315+ }
316+
317+ ArrayBufferOrViewContents<unsigned char> iv_buf(
318+ !args[3]->IsNull() ? args[3] : Local<Value>());
319+
320+ if (!iv_buf.CheckSizeInt32()) [[unlikely]] {
321+ return THROW_ERR_OUT_OF_RANGE(env, "iv is too big");
322+ }
323+ // Don't assign to cipher->auth_tag_len_ directly; the value might not
324+ // represent a valid length at this point.
325+ unsigned int auth_tag_len;
326+ if (args[4]->IsUint32()) {
327+ auth_tag_len = args[4].As<Uint32>()->Value();
328+ } else {
329+ CHECK(args[4]->IsInt32() && args[4].As<Int32>()->Value() == -1);
330+ auth_tag_len = kNoAuthTagLength;
331+ }
332+
333+ cipher->InitIv(*cipher_type, key_buf, iv_buf, auth_tag_len);
304334}
305335
306336void CipherBase::CommonInit(const char* cipher_type,
@@ -391,43 +421,6 @@ void CipherBase::InitIv(const char* cipher_type,
391421 auth_tag_len);
392422}
393423
394- void CipherBase::InitIv(const FunctionCallbackInfo<Value>& args) {
395- CipherBase* cipher;
396- ASSIGN_OR_RETURN_UNWRAP(&cipher, args.This());
397- Environment* env = cipher->env();
398-
399- CHECK_GE(args.Length(), 4);
400-
401- const Utf8Value cipher_type(env->isolate(), args[0]);
402-
403- // The argument can either be a KeyObjectHandle or a byte source
404- // (e.g. ArrayBuffer, TypedArray, etc). Whichever it is, grab the
405- // raw bytes and proceed...
406- const ByteSource key_buf = ByteSource::FromSecretKeyBytes(env, args[1]);
407-
408- if (key_buf.size() > INT_MAX) [[unlikely]] {
409- return THROW_ERR_OUT_OF_RANGE(env, "key is too big");
410- }
411-
412- ArrayBufferOrViewContents<unsigned char> iv_buf(
413- !args[2]->IsNull() ? args[2] : Local<Value>());
414-
415- if (!iv_buf.CheckSizeInt32()) [[unlikely]] {
416- return THROW_ERR_OUT_OF_RANGE(env, "iv is too big");
417- }
418- // Don't assign to cipher->auth_tag_len_ directly; the value might not
419- // represent a valid length at this point.
420- unsigned int auth_tag_len;
421- if (args[3]->IsUint32()) {
422- auth_tag_len = args[3].As<Uint32>()->Value();
423- } else {
424- CHECK(args[3]->IsInt32() && args[3].As<Int32>()->Value() == -1);
425- auth_tag_len = kNoAuthTagLength;
426- }
427-
428- cipher->InitIv(*cipher_type, key_buf, iv_buf, auth_tag_len);
429- }
430-
431424bool CipherBase::InitAuthenticated(const char* cipher_type,
432425 int iv_len,
433426 unsigned int auth_tag_len) {
0 commit comments