Skip to content

[4.x] Deprecate calling the Crypt constructor without a cipher and a key - #39

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-crypt-deprecate-default-cipher-key
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-crypt-deprecate-default-cipher-key

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

new Crypt() / new Crypt($cipher) silently fall back to the Crypto cipher (whose library defuse/php-encryption is only suggested) and to a freshly generated key that is never stored, so data encrypted that way can never be decrypted by another instance. Making both arguments required is a BC break and is done for 5.0 in #33.

This PR is the 4.x counterpart: the constructor keeps its signature and defaults, but triggers a deprecation (trigger_deprecation(), symfony/deprecation-contracts added to require) when the cipher or the key is omitted.

Testing Instructions

New tests in CryptTest:

  • testConstructorWithoutCipherOrKeyTriggersDeprecation (no arguments / no key / no cipher) expects the deprecation message; fails before the change.
  • testConstructorDefaultsStillWork shows that new Crypt() still encrypts and decrypts.
php vendor/bin/phpunit

Documentation Changes Required

docs/overview.md ("Which cipher to use"): new paragraph saying both arguments should always be passed, that omitting them is deprecated, and why.

Related to #33 (the 5.x removal of the defaults; it changes the same constructor docblock lines, so expect a small conflict when 4.x-dev is merged into 5.x-dev — #33's version wins).

🤖 Generated with Claude Code

Without a cipher, Crypt falls back to the Crypto cipher, whose library is
only suggested; without a key, it generates one that is never stored, so
the data it encrypts cannot be decrypted by any other instance. Trigger a
deprecation when either argument is omitted; both become required in 5.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant