1--TEST-- 2Phar::setSupportedSignatures() with hash, tar-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(); 7if (!in_array("OpenSSL", $arr)) die("skip openssl support required"); 8if (!in_array('SHA-256', $arr)) die("skip hash extension loaded shared"); ?> 9--INI-- 10phar.require_hash=0 11phar.readonly=0 12--ENV-- 13TEMP=. 14TMP=. 15--FILE-- 16<?php 17$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; 18$p = new Phar($fname); 19$p['file1.txt'] = 'hi'; 20var_dump($p->getSignature()); 21$p->setSignatureAlgorithm(Phar::MD5); 22var_dump($p->getSignature()); 23$p->setSignatureAlgorithm(Phar::SHA1); 24var_dump($p->getSignature()); 25try { 26$p->setSignatureAlgorithm(Phar::SHA256); 27var_dump($p->getSignature()); 28} catch (Exception $e) { 29echo $e->getMessage(); 30} 31try { 32$p->setSignatureAlgorithm(Phar::SHA512); 33var_dump($p->getSignature()); 34} catch (Exception $e) { 35echo $e->getMessage(); 36} 37try { 38$config = dirname(__FILE__) . '/../files/openssl.cnf'; 39$config_arg = array('config' => $config); 40$private = openssl_get_privatekey(file_get_contents(dirname(dirname(__FILE__)) . '/files/private.pem')); 41$pkey = ''; 42openssl_pkey_export($private, $pkey, NULL, $config_arg); 43$p->setSignatureAlgorithm(Phar::OPENSSL, $pkey); 44var_dump($p->getSignature()); 45} catch (Exception $e) { 46echo $e->getMessage(); 47} 48?> 49===DONE=== 50--CLEAN-- 51<?php 52unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); 53?> 54--EXPECTF-- 55array(2) { 56 ["hash"]=> 57 string(%d) "%s" 58 ["hash_type"]=> 59 string(5) "SHA-1" 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} 91===DONE=== 92