Repository navigation
Let OpenSslCipherMethodsProvider contribute its own result cache meta #6338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Let OpenSslCipherMethodsProvider contribute its own result cache meta
The provider builds its list of supported ciphers by asking openssl_get_cipher_methods() and then probing every algorithm with openssl_cipher_iv_length(), and the inferred type follows it: openssl_cipher_iv_length() is int for a supported algorithm and false for an unsupported one. That list is a property of the PHP build rather than of the PHP version, so two hosts on the same PHP_VERSION_ID disagree. Measured across CI runners and docker images: PHP 8.4.25, ubuntu-latest, OpenSSL 3.0.13 -> 212 ciphers PHP 8.4.25, macos-latest, OpenSSL 3.6.3 -> 208 ciphers The four missing on macOS are aes-128-cbc-hmac-sha1, aes-128-cbc-hmac-sha256, aes-256-cbc-hmac-sha1 and aes-256-cbc-hmac-sha256, so openssl_cipher_iv_length() for one of them is int on the first and false on the second. phpExtensions records extension names only, so the metadata is identical and the cache is reused across the difference. Implementing ResultCacheMetaExtension on the provider puts the fingerprint where the knowledge already lives, and it costs nothing for projects that never touch openssl, since the list is only computed when something asks for it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Loading branch information
commit c5bb9e41ed50acc1a4e5d3ab1d56682520f3d9f5
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/PHPStan/Type/Php/OpenSslCipherMethodsProviderTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Type\Php; | ||
|
|
||
| use PHPStan\Testing\PHPStanTestCase; | ||
|
|
||
| class OpenSslCipherMethodsProviderTest extends PHPStanTestCase | ||
| { | ||
|
|
||
| public function testHashFollowsTheSupportedCiphers(): void | ||
| { | ||
| $one = $this->createProvider(['aes-128-cbc', 'aes-256-cbc'])->getHash(); | ||
| $fewer = $this->createProvider(['aes-128-cbc'])->getHash(); | ||
|
|
||
| $this->assertNotSame( | ||
| $one, | ||
| $fewer, | ||
| 'A host offering a different set of ciphers must not reuse the cache: openssl_cipher_iv_length() is int for a supported algorithm and false for an unsupported one.', | ||
| ); | ||
| } | ||
|
|
||
| public function testHashIgnoresTheOrderTheCiphersAreReportedIn(): void | ||
| { | ||
| $this->assertSame( | ||
| $this->createProvider(['aes-128-cbc', 'aes-256-cbc'])->getHash(), | ||
| $this->createProvider(['aes-256-cbc', 'aes-128-cbc'])->getHash(), | ||
| 'Enumeration order is not analysis-relevant and must not invalidate the cache.', | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param list<string> $supportedCipherMethods | ||
| */ | ||
| private function createProvider(array $supportedCipherMethods): OpenSslCipherMethodsProvider | ||
| { | ||
| return new OpenSslCipherMethodsProvider($supportedCipherMethods); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.