1--TEST--
2Phar::setSupportedSignatures() with hash
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6$arr = Phar::getSupportedSignatures();
7if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
8?>
9--INI--
10phar.require_hash=0
11phar.readonly=0
12--FILE--
13<?php
14$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';
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 = __DIR__ . '/files/openssl.cnf';
36$config_arg = array('config' => $config);
37$private = openssl_get_privatekey(file_get_contents(__DIR__ . '/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--CLEAN--
47<?php
48unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar');
49?>
50--EXPECTF--
51array(2) {
52  ["hash"]=>
53  string(%d) "%s"
54  ["hash_type"]=>
55  string(5) "SHA-1"
56}
57array(2) {
58  ["hash"]=>
59  string(%d) "%s"
60  ["hash_type"]=>
61  string(3) "MD5"
62}
63array(2) {
64  ["hash"]=>
65  string(%d) "%s"
66  ["hash_type"]=>
67  string(5) "SHA-1"
68}
69array(2) {
70  ["hash"]=>
71  string(%d) "%s"
72  ["hash_type"]=>
73  string(7) "SHA-256"
74}
75array(2) {
76  ["hash"]=>
77  string(%d) "%s"
78  ["hash_type"]=>
79  string(7) "SHA-512"
80}
81array(2) {
82  ["hash"]=>
83  string(%d) "%s"
84  ["hash_type"]=>
85  string(7) "OpenSSL"
86}
87