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