php-src/ext/openssl/tests/openssl_free_key.phpt
Tim Düsterhus 29f98e7485
Replace @deprecated by #[\Deprecated] for internal functions / class constants (#14750)
Co-authored-by: Gina Peter Banyard <girgias@php.net>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2024-07-10 16:47:31 +02:00

75 lines
2.1 KiB
PHP

--TEST--
void openssl_free_key ( resource $key_identifier );
--CREDITS--
marcosptf - <marcosptf@yahoo.com.br> - @phpsp - sao paulo - br
--EXTENSIONS--
openssl
--SKIPIF--
<?php
if (!@openssl_pkey_new())
die("skip cannot create private key");
?>
--FILE--
<?php
echo "Creating private key\n";
$conf = array('config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf');
$privkey = openssl_pkey_new($conf);
if ($privkey === false)
die("failed to create private key");
$passphrase = "banana";
$key_file_name = tempnam(sys_get_temp_dir(), "ssl");
if ($key_file_name === false)
die("failed to get a temporary filename!");
echo "Export key to file\n";
openssl_pkey_export_to_file($privkey, $key_file_name, $passphrase, $conf) or die("failed to export to file $key_file_name");
echo "Load key from file - array syntax\n";
$loaded_key = openssl_pkey_get_private(array("file://$key_file_name", $passphrase));
if ($loaded_key === false)
die("failed to load key using array syntax");
openssl_free_key($loaded_key);
echo "Load key using direct syntax\n";
$loaded_key = openssl_pkey_get_private("file://$key_file_name", $passphrase);
if ($loaded_key === false)
die("failed to load key using direct syntax");
openssl_free_key($loaded_key);
echo "Load key manually and use string syntax\n";
$key_content = file_get_contents($key_file_name);
$loaded_key = openssl_pkey_get_private($key_content, $passphrase);
if ($loaded_key === false)
die("failed to load key using string syntax");
openssl_free_key($loaded_key);
echo "OK!\n";
@unlink($key_file_name);
?>
--EXPECTF--
Creating private key
Export key to file
Load key from file - array syntax
Deprecated: Function openssl_free_key() is deprecated since 8.0, as OpenSSLAsymmetricKey objects are freed automatically in %s on line %d
Load key using direct syntax
Deprecated: Function openssl_free_key() is deprecated since 8.0, as OpenSSLAsymmetricKey objects are freed automatically in %s on line %d
Load key manually and use string syntax
Deprecated: Function openssl_free_key() is deprecated since 8.0, as OpenSSLAsymmetricKey objects are freed automatically in %s on line %d
OK!