From f82b24f9c7657a083cf5bc7e6b9465d24aa191ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 7 Aug 2009 23:14:52 +0000 Subject: [PATCH] rngInstance is now located in BaseFrameworkSystem --- .../main/class_BaseFrameworkSystem.php | 26 ++++++++++++++++++- .../main/crypto/class_CryptoHelper.php | 8 +++--- .../main/helper/captcha/class_BaseCaptcha.php | 16 +----------- inc/classes/main/streams/class_BaseStream.php | 24 ----------------- 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index a3edd83f..16c04ed9 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -73,10 +73,15 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $controllerInstance = null; + /** + * Instance of an RNG + */ + private $rngInstance = null; + /** * The real class name */ - private $realClass = 'FrameworkSystem'; + private $realClass = 'BaseFrameworkSystem'; /** * Thousands seperator @@ -1140,6 +1145,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Return result return $isLoaded; } + + /** + * Setter for RNG instance + * + * @param $rngInstance An instance of a random number generator (RNG) + * @return void + */ + protected final function setRngInstance (RandomNumberGenerator $rngInstance) { + $this->rngInstance = $rngInstance; + } + + /** + * Getter for RNG instance + * + * @return $rngInstance An instance of a random number generator (RNG) + */ + public final function getRngInstance () { + return $this->rngInstance; + } } // [EOF] diff --git a/inc/classes/main/crypto/class_CryptoHelper.php b/inc/classes/main/crypto/class_CryptoHelper.php index 2335f5dc..c135b189 100644 --- a/inc/classes/main/crypto/class_CryptoHelper.php +++ b/inc/classes/main/crypto/class_CryptoHelper.php @@ -105,7 +105,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { // Do we have mcrypt loaded? if ($this->isPhpExtensionLoaded('mcrypt')) { // Then use it - $this->cryptoStreamInstance = ObjectFactory::createObjectByName('McryptStream', array($this->rngInstance())); + $this->cryptoStreamInstance = ObjectFactory::createObjectByName('McryptStream', array($this->getRngInstance())); } else { // If nothing works ... $this->cryptoStreamInstance = ObjectFactory::createObjectByName('NullCryptoStream'); @@ -119,7 +119,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { */ protected function initHasher () { // Initialize the random number generator which is required by some crypto methods - $this->rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); + $this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class')); // Generate a salt for the hasher $this->generateSalt(); @@ -132,7 +132,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { */ private function generateSalt () { // Get a random string from the RNG - $randomString = $this->rngInstance->randomString(); + $randomString = $this->getRngInstance()->randomString(); // Get config entry for salt length $length = $this->getConfigInstance()->getConfigEntry('salt_length'); @@ -171,7 +171,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { //* DEBUG: */ echo "salt=".$salt."/plain=".$str."
\n"; $hashed = $salt . md5(sprintf($this->getConfigInstance()->getConfigEntry('hash_mask'), $salt, - $this->rngInstance->getFixedSalt(), + $this->getRngInstance()->getFixedSalt(), $str )); diff --git a/inc/classes/main/helper/captcha/class_BaseCaptcha.php b/inc/classes/main/helper/captcha/class_BaseCaptcha.php index 9cef2076..e6190588 100644 --- a/inc/classes/main/helper/captcha/class_BaseCaptcha.php +++ b/inc/classes/main/helper/captcha/class_BaseCaptcha.php @@ -27,11 +27,6 @@ class BaseCaptcha extends BaseHelper { */ private $helperInstance = null; - /** - * Instance of an RNG - */ - private $rngInstance = null; - /** * Protected constructor * @@ -51,16 +46,7 @@ class BaseCaptcha extends BaseHelper { */ protected final function initializeRandomNumberGenerator (FrameworkInterface $extraInstance = null) { // Get an RNG from factory - $this->rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class', array($extraInstance)); - } - - /** - * Getter for RNG instance - * - * @return $rngInstance An instance of a random number generator (RNG) - */ - public final function getRngInstance () { - return $this->rngInstance; + $this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class', array($extraInstance))); } /** diff --git a/inc/classes/main/streams/class_BaseStream.php b/inc/classes/main/streams/class_BaseStream.php index 728e6c3e..e226545a 100644 --- a/inc/classes/main/streams/class_BaseStream.php +++ b/inc/classes/main/streams/class_BaseStream.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class BaseStream extends BaseFrameworkSystem { - /** - * Random number generator instance (RNG) - */ - private $rngInstance = null; - /** * Protected constructor * @@ -41,25 +36,6 @@ class BaseStream extends BaseFrameworkSystem { $this->removeNumberFormaters(); $this->removeSystemArray(); } - - /** - * Setter for RNG instance - * - * @param $rngInstance An RNG instance - * @return void - */ - protected final function setRngInstance (RandomNumberGenerator $rngInstance) { - $this->rngInstance = $rngInstance; - } - - /** - * Getter for RNG instance - * - * @return $rngInstance An RNG instance - */ - protected final function getRngInstance () { - return $this->rngInstance; - } } // [EOF] -- 2.39.2