Skip to content

Add openssl_pkey_get_details function missing in PHP < 8.4 #662

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions generated/8.1/functionsList.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions generated/8.1/rector-migrate.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions generated/8.2/functionsList.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions generated/8.2/rector-migrate.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions generated/8.3/functionsList.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions generated/8.3/rector-migrate.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions generated/8.4/openssl.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions generated/8.5/openssl.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions generator/config/CustomPhpStanFunctionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'openssl_random_pseudo_bytes' => ['string', 'length'=>'int', '&strong_result='=>'bool'],

// theses replace resource by OpenSSLAsymmetricKey
'openssl_pkey_get_details' => ['array|false', 'key'=>'OpenSSLAsymmetricKey'],
'openssl_pkey_get_private' => ['OpenSSLAsymmetricKey|false', 'private_key'=>'OpenSSLAsymmetricKey|OpenSSLCertificate|array|string', 'passphrase='=>'null|string'],
'openssl_pkey_get_public' => ['OpenSSLAsymmetricKey|false', 'public_key'=>'OpenSSLAsymmetricKey|OpenSSLCertificate|array|string'],
'openssl_csr_sign' => ['resource|false', 'csr'=>'string|OpenSSLCertificateSigningRequest', 'ca_certificate'=>'string|OpenSSLCertificate|null', 'private_key'=>'OpenSSLAsymmetricKey|OpenSSLCertificate|array|string', 'days'=>'int', 'options='=>'array', 'serial='=>'int', 'serial_hex='=>'string|null'],
Expand Down
28 changes: 28 additions & 0 deletions lib/special_cases.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,34 @@ function openssl_encrypt(string $data, string $method, string $key, int $options
return $result;
}

/**
* This function returns the key details (bits, key, type).
*
* @param \OpenSSLAsymmetricKey $key Resource holding the key.
* @return array Returns an array with the key details on success.
* Returned array has indexes bits (number of bits),
* key (string representation of the public key) and
* type (type of the key which is one of
* OPENSSL_KEYTYPE_RSA,
* OPENSSL_KEYTYPE_DSA,
* OPENSSL_KEYTYPE_DH,
* OPENSSL_KEYTYPE_EC or -1 meaning unknown).
*
* Depending on the key type used, additional details may be returned. Note that
* some elements may not always be available.
* @throws OpensslException
*
*/
function openssl_pkey_get_details(\OpenSSLAsymmetricKey $key): array
{
error_clear_last();
$safeResult = \openssl_pkey_get_details($key);
if ($safeResult === false) {
throw OpensslException::createFromPhpError();
}
return $safeResult;
}

/**
* The function socket_write writes to the
* socket from the given
Expand Down