Skip to content

[5.x] Add native parameter and return types to the cipher API - #46

Open
Hackwar wants to merge 2 commits into
joomla-framework:5.x-devfrom
Hackwar:5.x-native-types
Open

Hackwar wants to merge 2 commits into
joomla-framework:5.x-devfrom
Hackwar:5.x-native-types

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

CipherInterface::encrypt()/decrypt()/generateKey(), their implementations and Crypt::encrypt()/decrypt()/generateKey()/setKey()/genRandomBytes() have no scalar parameter or return types, so null or other non-string input is silently coerced. Adding types to the interface breaks every implementer, hence 5.x.

New signatures:

  • CipherInterface and Cipher\Crypto, Cipher\OpenSSL, Cipher\Sodium: encrypt(string $data, Key $key): string, decrypt(string $data, Key $key): string, generateKey(array $options = []): Key
  • Crypt: encrypt(string $data): string, decrypt(string $data): string, generateKey(array $options = []): Key, setKey(Key $key): static, genRandomBytes(int $length = 16): string

The constructor of Crypt is left to #33. The removal of the deprecated Sodium::setNonce() is a separate PR; the future of Cipher\OpenSSL is still open.

Testing Instructions

New Tests/NativeTypesTest.php checks the declared return types via reflection and that null data / a non-numeric length now raise TypeError (fails before the change).

php vendor/bin/phpunit
php vendor/bin/phpstan analyse

Documentation Changes Required

docs/v4-to-v5-update.md: new section "Native parameter and return types" (fills its placeholder).

Depends on #45 (creates the update guide; this branch contains its commit until it is merged).
Related to #38 (4.x): it changes the doc blocks of the same method signatures, so expect small conflicts when 4.x-dev is merged into 5.x-dev; the result needs both changes.

🤖 Generated with Claude Code

Hackwar and others added 2 commits November 12, 2026 23:17
Several pull requests against 5.x-dev need to describe their breaking
changes in the update guide. Create it with one placeholder per pending
change, so that these pull requests fill in their own section without
conflicting with each other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
encrypt(), decrypt(), generateKey() of CipherInterface and the ciphers, and
the corresponding Crypt methods had no scalar or return types, so null or
other non-string input was silently coerced. Declare the types; this breaks
implementers of the interface and is therefore a 5.0 change.

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