1--TEST--
2Phar::setSupportedSignatures() with hash
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6if (!extension_loaded("hash")) die("skip hash extension required");
7$arr = Phar::getSupportedSignatures();
8if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
9if (!in_array('SHA-256', $arr)) die("skip hash extension loaded shared");
10?>
11--INI--
12phar.require_hash=0
13phar.readonly=0
14--FILE--
15<?php
16$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
17$p = new Phar($fname);
18$p['file1.txt'] = 'hi';
19var_dump($p->getSignature());
20$p->setSignatureAlgorithm(Phar::MD5);
21var_dump($p->getSignature());
22$p->setSignatureAlgorithm(Phar::SHA1);
23var_dump($p->getSignature());
24try {
25$p->setSignatureAlgorithm(Phar::SHA256);
26var_dump($p->getSignature());
27} catch (Exception $e) {
28echo $e->getMessage();
29}
30try {
31$p->setSignatureAlgorithm(Phar::SHA512);
32var_dump($p->getSignature());
33} catch (Exception $e) {
34echo $e->getMessage();
35}
36try {
37$config = dirname(__FILE__) . '/files/openssl.cnf';
38$config_arg = array('config' => $config);
39$private = openssl_get_privatekey(file_get_contents(dirname(__FILE__) . '/files/private.pem'));
40$pkey = '';
41openssl_pkey_export($private, $pkey, NULL, $config_arg);
42$p->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
43var_dump($p->getSignature());
44} catch (Exception $e) {
45echo $e->getMessage();
46}
47?>
48===DONE===
49--CLEAN--
50<?php
51unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
52?>
53--EXPECTF--
54array(2) {
55  ["hash"]=>
56  string(%d) "%s"
57  ["hash_type"]=>
58  string(5) "SHA-1"
59}
60array(2) {
61  ["hash"]=>
62  string(%d) "%s"
63  ["hash_type"]=>
64  string(3) "MD5"
65}
66array(2) {
67  ["hash"]=>
68  string(%d) "%s"
69  ["hash_type"]=>
70  string(5) "SHA-1"
71}
72array(2) {
73  ["hash"]=>
74  string(%d) "%s"
75  ["hash_type"]=>
76  string(7) "SHA-256"
77}
78array(2) {
79  ["hash"]=>
80  string(%d) "%s"
81  ["hash_type"]=>
82  string(7) "SHA-512"
83}
84array(2) {
85  ["hash"]=>
86  string(%d) "%s"
87  ["hash_type"]=>
88  string(7) "OpenSSL"
89}
90===DONE===
91