@@ -968,11 +968,40 @@ function openssl_pkey_export($key, ?string &$output, ?string $passphrase = null,
968
968
}
969
969
970
970
971
+ /**
972
+ * This function returns the key details (bits, key, type).
973
+ *
974
+ * @param \OpenSSLAsymmetricKey $key Resource holding the key.
975
+ * @return array Returns an array with the key details on success.
976
+ * Returned array has indexes bits (number of bits),
977
+ * key (string representation of the public key) and
978
+ * type (type of the key which is one of
979
+ * OPENSSL_KEYTYPE_RSA,
980
+ * OPENSSL_KEYTYPE_DSA,
981
+ * OPENSSL_KEYTYPE_DH,
982
+ * OPENSSL_KEYTYPE_EC or -1 meaning unknown).
983
+ *
984
+ * Depending on the key type used, additional details may be returned. Note that
985
+ * some elements may not always be available.
986
+ * @throws OpensslException
987
+ *
988
+ */
989
+ function openssl_pkey_get_details (\OpenSSLAsymmetricKey $ key ): array
990
+ {
991
+ error_clear_last ();
992
+ $ safeResult = \openssl_pkey_get_details ($ key );
993
+ if ($ safeResult === false ) {
994
+ throw OpensslException::createFromPhpError ();
995
+ }
996
+ return $ safeResult ;
997
+ }
998
+
999
+
971
1000
/**
972
1001
* openssl_pkey_get_private parses
973
1002
* private_key and prepares it for use by other functions.
974
1003
*
975
- * @param string $private_key private_key can be one of the following:
1004
+ * @param \OpenSSLAsymmetricKey|\OpenSSLCertificate|array| string $private_key private_key can be one of the following:
976
1005
*
977
1006
* a string having the format
978
1007
* file://path/to/file.pem. The named file must
@@ -981,13 +1010,13 @@ function openssl_pkey_export($key, ?string &$output, ?string $passphrase = null,
981
1010
*
982
1011
* A PEM formatted private key.
983
1012
*
984
- * @param string $passphrase The optional parameter passphrase must be used
1013
+ * @param string|null $passphrase The optional parameter passphrase must be used
985
1014
* if the specified key is encrypted (protected by a passphrase).
986
- * @return resource Returns an OpenSSLAsymmetricKey instance on success.
1015
+ * @return \OpenSSLAsymmetricKey Returns an OpenSSLAsymmetricKey instance on success.
987
1016
* @throws OpensslException
988
1017
*
989
1018
*/
990
- function openssl_pkey_get_private (string $ private_key , string $ passphrase = null )
1019
+ function openssl_pkey_get_private ($ private_key , ? string $ passphrase = null ): \ OpenSSLAsymmetricKey
991
1020
{
992
1021
error_clear_last ();
993
1022
if ($ passphrase !== null ) {
@@ -1007,7 +1036,7 @@ function openssl_pkey_get_private(string $private_key, string $passphrase = null
1007
1036
* public_key and prepares it for use by other
1008
1037
* functions.
1009
1038
*
1010
- * @param resource |string $public_key public_key can be one of the following:
1039
+ * @param \OpenSSLAsymmetricKey|\OpenSSLCertificate|array |string $public_key public_key can be one of the following:
1011
1040
*
1012
1041
* an OpenSSLAsymmetricKey instance
1013
1042
* a string having the format
@@ -1017,11 +1046,11 @@ function openssl_pkey_get_private(string $private_key, string $passphrase = null
1017
1046
*
1018
1047
* A PEM formatted public key.
1019
1048
*
1020
- * @return resource Returns an OpenSSLAsymmetricKey instance on success.
1049
+ * @return \OpenSSLAsymmetricKey Returns an OpenSSLAsymmetricKey instance on success.
1021
1050
* @throws OpensslException
1022
1051
*
1023
1052
*/
1024
- function openssl_pkey_get_public ($ public_key )
1053
+ function openssl_pkey_get_public ($ public_key ): \ OpenSSLAsymmetricKey
1025
1054
{
1026
1055
error_clear_last ();
1027
1056
$ safeResult = \openssl_pkey_get_public ($ public_key );
0 commit comments