Skip to content

Commit

Permalink
[NS4] Migrated Zend_Crypt to namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Apr 5, 2010
1 parent 4c2c9b9 commit 9debea3
Show file tree
Hide file tree
Showing 28 changed files with 695 additions and 437 deletions.
2 changes: 1 addition & 1 deletion README-DEV.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Third pass:
Fourth pass:
THE FOLLOWING IN ANY ORDER (except where indicated):
[ ] Zend_Json
[ ] Zend_Crypt -> [ ] Zend_Oauth, [ ] Zend_XmlRpc
[X] Zend_Crypt -> [ ] Zend_Oauth, [ ] Zend_XmlRpc
[X] Zend_Acl
[ ] Zend_Reflection
[ ] Zend_CodeGenerator
Expand Down
51 changes: 27 additions & 24 deletions library/Zend/Crypt.php → library/Zend/Crypt/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@
*/

/**
* @uses Zend_Crypt_Exception
* @namespace
*/
namespace Zend\Crypt;

/**
* @uses Zend\Crypt\Exception
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt
class Crypt
{

const TYPE_OPENSSL = 'openssl';
const TYPE_HASH = 'hash';
const TYPE_MHASH = 'mhash';
const TYPE_HASH = 'hash';
const TYPE_MHASH = 'mhash';

protected static $_type = null;

Expand All @@ -48,7 +52,7 @@ class Zend_Crypt
'sha224',
'sha256',
'sha384',
'sha512'
'sha512',
);

/**
Expand All @@ -70,14 +74,14 @@ class Zend_Crypt
'sha256',
'tiger',
'tiger128',
'tiger160'
'tiger160',
);

/**
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @return unknown
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @return void
*/
public static function hash($algorithm, $data, $binaryOutput = false)
{
Expand All @@ -91,8 +95,8 @@ public static function hash($algorithm, $data, $binaryOutput = false)
}

/**
* @param string $algorithm
* @throws Zend_Crypt_Exception
* @param string $algorithm
* @throws Zend\Crypt\Exception
*/
protected static function _detectHashSupport($algorithm)
{
Expand All @@ -117,13 +121,13 @@ protected static function _detectHashSupport($algorithm)
return;
}
}
throw new Zend_Crypt_Exception('\'' . $algorithm . '\' is not supported by any available extension or native function');
throw new Exception('\'' . $algorithm . '\' is not supported by any available extension or native function');
}

/**
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @return string
*/
protected static function _digestHash($algorithm, $data, $binaryOutput)
Expand All @@ -132,9 +136,9 @@ protected static function _digestHash($algorithm, $data, $binaryOutput)
}

/**
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @return string
*/
protected static function _digestMhash($algorithm, $data, $binaryOutput)
Expand All @@ -148,9 +152,9 @@ protected static function _digestMhash($algorithm, $data, $binaryOutput)
}

/**
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @return string
*/
protected static function _digestOpenssl($algorithm, $data, $binaryOutput)
Expand All @@ -160,5 +164,4 @@ protected static function _digestOpenssl($algorithm, $data, $binaryOutput)
}
return openssl_digest($data, $algorithm, $binaryOutput);
}

}
43 changes: 24 additions & 19 deletions library/Zend/Crypt/DiffieHellman.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@
* @version $Id$
*/

/**
* @namespace
*/
namespace Zend\Crypt;

/**
* PHP implementation of the Diffie-Hellman public key encryption algorithm.
* Allows two unassociated parties to establish a joint shared secret key
* to be used in encrypting subsequent communications.
*
* @uses Zend_Crypt_DiffieHellman_Exception
* @uses Zend_Crypt_Math
* @uses Zend\Crypt\DiffieHellmanException
* @uses Zend\Crypt\Math\Math
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_DiffieHellman
class DiffieHellman
{

/**
Expand Down Expand Up @@ -69,7 +74,7 @@ class Zend_Crypt_DiffieHellman
/**
* BigInteger support object courtesy of Zend_Crypt_Math
*
* @var Zend_Crypt_Math_BigInteger
* @var Zend\Crypt\Math\BigInteger\BigInteger
*/
private $_math = null;

Expand Down Expand Up @@ -120,7 +125,7 @@ public function __construct($prime, $generator, $privateKey = null, $privateKeyT
* Generate own public key. If a private number has not already been
* set, one will be generated at this stage.
*
* @return Zend_Crypt_DiffieHellman
* @return Zend\Crypt\DiffieHellman
*/
public function generateKeys()
{
Expand Down Expand Up @@ -148,15 +153,15 @@ public function generateKeys()
*
* @param string $number
* @param string $type
* @return Zend_Crypt_DiffieHellman
* @return Zend\Crypt\DiffieHellman
*/
public function setPublicKey($number, $type = self::NUMBER)
{
if ($type == self::BINARY) {
$number = $this->_math->fromBinary($number);
}
if (!preg_match("/^\d+$/", $number)) {
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number');
throw new DiffieHellmanException('invalid parameter; not a positive natural number');
}
$this->_publicKey = (string) $number;
return $this;
Expand All @@ -172,7 +177,7 @@ public function setPublicKey($number, $type = self::NUMBER)
public function getPublicKey($type = self::NUMBER)
{
if (is_null($this->_publicKey)) {
throw new Zend_Crypt_DiffieHellman_Exception('A public key has not yet been generated using a prior call to generateKeys()');
throw new DiffieHellmanException('A public key has not yet been generated using a prior call to generateKeys()');
}
if ($type == self::BINARY) {
return $this->_math->toBinary($this->_publicKey);
Expand Down Expand Up @@ -203,7 +208,7 @@ public function computeSecretKey($publicKey, $type = self::NUMBER, $output = sel
$publicKey = $this->_math->fromBinary($publicKey);
}
if (!preg_match("/^\d+$/", $publicKey)) {
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number');
throw new DiffieHellmanException('invalid parameter; not a positive natural number');
}
if (function_exists('openssl_dh_compute_key') && self::$useOpenssl !== false) {
$this->_secretKey = openssl_dh_compute_key($publicKey, $this->getPublicKey());
Expand All @@ -222,7 +227,7 @@ public function computeSecretKey($publicKey, $type = self::NUMBER, $output = sel
public function getSharedSecretKey($type = self::NUMBER)
{
if (!isset($this->_secretKey)) {
throw new Zend_Crypt_DiffieHellman_Exception('A secret key has not yet been computed; call computeSecretKey()');
throw new DiffieHellmanException('A secret key has not yet been computed; call computeSecretKey()');
}
if ($type == self::BINARY) {
return $this->_math->toBinary($this->_secretKey);
Expand All @@ -236,12 +241,12 @@ public function getSharedSecretKey($type = self::NUMBER)
* Setter for the value of the prime number
*
* @param string $number
* @return Zend_Crypt_DiffieHellman
* @return Zend\Crypt\DiffieHellman
*/
public function setPrime($number)
{
if (!preg_match("/^\d+$/", $number) || $number < 11) {
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number or too small: should be a large natural number prime');
throw new DiffieHellmanException('invalid parameter; not a positive natural number or too small: should be a large natural number prime');
}
$this->_prime = (string) $number;
return $this;
Expand All @@ -255,7 +260,7 @@ public function setPrime($number)
public function getPrime()
{
if (!isset($this->_prime)) {
throw new Zend_Crypt_DiffieHellman_Exception('No prime number has been set');
throw new DiffieHellmanException('No prime number has been set');
}
return $this->_prime;
}
Expand All @@ -265,12 +270,12 @@ public function getPrime()
* Setter for the value of the generator number
*
* @param string $number
* @return Zend_Crypt_DiffieHellman
* @return Zend\Crypt\DiffieHellman
*/
public function setGenerator($number)
{
if (!preg_match("/^\d+$/", $number) || $number < 2) {
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number greater than 1');
throw new DiffieHellmanException('invalid parameter; not a positive natural number greater than 1');
}
$this->_generator = (string) $number;
return $this;
Expand All @@ -284,7 +289,7 @@ public function setGenerator($number)
public function getGenerator()
{
if (!isset($this->_generator)) {
throw new Zend_Crypt_DiffieHellman_Exception('No generator number has been set');
throw new DiffieHellmanException('No generator number has been set');
}
return $this->_generator;
}
Expand All @@ -294,15 +299,15 @@ public function getGenerator()
*
* @param string $number
* @param string $type
* @return Zend_Crypt_DiffieHellman
* @return Zend\Crypt\DiffieHellman
*/
public function setPrivateKey($number, $type = self::NUMBER)
{
if ($type == self::BINARY) {
$number = $this->_math->fromBinary($number);
}
if (!preg_match("/^\d+$/", $number)) {
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number');
throw new DiffieHellmanException('invalid parameter; not a positive natural number');
}
$this->_privateKey = (string) $number;
return $this;
Expand Down Expand Up @@ -348,7 +353,7 @@ public function hasPrivateKey()
*/
public function setBigIntegerMath($extension = null)
{
$this->_math = new Zend_Crypt_Math($extension);
$this->_math = new \Zend\Crypt\Math\Math($extension);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
*/

/**
* @uses Zend_Crypt_Exception
* @namespace
*/
namespace Zend\Crypt;

/**
* @uses Zend\Crypt\Exception
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_DiffieHellman_Exception extends Zend_Crypt_Exception
class DiffieHellmanException extends Exception
{
}
9 changes: 7 additions & 2 deletions library/Zend/Crypt/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
*/

/**
* @uses Zend_Exception
* @namespace
*/
namespace Zend\Crypt;

/**
* @uses \Zend\Exception
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Exception extends Zend_Exception
class Exception extends \Zend\Exception
{
}
Loading

0 comments on commit 9debea3

Please sign in to comment.