Annotation of embedaddon/php/ext/phar/tests/phar_setsignaturealgo2.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Phar::setSupportedSignatures() with hash
3: --SKIPIF--
4: <?php
5: if (!extension_loaded("phar")) die("skip");
6: if (!extension_loaded("hash")) die("skip hash extension required");
7: $arr = Phar::getSupportedSignatures();
8: if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
9: if (!in_array('SHA-256', $arr)) die("skip hash extension loaded shared");
10: ?>
11: --INI--
12: phar.require_hash=0
13: phar.readonly=0
14: --FILE--
15: <?php
16: $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
17: $p = new Phar($fname);
18: $p['file1.txt'] = 'hi';
19: var_dump($p->getSignature());
20: $p->setSignatureAlgorithm(Phar::MD5);
21: var_dump($p->getSignature());
22: $p->setSignatureAlgorithm(Phar::SHA1);
23: var_dump($p->getSignature());
24: try {
25: $p->setSignatureAlgorithm(Phar::SHA256);
26: var_dump($p->getSignature());
27: } catch (Exception $e) {
28: echo $e->getMessage();
29: }
30: try {
31: $p->setSignatureAlgorithm(Phar::SHA512);
32: var_dump($p->getSignature());
33: } catch (Exception $e) {
34: echo $e->getMessage();
35: }
36: try {
1.1.1.2 ! misho 37: $config = dirname(__FILE__) . '/files/openssl.cnf';
! 38: $config_arg = array('config' => $config);
1.1 misho 39: $private = openssl_get_privatekey(file_get_contents(dirname(__FILE__) . '/files/private.pem'));
40: $pkey = '';
1.1.1.2 ! misho 41: openssl_pkey_export($private, $pkey, NULL, $config_arg);
1.1 misho 42: $p->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
43: var_dump($p->getSignature());
44: } catch (Exception $e) {
45: echo $e->getMessage();
46: }
47: ?>
48: ===DONE===
49: --CLEAN--
50: <?php
51: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
52: ?>
53: --EXPECTF--
54: array(2) {
55: ["hash"]=>
56: string(%d) "%s"
57: ["hash_type"]=>
58: string(5) "SHA-1"
59: }
60: array(2) {
61: ["hash"]=>
62: string(%d) "%s"
63: ["hash_type"]=>
64: string(3) "MD5"
65: }
66: array(2) {
67: ["hash"]=>
68: string(%d) "%s"
69: ["hash_type"]=>
70: string(5) "SHA-1"
71: }
72: array(2) {
73: ["hash"]=>
74: string(%d) "%s"
75: ["hash_type"]=>
76: string(7) "SHA-256"
77: }
78: array(2) {
79: ["hash"]=>
80: string(%d) "%s"
81: ["hash_type"]=>
82: string(7) "SHA-512"
83: }
84: array(2) {
85: ["hash"]=>
86: string(%d) "%s"
87: ["hash_type"]=>
88: string(7) "OpenSSL"
89: }
90: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>