From 29af9cea7f233f2aa2ac052a86149293cdd9f13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 14 Apr 2025 01:22:02 +0200 Subject: [PATCH] crypto: fix misleading positional argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Luigi Pinca Reviewed-By: Edy Silva Reviewed-By: James M Snell --- lib/internal/crypto/cipher.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js index e2b863cdc5..3f8de4b793 100644 --- a/lib/internal/crypto/cipher.js +++ b/lib/internal/crypto/cipher.js @@ -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