mirror of
https://github.com/php/php-src.git
synced 2024-12-26 02:10:46 +08:00
d679f02295
This patch adds missing newlines, trims multiple redundant final newlines into a single one, and trims redundant leading newlines in all *.phpt sections. According to POSIX, a line is a sequence of zero or more non-' <newline>' characters plus a terminating '<newline>' character. [1] Files should normally have at least one final newline character. C89 [2] and later standards [3] mention a final newline: "A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character." Although it is not mandatory for all files to have a final newline fixed, a more consistent and homogeneous approach brings less of commit differences issues and a better development experience in certain text editors and IDEs. [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206 [2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2 [3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
--TEST--
|
|
OpenSSL private key functions
|
|
--SKIPIF--
|
|
<?php
|
|
if (!extension_loaded("openssl")) die("skip");
|
|
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 = __DIR__ . '/001-tmp.key';
|
|
if ($key_file_name === false) {
|
|
die("failed to get a temporary filename!");
|
|
}
|
|
|
|
echo "Export key to file\n";
|
|
|
|
if (!openssl_pkey_export_to_file($privkey, $key_file_name, $passphrase, $conf)) {
|
|
die("failed to export to file $key_file_name");
|
|
}
|
|
var_dump(is_resource($privkey));
|
|
|
|
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_pkey_free($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_pkey_free($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_pkey_free($loaded_key);
|
|
|
|
echo "OK!\n";
|
|
|
|
?>
|
|
--EXPECT--
|
|
Creating private key
|
|
Export key to file
|
|
bool(true)
|
|
Load key from file - array syntax
|
|
Load key using direct syntax
|
|
Load key manually and use string syntax
|
|
OK!
|
|
--CLEAN--
|
|
<?php
|
|
$key_file_name = __DIR__ . DIRECTORY_SEPARATOR . '001-tmp.key';
|
|
@unlink($key_file_name);
|
|
?>
|