]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/source/units/class_TestUnitSource.php
Swapped code, moved/renamed classes and interfaces:
[hub.git] / application / hub / main / source / units / class_TestUnitSource.php
index 8aaac2f4edcd6ecc7832064b7ca628c01e9bffaf..804b06c2ea262b8a0846dcfa747717484e6c5372 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
         *
@@ -46,6 +41,14 @@ class TestUnitSource extends BaseSource implements Sourceable {
                // Get new instance
                $sourceInstance = new TestUnitSource();
 
+               // Create a RNG instance and set it in this class
+               $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;
        }
@@ -56,14 +59,14 @@ class TestUnitSource extends BaseSource implements Sourceable {
         * @return      $encryptedMessage       The encrypted random message
         */
        public function generateMessageFromSource () {
-               // 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
+               // 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'));
 
-               // Get the message from the message helper
-               $encryptedMessage = $this->messageInstance->generateRandomMessage();
+               // Now encrypt the message with our key and a good (strong) cipher
+               $encryptedMessage = base64_encode($this->getCryptoInstance()->encryptString($secretMessage, $secretKey));
 
                // Return it
                return $encryptedMessage;