helly Sun Jun 1 17:16:05 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/phar/phar pharcommand.inc Log: - Fix signature handling (and remaining API change fixes) http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar/pharcommand.inc?r1=1.49.2.3&r2=1.49.2.4&diff_format=u Index: php-src/ext/phar/phar/pharcommand.inc diff -u php-src/ext/phar/phar/pharcommand.inc:1.49.2.3 php-src/ext/phar/phar/pharcommand.inc:1.49.2.4 --- php-src/ext/phar/phar/pharcommand.inc:1.49.2.3 Sun Jun 1 07:39:06 2008 +++ php-src/ext/phar/phar/pharcommand.inc Sun Jun 1 17:16:04 2008 @@ -136,7 +136,11 @@ 'val' => NULL, 'inf' => '<regex> Regular expression for input files to exclude.' ), - + 'y' => array( + 'typ' => 'string', + 'val' => NULL, + 'inf' => 'Private key for OpenSSL signing.', + ), ); if (extension_loaded('zlib')) { @@ -150,6 +154,9 @@ } $hash_avail = Phar::getSupportedSignatures(); + if (!in_array('OpenSSL', $hash_avail)) { + unset($phar_args['y']); + } $hash_optional = array('SHA-256' => 'SHA256', 'SHA-512' => 'SHA512', 'OpenSSL' => 'OpenSSL'); @@ -347,6 +354,33 @@ return $arg; } // }}} + // {{{ static function phar_check_hash + /** + * Check whether hash method is valid. + * + * @return Hash constant to be used. + */ + function phar_check_hash($hash, $privkey) + { + switch($hash) + { + case 'md5': + return Phar::MD5; + case 'sha1': + return Phar::SHA1; + case 'sha256': + return Phar::SHA256; + case 'sha512': + return Phar::SHA512; + case 'openssl': + if (!$privkey) + { + self::error("Cannot use OpenSSL signing without key.\n"); + } + return Phar::OPENSSL; + } + } + // }}} // {{{ static function cli_cmd_inf_pack /** * Information pack @@ -370,7 +404,7 @@ */ static function cli_cmd_arg_pack() { - $args = self::phar_args('abcFhilpsx', 'pharnew'); + $args = self::phar_args('abcFhilpsxy', 'pharnew'); $args[''] = array( 'typ' => 'any', @@ -477,6 +511,7 @@ $hashbang = $this->args['b']['val']; $archive = $this->args['f']['val']; $hash = $this->args['h']['val']; + $privkey = $this->args['y']['val']; $regex = $this->args['i']['val']; $level = $this->args['l']['val']; $loader = $this->args['p']['val']; @@ -484,6 +519,8 @@ $invregex = $this->args['x']['val']; $input = $this->args['']['val']; + $hash = self::phar_check_hash($hash, $privkey); + $phar = new Phar($archive, 0, $alias); $phar->startBuffering(); @@ -510,12 +547,13 @@ $phar->compressFiles(Phar::BZ2); break; default: - $phar->compressFiles(Phar::NONE);; + $phar->decompressFiles();; break; } - if ($hash) { - $phar->setSignatureAlgorithm($hash); + if ($hash) + { + $phar->setSignatureAlgorithm($hash, $privkey); } $phar->stopBuffering(); @@ -594,11 +632,14 @@ switch($compress) { case 'gz': case 'gzip': - $phar[$entry]->setCompressedGZ(); + $phar[$entry]->compress(Phar::GZ); break; case 'bz2': case 'bzip2': - $phar[$entry]->setCompressedBZIP2(); + $phar[$entry]->compress(Phar::BZ2); + break; + case '0': + $phar[$entry]->decompress(); break; default: break; @@ -1047,24 +1088,24 @@ case 'gz': case 'gzip': if (isset($entry)) { - $phar[$entry]->setCompressedGZ(); + $phar[$entry]->compress(Phar::GZ); } else { - $phar->compressAllFilesGZ(); + $phar->compressFiles(Phar::GZ); } break; case 'bz2': case 'bzip2': if (isset($entry)) { - $phar[$entry]->setCompressedBZIP2(); + $phar[$entry]->compress(Phar::BZ2); } else { - $phar->compressAllFilesBZIP2(); + $phar->compressFiles(Phar::BZ2); } break; default: if (isset($entry)) { - $phar[$entry]->setUncompressed(); + $phar[$entry]->decompress(); } else { - $phar->uncompressAllFiles(); + $phar->decompressFiles(); } break; } @@ -1089,7 +1130,7 @@ */ public function cli_cmd_arg_sign() { - return self::phar_args('FH', 'phar'); + return self::phar_args('FHy', 'phar'); } // }}} // {{{ public function cli_cmd_run_sign @@ -1100,10 +1141,13 @@ */ public function cli_cmd_run_sign() { - $phar = $this->args['f']['val']; - $hash = $this->args['h']['val']; + $phar = $this->args['f']['val']; + $hash = $this->args['h']['val']; + $privkey = $this->args['y']['val']; + + $hash = self::phar_check_hash($hash, $privkey); - $phar->setSignatureAlgorithm($hash); + $phar->setSignatureAlgorithm($hash, $privkey); } // }}} // {{{ public function cli_cmd_inf_meta_set @@ -1391,9 +1435,9 @@ if ($ent->isCompressed()) { $ccount++; $csize += $ent->getCompressedSize(); - if ($ent->isCompressedGZ()) { + if ($ent->isCompressed(Phar::GZ)) { $compalg['GZ']++; - } elseif ($ent->isCompressedBZIP2()) { + } elseif ($ent->isCompressed(Phar::BZ2)) { $compalg['BZ2']++; } } else { @@ -1472,7 +1516,7 @@ $use_ext = extension_loaded('phar'); $version = array( 'PHP Version' => phpversion(), - 'phar.phar version' => '$Revision: 1.49.2.3 $', + 'phar.phar version' => '$Revision: 1.49.2.4 $', 'Phar EXT version' => $use_ext ? phpversion('phar') : 'Not available', 'Phar API version' => Phar::apiVersion(), 'Phar-based phar archives' => true,
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php