From f7665dbd7ec87c681694d30c33322d271a9ce228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 12 Apr 2025 01:02:28 +0200 Subject: [PATCH] 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. --- 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 e2b863cdc5749a..3f8de4b793a413 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