Exemplo n.º 1
0
 /**
  * @override
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $verbose = OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity();
     $phar = $input->getArgument('phar');
     if ($verbose) {
         $output->writeln('Verifying the Phar...');
     }
     if (false === is_file($phar)) {
         $output->writeln(sprintf('<error>The path "%s" is not a file or does not exist.</error>', $phar));
         return 1;
     }
     $signature = null;
     $verified = false;
     try {
         if (!$input->getOption('no-extension') && extension_loaded('phar')) {
             $phar = new Phar($phar);
             $verified = true;
             $signature = $phar->getSignature();
         } else {
             $phar = new Signature($phar);
             $verified = $phar->verify();
             $signature = $phar->get();
         }
     } catch (Exception $exception) {
     }
     if ($verified) {
         $output->writeln('<info>The Phar passed verification.</info>');
         if ($verbose) {
             $output->writeln($signature['hash_type'] . ' Signature:');
             $output->writeln($signature['hash']);
         }
         return 1;
     }
     $output->writeln('<error>The Phar failed verification.</error>');
     if ($verbose && isset($exception)) {
         throw $exception;
     }
     return 0;
 }
Exemplo n.º 2
0
 /**
  * @dataProvider getPhars
  */
 public function testVerify($path)
 {
     $sig = new Signature($path);
     $this->assertTrue($sig->verify());
 }
Exemplo n.º 3
0
 /**
  * Returns the signature of the phar.
  *
  * This method does not use the extension to extract the phar's signature.
  *
  * @param string  $path The phar file path.
  *
  * @return array The signature.
  */
 public static function getSignature($path)
 {
     return Signature::create($path)->get();
 }