crypto: fix misleading positional argument

The fourth positional argument of `createCipherBase` is `true` when
called from within the `Cipheriv` constructor and `false`when called
from within the `Decipheriv` constructor. This value is then passed to
the `CipherBase::New()` method, which treats it as follows:

    args[0]->IsTrue() ? kCipher : kDecipher

However, the current name of said positional argument is `decipher` and
thus indicates the exact opposite: when the argument is set to true, the
instance is *not* a `Decipheriv` object. Therefore, this commit renames
the argument to `isEncrypt`, which matches the actual semantics.

PR-URL: https://github.com/nodejs/node/pull/57843
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Tobias Nießen
2025-04-14 01:22:02 +02:00
committed by GitHub
parent 86c2505441
commit 29af9cea7f

View File

@@ -112,21 +112,21 @@ function getUIntOption(options, key) {
return -1;
}
function createCipherBase(cipher, credential, options, decipher, iv) {
function createCipherBase(cipher, credential, options, isEncrypt, iv) {
const authTagLength = getUIntOption(options, 'authTagLength');
this[kHandle] = new CipherBase(decipher);
this[kHandle] = new CipherBase(isEncrypt);
this[kHandle].initiv(cipher, credential, iv, authTagLength);
this._decoder = null;
ReflectApply(LazyTransform, this, [options]);
}
function createCipherWithIV(cipher, key, options, decipher, iv) {
function createCipherWithIV(cipher, key, options, isEncrypt, iv) {
validateString(cipher, 'cipher');
const encoding = getStringOption(options, 'encoding');
key = prepareSecretKey(key, encoding);
iv = iv === null ? null : getArrayBufferOrView(iv, 'iv');
ReflectApply(createCipherBase, this, [cipher, key, options, decipher, iv]);
ReflectApply(createCipherBase, this, [cipher, key, options, isEncrypt, iv]);
}
// The Cipher class is part of the legacy Node.js crypto API. It exposes