1--TEST--
2Phar::setSupportedSignatures() with hash, tar-based
3--EXTENSIONS--
4phar
5--SKIPIF--
6<?php
7$arr = Phar::getSupportedSignatures();
8if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
9--INI--
10phar.require_hash=0
11phar.readonly=0
12--FILE--
13<?php
14$fname = __DIR__ . '/' . 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 = __DIR__ . '/../files/openssl.cnf';
36$config_arg = array('config' => $config);
37$private = openssl_get_privatekey(file_get_contents(dirname(__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$p->setSignatureAlgorithm(Phar::OPENSSL_SHA512, $pkey);
43var_dump($p->getSignature());
44$p->setSignatureAlgorithm(Phar::OPENSSL_SHA256, $pkey);
45var_dump($p->getSignature());
46} catch (Exception $e) {
47echo $e->getMessage();
48}
49?>
50--CLEAN--
51<?php
52unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
53?>
54--EXPECTF--
55array(2) {
56  ["hash"]=>
57  string(%d) "%s"
58  ["hash_type"]=>
59  string(7) "SHA-256"
60}
61array(2) {
62  ["hash"]=>
63  string(%d) "%s"
64  ["hash_type"]=>
65  string(3) "MD5"
66}
67array(2) {
68  ["hash"]=>
69  string(%d) "%s"
70  ["hash_type"]=>
71  string(5) "SHA-1"
72}
73array(2) {
74  ["hash"]=>
75  string(%d) "%s"
76  ["hash_type"]=>
77  string(7) "SHA-256"
78}
79array(2) {
80  ["hash"]=>
81  string(%d) "%s"
82  ["hash_type"]=>
83  string(7) "SHA-512"
84}
85array(2) {
86  ["hash"]=>
87  string(%d) "%s"
88  ["hash_type"]=>
89  string(7) "OpenSSL"
90}
91array(2) {
92  ["hash"]=>
93  string(%d) "%s"
94  ["hash_type"]=>
95  string(14) "OpenSSL_SHA512"
96}
97array(2) {
98  ["hash"]=>
99  string(%d) "%s"
100  ["hash_type"]=>
101  string(14) "OpenSSL_SHA256"
102}
103