From d9274beb3ab177eb088e2166485648b8548ad55f Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 13 May 2025 10:58:40 +0100 Subject: [PATCH] detect openssl_pkey_get_details in earlier php versions, see #662 --- generated/8.1/functionsList.php | 1 + generated/8.1/openssl.php | 29 ++++++++++++++++++++++++++++ generated/8.1/rector-migrate.php | 1 + generated/8.2/functionsList.php | 1 + generated/8.2/openssl.php | 29 ++++++++++++++++++++++++++++ generated/8.2/rector-migrate.php | 1 + generated/8.3/functionsList.php | 1 + generated/8.3/openssl.php | 29 ++++++++++++++++++++++++++++ generated/8.3/rector-migrate.php | 1 + generator/config/detectErrorType.php | 1 + 10 files changed, 94 insertions(+) diff --git a/generated/8.1/functionsList.php b/generated/8.1/functionsList.php index 2aae135b..112fb4be 100644 --- a/generated/8.1/functionsList.php +++ b/generated/8.1/functionsList.php @@ -678,6 +678,7 @@ 'openssl_pkey_derive', 'openssl_pkey_export', 'openssl_pkey_export_to_file', + 'openssl_pkey_get_details', 'openssl_pkey_get_private', 'openssl_pkey_get_public', 'openssl_pkey_new', diff --git a/generated/8.1/openssl.php b/generated/8.1/openssl.php index 2feace0e..ff29aa80 100644 --- a/generated/8.1/openssl.php +++ b/generated/8.1/openssl.php @@ -943,6 +943,35 @@ function openssl_pkey_export($key, ?string &$output, ?string $passphrase = null, } +/** + * 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 in success or FALSE in failure. + * 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; +} + + /** * openssl_pkey_get_private parses * private_key and prepares it for use by other functions. diff --git a/generated/8.1/rector-migrate.php b/generated/8.1/rector-migrate.php index 051c758f..16fd62f2 100644 --- a/generated/8.1/rector-migrate.php +++ b/generated/8.1/rector-migrate.php @@ -686,6 +686,7 @@ 'openssl_pkey_derive' => 'Safe\openssl_pkey_derive', 'openssl_pkey_export' => 'Safe\openssl_pkey_export', 'openssl_pkey_export_to_file' => 'Safe\openssl_pkey_export_to_file', + 'openssl_pkey_get_details' => 'Safe\openssl_pkey_get_details', 'openssl_pkey_get_private' => 'Safe\openssl_pkey_get_private', 'openssl_pkey_get_public' => 'Safe\openssl_pkey_get_public', 'openssl_pkey_new' => 'Safe\openssl_pkey_new', diff --git a/generated/8.2/functionsList.php b/generated/8.2/functionsList.php index ee336c6c..55eb6dd5 100644 --- a/generated/8.2/functionsList.php +++ b/generated/8.2/functionsList.php @@ -676,6 +676,7 @@ 'openssl_pkey_derive', 'openssl_pkey_export', 'openssl_pkey_export_to_file', + 'openssl_pkey_get_details', 'openssl_pkey_get_private', 'openssl_pkey_get_public', 'openssl_pkey_new', diff --git a/generated/8.2/openssl.php b/generated/8.2/openssl.php index 36339eaa..776b9669 100644 --- a/generated/8.2/openssl.php +++ b/generated/8.2/openssl.php @@ -968,6 +968,35 @@ function openssl_pkey_export($key, ?string &$output, ?string $passphrase = null, } +/** + * 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 in success or FALSE in failure. + * 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; +} + + /** * openssl_pkey_get_private parses * private_key and prepares it for use by other functions. diff --git a/generated/8.2/rector-migrate.php b/generated/8.2/rector-migrate.php index 225f82d1..5a03708f 100644 --- a/generated/8.2/rector-migrate.php +++ b/generated/8.2/rector-migrate.php @@ -684,6 +684,7 @@ 'openssl_pkey_derive' => 'Safe\openssl_pkey_derive', 'openssl_pkey_export' => 'Safe\openssl_pkey_export', 'openssl_pkey_export_to_file' => 'Safe\openssl_pkey_export_to_file', + 'openssl_pkey_get_details' => 'Safe\openssl_pkey_get_details', 'openssl_pkey_get_private' => 'Safe\openssl_pkey_get_private', 'openssl_pkey_get_public' => 'Safe\openssl_pkey_get_public', 'openssl_pkey_new' => 'Safe\openssl_pkey_new', diff --git a/generated/8.3/functionsList.php b/generated/8.3/functionsList.php index ee336c6c..55eb6dd5 100644 --- a/generated/8.3/functionsList.php +++ b/generated/8.3/functionsList.php @@ -676,6 +676,7 @@ 'openssl_pkey_derive', 'openssl_pkey_export', 'openssl_pkey_export_to_file', + 'openssl_pkey_get_details', 'openssl_pkey_get_private', 'openssl_pkey_get_public', 'openssl_pkey_new', diff --git a/generated/8.3/openssl.php b/generated/8.3/openssl.php index 36339eaa..776b9669 100644 --- a/generated/8.3/openssl.php +++ b/generated/8.3/openssl.php @@ -968,6 +968,35 @@ function openssl_pkey_export($key, ?string &$output, ?string $passphrase = null, } +/** + * 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 in success or FALSE in failure. + * 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; +} + + /** * openssl_pkey_get_private parses * private_key and prepares it for use by other functions. diff --git a/generated/8.3/rector-migrate.php b/generated/8.3/rector-migrate.php index 225f82d1..5a03708f 100644 --- a/generated/8.3/rector-migrate.php +++ b/generated/8.3/rector-migrate.php @@ -684,6 +684,7 @@ 'openssl_pkey_derive' => 'Safe\openssl_pkey_derive', 'openssl_pkey_export' => 'Safe\openssl_pkey_export', 'openssl_pkey_export_to_file' => 'Safe\openssl_pkey_export_to_file', + 'openssl_pkey_get_details' => 'Safe\openssl_pkey_get_details', 'openssl_pkey_get_private' => 'Safe\openssl_pkey_get_private', 'openssl_pkey_get_public' => 'Safe\openssl_pkey_get_public', 'openssl_pkey_new' => 'Safe\openssl_pkey_new', diff --git a/generator/config/detectErrorType.php b/generator/config/detectErrorType.php index 52fc6bdd..74ca5ca3 100644 --- a/generator/config/detectErrorType.php +++ b/generator/config/detectErrorType.php @@ -24,6 +24,7 @@ '/[Tt]he function returns &false;/m', '/&false;\s+on\s+error/m', '/&false;\s+on\s+failure/m', + '/&false;\s+in\s+failure/m', // openssl_pkey_get_details (8.1 - 8.3) '/&false;\s+for\s+failure/m', '/&false;\s+in\s+case\s+of\s+error/m', '/&false;\s+if\s+an\s+error\s+occurred/m',