@@ -231,7 +231,6 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) { |
231 | 231 |
|
232 | 232 | t->InstanceTemplate()->SetInternalFieldCount(CipherBase::kInternalFieldCount); |
233 | 233 |
|
234 | | - SetProtoMethod(isolate, t, "initiv", InitIv); |
235 | 234 | SetProtoMethod(isolate, t, "update", Update); |
236 | 235 | SetProtoMethod(isolate, t, "final", Final); |
237 | 236 | SetProtoMethod(isolate, t, "setAutoPadding", SetAutoPadding); |
@@ -274,7 +273,6 @@ void CipherBase::RegisterExternalReferences( |
274 | 273 | ExternalReferenceRegistry* registry) { |
275 | 274 | registry->Register(New); |
276 | 275 |
|
277 | | - registry->Register(InitIv); |
278 | 276 | registry->Register(Update); |
279 | 277 | registry->Register(Final); |
280 | 278 | registry->Register(SetAutoPadding); |
@@ -300,7 +298,39 @@ void CipherBase::RegisterExternalReferences( |
300 | 298 | void CipherBase::New(const FunctionCallbackInfo<Value>& args) { |
301 | 299 | CHECK(args.IsConstructCall()); |
302 | 300 | 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); |
304 | 334 | } |
305 | 335 |
|
306 | 336 | void CipherBase::CommonInit(const char* cipher_type, |
@@ -391,43 +421,6 @@ void CipherBase::InitIv(const char* cipher_type, |
391 | 421 | auth_tag_len); |
392 | 422 | } |
393 | 423 |
|
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 | | - |
431 | 424 | bool CipherBase::InitAuthenticated(const char* cipher_type, |
432 | 425 | int iv_len, |
433 | 426 | unsigned int auth_tag_len) { |
|