1--TEST--
2Phar::setSupportedSignatures() with hash, tar-based
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php
6$arr = Phar::getSupportedSignatures();
7if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
8--INI--
9phar.require_hash=0
10phar.readonly=0
11--FILE--
12<?php
13$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.tar';
14$p = new Phar($fname);
15$p['file1.txt'] = 'hi';
16var_dump($p->getSignature());
17$p->setSignatureAlgorithm(Phar::MD5);
18var_dump($p->getSignature());
19$p->setSignatureAlgorithm(Phar::SHA1);
20var_dump($p->getSignature());
21try {
22$p->setSignatureAlgorithm(Phar::SHA256);
23var_dump($p->getSignature());
24} catch (Exception $e) {
25echo $e->getMessage();
26}
27try {
28$p->setSignatureAlgorithm(Phar::SHA512);
29var_dump($p->getSignature());
30} catch (Exception $e) {
31echo $e->getMessage();
32}
33try {
34$config = __DIR__ . '/../files/openssl.cnf';
35$config_arg = array('config' => $config);
36$private = openssl_get_privatekey(file_get_contents(dirname(__DIR__) . '/files/private.pem'));
37$pkey = '';
38openssl_pkey_export($private, $pkey, NULL, $config_arg);
39$p->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
40var_dump($p->getSignature());
41} catch (Exception $e) {
42echo $e->getMessage();
43}
44?>
45===DONE===
46--CLEAN--
47<?php
48unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
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===DONE===
88