com php-src: test to function openssl_free_key($loaded _key);: ext/openssl/tests/openssl_free_key.phpt
| From: | Joe Watkins | Date: | Sun, 13 Mar 2016 13:53:34 +0000 |
| Subject: | com php-src: test to function openssl_free_key($loaded _key);: ext/openssl/tests/openssl_free_key.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95152@lists.php.net to get a copy of this message | ||
Commit: 5cd9c3bd710c7abcce210e6d7a0200238edc7c59
Author: marcosptf <marcosptf@yahoo.com.br> Sun, 13 Mar 2016 10:53:34 -0300
Parents: 01579ae0a6eda82b72a8d44d5cbdeef50a21ca79
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5cd9c3bd710c7abcce210e6d7a0200238edc7c59
Log:
test to function openssl_free_key($loaded_key);
was added a new test to openssl module to coverage openssl_free_key($loaded_key); function
Changed paths:
A ext/openssl/tests/openssl_free_key.phpt
Diff:
diff --git a/ext/openssl/tests/openssl_free_key.phpt b/ext/openssl/tests/openssl_free_key.phpt
new file mode 100644
index 0000000..18219a2
--- /dev/null
+++ b/ext/openssl/tests/openssl_free_key.phpt
@@ -0,0 +1,77 @@
+--TEST--
+void openssl_free_key ( resource $key_identifier );
+--CREDITS--
+marcosptf - <marcosptf@yahoo.com.br> - @phpsp - sao paulo - br
+--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";
+
+/* stack up some entropy; performance is not critical,
+ * and being slow will most likely even help the test.
+ */
+for ($z = "", $i = 0; $i < 1024; $i++) {
+ $z .= $i * $i;
+ if (function_exists("usleep"))
+ usleep($i);
+}
+
+$privkey = openssl_pkey_new();
+
+if ($privkey === false)
+ die("failed to create private key");
+
+$passphrase = "banana";
+$key_file_name = tempnam("/tmp", "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) 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);
+?>
+--EXPECT--
+Creating private key
+Export key to file
+Load key from file - array syntax
+Load key using direct syntax
+Load key manually and use string syntax
+OK!