Skip to content

crypto: fix misleading positional argument - #57843

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
tniessen:crypto-createcipherbase-isencrypt
Apr 13, 2025
Merged

crypto: fix misleading positional argument#57843
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
tniessen:crypto-createcipherbase-isencrypt

Conversation

@tniessen

Copy link
Copy Markdown
Member

The fourth positional argument of createCipherBase is true when called from within the Cipheriv constructor and falsewhen 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.

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.
@tniessentniessen added the crypto Issues and PRs related to the crypto subsystem. label Apr 11, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-botnodejs-github-bot added the needs-ci PRs that need a full CI run. label Apr 11, 2025
@codecov

codecovBot commented Apr 11, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.23%. Comparing base (86f86a2) to head (f7665db).
Report is 207 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #57843 +/- ##
=======================================
Coverage 90.22% 90.23% =======================================
Files 630 630 Lines 185481 185481 Branches 36364 36372 +8 =======================================
+ Hits 167357 167368 +11 + Misses 11004 10994 -10 + Partials 7120 7119 -1 
Files with missing linesCoverage Δ
lib/internal/crypto/cipher.js98.27% <100.00%> (ø)

... and 18 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tniessentniessen added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Apr 12, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 12, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@tniessentniessen added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 13, 2025
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 13, 2025
@nodejs-github-bot
nodejs-github-bot merged commit 29af9ce into nodejs:mainApr 13, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 29af9ce

RafaelGSS pushed a commit that referenced this pull request May 1, 2025
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: #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>
RafaelGSS pushed a commit that referenced this pull request May 2, 2025
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: #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>
@aduh95aduh95 added the backport-requested-v22.x PRs awaiting manual backport to the v22.x-staging branch. label May 6, 2025
@aduh95

Copy link
Copy Markdown
Contributor

This needs a manual backport for v22.x

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.backport-requested-v22.xPRs awaiting manual backport to the v22.x-staging branch.cryptoIssues and PRs related to the crypto subsystem.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@tniessen@nodejs-github-bot@aduh95@jasnell@lpinca@targos@geeksilva97