1--TEST--
2Phar::setSignatureAlgorithm()
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if ( extension_loaded("hash")) die("skip extension hash conflicts"); ?>
6<?php if (!defined("Phar::PGP")) die("skip PGP Signature algorithm not available"); ?>
7--INI--
8phar.require_hash=0
9phar.readonly=0
10--FILE--
11<?php
12$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
13$p['file1.txt'] = 'hi';
14var_dump($p->getSignature());
15$p->setSignatureAlgorithm(Phar::MD5);
16var_dump($p->getSignature());
17$p->setSignatureAlgorithm(Phar::SHA1);
18var_dump($p->getSignature());
19try {
20$p->setSignatureAlgorithm(Phar::SHA256);
21var_dump($p->getSignature());
22} catch (Exception $e) {
23echo $e->getMessage();
24}
25try {
26$p->setSignatureAlgorithm(Phar::SHA512);
27var_dump($p->getSignature());
28} catch (Exception $e) {
29echo $e->getMessage();
30}
31try {
32$p->setSignatureAlgorithm(Phar::PGP);
33var_dump($p->getSignature());
34} catch (Exception $e) {
35echo $e->getMessage();
36}
37?>
38===DONE===
39--CLEAN--
40<?php
41unlink(dirname(__FILE__) . '/brandnewphar.phar');
42?>
43--EXPECTF--
44array(2) {
45  ["hash"]=>
46  string(%d) "%s"
47  ["hash_type"]=>
48  string(5) "SHA-1"
49}
50array(2) {
51  ["hash"]=>
52  string(%d) "%s"
53  ["hash_type"]=>
54  string(3) "MD5"
55}
56array(2) {
57  ["hash"]=>
58  string(%d) "%s"
59  ["hash_type"]=>
60  string(5) "SHA-1"
61}
62string (82) "SHA-256 and SHA-512 signatures are only supported if the hash extension is enabled"
63string (82) "SHA-256 and SHA-512 signatures are only supported if the hash extension is enabled"
64array(2) {
65  ["hash"]=>
66  string(%d) "%s"
67  ["hash_type"]=>
68  string(5) "SHA-1"
69}
70===DONE===
71