]> git.mxchange.org Git - hub.git/commitdiff
The previously added but not used message helper is now being used (and filled with...
authorRoland Häder <roland@mxchange.org>
Tue, 29 Mar 2011 16:04:22 +0000 (16:04 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 29 Mar 2011 16:04:22 +0000 (16:04 +0000)
application/hub/config.php
application/hub/main/helper/messages/crypto/class_CryptoRandomMessageHelper.php
application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php
application/hub/main/source/units/class_TestUnitSource.php

index 3377f8b2bd2ae517128559accb77e6d81baf6910..88fefc51fc91f935db8e0f4252e0de1e2ff18c00 100644 (file)
@@ -573,5 +573,8 @@ $cfg->setConfigEntry('random_secret_key_length', 8);
 // CFG: TEST-UNIT-SOURCE-CLASS
 $cfg->setConfigEntry('test_unit_source_class', 'TestUnitSource');
 
+// CFG: CRYPTO-RANDOM-MESSAGE-HELPER-CLASS
+$cfg->setConfigEntry('crypto_random_message_helper_class', 'CryptoRandomMessageHelper');
+
 // [EOF]
 ?>
index ac725f6620f17192a2fb6aa04fe56d43363c2134..758006d52ae6fa005bcd14570abd43b80904fbb6 100644 (file)
@@ -41,9 +41,36 @@ class CryptoRandomMessageHelper extends BaseMessageHelper implements MessageHelp
                // Get new instance
                $messageInstance = new CryptoRandomMessageHelper();
 
+               // Create a RNG instance and set it in this class
+               $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+               $messageInstance->setRngInstance($rngInstance);
+
+               // And also a crypto instance (for our encrypted messages)
+               $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+               $messageInstance->setCryptoInstance($cryptoInstance);
+
                // Return the prepared instance
                return $messageInstance;
        }
+
+       /**
+        * Generates an encrypted random message
+        *
+        * @return      $encryptedMessage       The encrypted random message
+        */
+       public function generateRandomMessage () {
+               // Get a very secret message by encoding and random string with BASE64
+               $secretMessage = base64_encode($this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_message_length')));
+
+               // Get a random, secret key
+               $secretKey = $this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_key_length'));
+
+               // Now encrypt the message with our key and a good (strong) cipher
+               $encryptedMessage = base64_encode($this->getCryptoInstance()->encryptString($secretMessage, $secretKey));
+
+               // Return it
+               return $encryptedMessage;
+       }
 }
 
 // [EOF]
index 02d7052ef89745cdf27542a49ad5ab375c86033f..f735b6be66e66314c536b7bbc1a637430a73a7db 100644 (file)
@@ -100,6 +100,7 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer,
                } else {
                        // Get an encrypted, random message from our source
                        $encryptedMessage = $this->getSourceInstance()->generateMessageFromSource();
+                       die($encryptedMessage."\n");
                }
        }
 }
index 5a6f1886dec5bf035c2622f96f9f0607a520ed7d..8aaac2f4edcd6ecc7832064b7ca628c01e9bffaf 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class TestUnitSource extends BaseSource implements Sourceable {
+       /**
+        * Message helper instance
+        */
+       private $messageInstance = null;
+
        /**
         * Protected constructor
         *
@@ -41,14 +46,6 @@ class TestUnitSource extends BaseSource implements Sourceable {
                // Get new instance
                $sourceInstance = new TestUnitSource();
 
-               // Create a RNG instance and set it in this source
-               $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
-               $sourceInstance->setRngInstance($rngInstance);
-
-               // And also a crypto instance (for our encrypted messages)
-               $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
-               $sourceInstance->setCryptoInstance($cryptoInstance);
-
                // Return the prepared instance
                return $sourceInstance;
        }
@@ -59,14 +56,14 @@ class TestUnitSource extends BaseSource implements Sourceable {
         * @return      $encryptedMessage       The encrypted random message
         */
        public function generateMessageFromSource () {
-               // Get a very secret message by encoding and random string with BASE64
-               $secretMessage = base64_encode($this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_message_length')));
-
-               // Get a random, secret key
-               $secretKey = $this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_key_length'));
+               // Is the instance set?
+               if (is_null($this->messageInstance)) {
+                       // No, then create a new instance
+                       $this->messageInstance = ObjectFactory::createObjectByConfiguredName('crypto_random_message_helper_class');
+               } // END - if
 
-               // Now encrypt the message with our key and a good (strong) cipher
-               $encryptedMessage = base64_encode($this->getCryptoInstance()->encryptString($secretMessage, $secretKey));
+               // Get the message from the message helper
+               $encryptedMessage = $this->messageInstance->generateRandomMessage();
 
                // Return it
                return $encryptedMessage;