public function testLastError() { if (false === extension_loaded('openssl')) { $this->markTestSkipped('The "openssl" extension is required to test the exception.'); } OpenSslException::reset(); openssl_pkey_get_private('test', 'test'); $exception = OpenSslException::lastError(); $this->assertRegExp('/PEM routines/', $exception->getMessage()); }
/** * @see VerifyInterface::verify */ public function verify($signature) { OpenSslException::reset(); ob_start(); $result = openssl_verify($this->getData(), @pack('H*', $signature), $this->getKey()); $error = trim(ob_get_clean()); if (-1 === $result) { throw OpenSslException::lastError(); } elseif (!empty($error)) { throw new OpenSslException($error); } return 1 === $result; }
/** * 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(); } }