Annotation of embedaddon/php/ext/phar/tests/zip/phar_setsignaturealgo2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Phar::setSupportedSignatures() with hash, zip-based
3: --SKIPIF--
4: <?php if (!extension_loaded("phar")) die("skip"); ?>
5: <?php if (!extension_loaded("hash")) die("skip extension hash required");
6: $arr = Phar::getSupportedSignatures();
7: if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
8: if (!in_array('SHA-256', $arr)) die("skip hash extension loaded shared"); ?>
9: --INI--
10: phar.require_hash=0
11: phar.readonly=0
12: --FILE--
13: <?php
14: $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
15: $fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
16: $fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.3.phar.zip';
17: $fname4 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.4.phar.zip';
18: $fname5 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.5.phar.zip';
19: $fname6 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.6.phar.zip';
20: $p = new Phar($fname);
21: $p['file1.txt'] = 'hi';
22: var_dump($p->getSignature());
23: $p->setSignatureAlgorithm(Phar::MD5);
24:
25: copy($fname, $fname2);
26: $p = new Phar($fname2);
27: var_dump($p->getSignature());
28:
29: $p->setSignatureAlgorithm(Phar::SHA1);
30:
31: copy($fname2, $fname3);
32: $p = new Phar($fname3);
33: var_dump($p->getSignature());
34:
35: try {
36: $p->setSignatureAlgorithm(Phar::SHA256);
37: copy($fname3, $fname4);
38: $p = new Phar($fname4);
39: var_dump($p->getSignature());
40: } catch (Exception $e) {
41: echo $e->getMessage();
42: }
43: try {
44: $p->setSignatureAlgorithm(Phar::SHA512);
45: copy($fname4, $fname5);
46: $p = new Phar($fname5);
47: var_dump($p->getSignature());
48: } catch (Exception $e) {
49: echo $e->getMessage();
50: }
51: try {
52: $keys=openssl_pkey_new();
53: openssl_pkey_export($keys, $privkey);
54: $pubkey=openssl_pkey_get_details($keys);
55: $p->setSignatureAlgorithm(Phar::OPENSSL, $privkey);
56:
57: copy($fname5, $fname6);
58: file_put_contents($fname6 . '.pubkey', $pubkey['key']);
59: $p = new Phar($fname6);
60: var_dump($p->getSignature());
61: } catch (Exception $e) {
62: echo $e->getMessage();
63: }
64: ?>
65: ===DONE===
66: --CLEAN--
67: <?php
68: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
69: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
70: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar.zip');
71: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.4.phar.zip');
72: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.5.phar.zip');
73: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip');
74: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip.pubkey');
75: ?>
76: --EXPECTF--
77: array(2) {
78: ["hash"]=>
79: string(%d) "%s"
80: ["hash_type"]=>
81: string(5) "SHA-1"
82: }
83: array(2) {
84: ["hash"]=>
85: string(%d) "%s"
86: ["hash_type"]=>
87: string(3) "MD5"
88: }
89: array(2) {
90: ["hash"]=>
91: string(%d) "%s"
92: ["hash_type"]=>
93: string(5) "SHA-1"
94: }
95: array(2) {
96: ["hash"]=>
97: string(%d) "%s"
98: ["hash_type"]=>
99: string(7) "SHA-256"
100: }
101: array(2) {
102: ["hash"]=>
103: string(%d) "%s"
104: ["hash_type"]=>
105: string(7) "SHA-512"
106: }
107: array(2) {
108: ["hash"]=>
109: string(%d) "%s"
110: ["hash_type"]=>
111: string(7) "OpenSSL"
112: }
113: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>