Пример #1
0
 /**
  * Signs the Phar using a private key.
  *
  * @param string $key      The private key.
  * @param string $password The private key password.
  *
  * @throws Exception\Exception
  * @throws OpenSslException If the "openssl" extension could not be used
  *                          or has generated an error.
  */
 public function sign($key, $password = null)
 {
     OpenSslException::reset();
     if (false === extension_loaded('openssl')) {
         // @codeCoverageIgnoreStart
         throw OpenSslException::create('The "openssl" extension is not available.');
         // @codeCoverageIgnoreEnd
     }
     if (false === ($resource = openssl_pkey_get_private($key, $password))) {
         // @codeCoverageIgnoreStart
         throw OpenSslException::lastError();
         // @codeCoverageIgnoreEnd
     }
     if (false === openssl_pkey_export($resource, $private)) {
         // @codeCoverageIgnoreStart
         throw OpenSslException::lastError();
         // @codeCoverageIgnoreEnd
     }
     if (false === ($details = openssl_pkey_get_details($resource))) {
         // @codeCoverageIgnoreStart
         throw OpenSslException::lastError();
         // @codeCoverageIgnoreEnd
     }
     $this->phar->setSignatureAlgorithm(Phar::OPENSSL, $private);
     if (false === @file_put_contents($this->file . '.pubkey', $details['key'])) {
         throw FileException::lastError();
     }
 }