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--CLEAN--
46<?php
47unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
48?>
49--EXPECTF--
50array(2) {
51  ["hash"]=>
52  string(%d) "%s"
53  ["hash_type"]=>
54  string(5) "SHA-1"
55}
56array(2) {
57  ["hash"]=>
58  string(%d) "%s"
59  ["hash_type"]=>
60  string(3) "MD5"
61}
62array(2) {
63  ["hash"]=>
64  string(%d) "%s"
65  ["hash_type"]=>
66  string(5) "SHA-1"
67}
68array(2) {
69  ["hash"]=>
70  string(%d) "%s"
71  ["hash_type"]=>
72  string(7) "SHA-256"
73}
74array(2) {
75  ["hash"]=>
76  string(%d) "%s"
77  ["hash_type"]=>
78  string(7) "SHA-512"
79}
80array(2) {
81  ["hash"]=>
82  string(%d) "%s"
83  ["hash_type"]=>
84  string(7) "OpenSSL"
85}
86