Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'openid-renamed-interfaces' of https://github.com/prolic…
Browse files Browse the repository at this point in the history
…/zf2 into feature/zen27-openid
  • Loading branch information
weierophinney committed May 18, 2012
2 parents 42911f3 + f4f906d commit 00ac630
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 39 deletions.
18 changes: 9 additions & 9 deletions library/Zend/OpenId/Consumer/Storage/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class File extends AbstractStorage
* Constructs storage object and creates storage directory
*
* @param string $dir directory name to store data files in
* @throws Zend\OpenId\Exception
* @throws OpenId\Exception\RuntimeException
*/
public function __construct($dir = null)
{
Expand All @@ -67,27 +67,27 @@ public function __construct($dir = null)
$this->_dir = $dir;
if (!is_dir($this->_dir)) {
if (!@mkdir($this->_dir, 0700, 1)) {
throw new OpenId\Exception(
throw new OpenId\Exception\RuntimeException(
'Cannot access storage directory ' . $dir,
OpenId\Exception::ERROR_STORAGE);
OpenId\Exception\RuntimeException::ERROR_STORAGE);
}
}
if (($f = fopen($this->_dir.'/assoc.lock', 'w+')) === null) {
throw new OpenId\Exception(
throw new OpenId\Exception\RuntimeException(
'Cannot create a lock file in the directory ' . $dir,
OpenId\Exception::ERROR_STORAGE);
OpenId\Exception\RuntimeException::ERROR_STORAGE);
}
fclose($f);
if (($f = fopen($this->_dir.'/discovery.lock', 'w+')) === null) {
throw new OpenId\Exception(
throw new OpenId\Exception\RuntimeException(
'Cannot create a lock file in the directory ' . $dir,
OpenId\Exception::ERROR_STORAGE);
OpenId\Exception\RuntimeException::ERROR_STORAGE);
}
fclose($f);
if (($f = fopen($this->_dir.'/nonce.lock', 'w+')) === null) {
throw new OpenId\Exception(
throw new OpenId\Exception\RuntimeException(
'Cannot create a lock file in the directory ' . $dir,
OpenId\Exception::ERROR_STORAGE);
OpenId\Exception\RuntimeException::ERROR_STORAGE);
}
fclose($f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\OpenId;
namespace Zend\OpenId\Exception;

/**
* Exception class for Zend\OpenId
*
* @category Zend
* @package Zend_OpenId
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Exception
interface ExceptionInterface
{

/**
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/OpenId/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\OpenId\Exception;

class InvalidArgumentException
extends \InvalidArgumentException
implements ExceptionInterface
{}
8 changes: 8 additions & 0 deletions library/Zend/OpenId/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\OpenId\Exception;

class RuntimeException
extends \RuntimeException
implements ExceptionInterface
{}
22 changes: 11 additions & 11 deletions library/Zend/OpenId/OpenId.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ static public function randomBytes($len)
* @param string $func digest algorithm
* @param string $data data to sign
* @return string RAW digital signature
* @throws Zend\OpenId\Exception
* @throws Exception\InvalidArgumentException
*/
static public function digest($func, $data)
{
Expand All @@ -508,9 +508,9 @@ static public function digest($func, $data)
return mhash(MHASH_SHA256 , $data);
}
}
throw new Exception(
throw new Exception\InvalidArgumentException(
'Unsupported digest algorithm "' . $func . '".',
Exception::UNSUPPORTED_DIGEST);
Exception\InvalidArgumentException::UNSUPPORTED_DIGEST);
}

/**
Expand Down Expand Up @@ -546,7 +546,7 @@ static public function hashHmac($macFunc, $data, $secret)
*
* @param string $bin binary representation of big number
* @return mixed
* @throws Zend\OpenId\Exception
* @throws Exception\RuntimeException
*/
static protected function binToBigNum($bin)
{
Expand All @@ -561,7 +561,7 @@ static protected function binToBigNum($bin)
}
return $bn;
}
throw new Exception(
throw new Exception\RuntimeException(
'The system doesn\'t have proper big integer extension',
Exception::UNSUPPORTED_LONG_MATH);
}
Expand All @@ -572,7 +572,7 @@ static protected function binToBigNum($bin)
*
* @param mixed $bn big number
* @return string
* @throws Zend\OpenId\Exception
* @throws Exception\RuntimeException
*/
static protected function bigNumToBin($bn)
{
Expand Down Expand Up @@ -603,9 +603,9 @@ static protected function bigNumToBin($bn)
}
return $bin;
}
throw new Exception(
throw new Exception\RuntimeException(
'The system doesn\'t have proper big integer extension',
Exception::UNSUPPORTED_LONG_MATH);
Exception\RuntimeException::UNSUPPORTED_LONG_MATH);
}

/**
Expand Down Expand Up @@ -686,7 +686,7 @@ static public function getDhKeyDetails($dh)
* @param string $pub_key other party's public value
* @param mixed $dh Diffie-Hellman key
* @return string
* @throws Zend\OpenId\Exception
* @throws Exception\RuntimeException
*/
static public function computeDhSecret($pub_key, $dh)
{
Expand All @@ -705,9 +705,9 @@ static public function computeDhSecret($pub_key, $dh)
$bn_secret = bcpowmod($bn_pub_key, $dh['priv_key'], $dh['p']);
return self::bigNumToBin($bn_secret);
}
throw new Exception(
throw new Exception\RuntimeException(
'The system doesn\'t have proper big integer extension',
Exception::UNSUPPORTED_LONG_MATH);
Exception\RuntimeException::UNSUPPORTED_LONG_MATH);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions library/Zend/OpenId/Provider/Storage/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class File extends AbstractStorage
* Constructs storage object and creates storage directory
*
* @param string $dir directory name to store data files in
* @throws Zend\OpenId\Exception
* @throws OpenId\Exception\RuntimeException
*/
public function __construct($dir = null)
{
Expand All @@ -67,21 +67,21 @@ public function __construct($dir = null)
$this->_dir = $dir;
if (!is_dir($this->_dir)) {
if (!@mkdir($this->_dir, 0700, 1)) {
throw new OpenId\Exception(
throw new OpenId\Exception\RuntimeException(
"Cannot access storage directory $dir",
OpenId\Exception::ERROR_STORAGE);
OpenId\Exception\RuntimeException::ERROR_STORAGE);
}
}
if (($f = fopen($this->_dir.'/assoc.lock', 'w+')) === null) {
throw new OpenId\Exception(
throw new OpenId\Exception\RuntimeException(
'Cannot create a lock file in the directory ' . $dir,
OpenId\Exception::ERROR_STORAGE);
OpenId\Exception\RuntimeException::ERROR_STORAGE);
}
fclose($f);
if (($f = fopen($this->_dir.'/user.lock', 'w+')) === null) {
throw new OpenId\Exception(
throw new OpenId\Exception\RuntimeException(
'Cannot create a lock file in the directory ' . $dir,
OpenId\Exception::ERROR_STORAGE);
OpenId\Exception\RuntimeException::ERROR_STORAGE);
}
fclose($f);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/OpenId/Consumer/Storage/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public function testConstruct()
} catch (\Exception $e) {
$ex = $e;
}
$this->assertTrue( $ex instanceof \Zend\OpenId\Exception );
$this->assertSame( \Zend\OpenId\Exception::ERROR_STORAGE, $ex->getCode() );
$this->assertTrue( $ex instanceof \Zend\OpenId\Exception\ExceptionInterface );
$this->assertSame( \Zend\OpenId\Exception\ExceptionInterface::ERROR_STORAGE, $ex->getCode() );
$this->assertContains( 'Cannot access storage directory', $ex->getMessage() );
chmod($dir, 0777);
$this->assertFalse( is_dir($dir2) );
Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/OpenId/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public function testAssociate()
$this->assertSame( "sha256", $macFunc );
$this->assertSame( "ed901bc561c29fd7bb42862e5f09fa37e7944a7ee72142322f34a21bfe1384b8", bin2hex($secret) );
$this->assertTrue( $storage->delAssociation(self::SERVER) );
} catch (\Zend\OpenId\Exception $e) {
} catch (\Zend\OpenId\Exception\ExceptionInterface $e) {
$this->markTestSkipped($e->getMessage());
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/OpenId/OpenIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function testCreateDhKey()
$this->assertTrue( strlen($dh_details['priv_key']) > 0 );
$this->assertTrue( is_string($dh_details['pub_key']) );
$this->assertTrue( strlen($dh_details['pub_key']) > 0 );
} catch (\Zend\OpenId\Exception $e) {
} catch (\Zend\OpenId\Exception\ExceptionInterface $e) {
$this->markTestSkipped($e->getMessage());
}
}
Expand Down Expand Up @@ -632,7 +632,7 @@ public function testComputeDhSecret()
bin2hex(OpenId::computeDhSecret($alice_details['pub_key'], $bob)) );
$this->assertSame( '75',
bin2hex(OpenId::computeDhSecret($bob_details['pub_key'], $alice)) );
} catch (\Zend\OpenId\Exception $e) {
} catch (\Zend\OpenId\Exception\ExceptionInterface $e) {
$this->markTestSkipped($e->getMessage());
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/OpenId/Provider/Storage/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function testConstruct()
} catch (\Exception $e) {
$ex = $e;
}
$this->assertTrue( $ex instanceof \Zend\OpenId\Exception );
$this->assertSame( \Zend\OpenId\Exception::ERROR_STORAGE, $ex->getCode() );
$this->assertTrue( $ex instanceof \Zend\OpenId\Exception\ExceptionInterface );
$this->assertSame( \Zend\OpenId\Exception\ExceptionInterface::ERROR_STORAGE, $ex->getCode() );
$this->assertContains( 'Cannot access storage directory', $ex->getMessage() );
chmod($dir, 0777);
$this->assertFalse( is_dir($dir2) );
Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/OpenId/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ public function testAssociate()
$this->assertSame( '3600', $res['expires_in'] );
$this->assertTrue( $storage->getAssociation($res['assoc_handle'], $macFunc, $secret, $expires) );
$this->assertSame( 'sha256', $macFunc );
} catch (\Zend\OpenId\Exception $e) {
} catch (\Zend\OpenId\Exception\ExceptionInterface $e) {
$this->markTestSkipped($e->getMessage());
}
}
Expand Down

0 comments on commit 00ac630

Please sign in to comment.