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