* 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
*
// 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;
}
* @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('test_unit_random_secret_key_length') / 8);
- // 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;