3 namespace Org\Mxchange\CoreFramework\Stream\Crypto\Null;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
7 use Org\Mxchange\CoreFramework\Stream\Crypto\BaseCryptoStream;
8 use Org\Mxchange\CoreFramework\Stream\Crypto\EncryptableStream;
11 * A null-encryption stream does not encrypt anything but can be used if e.e.
12 * mcrypt is not installed.
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Developer Team
17 * @license GNU GPL 3.0 or any newer version
18 * @link http://www.shipsimu.org
20 * This program is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 class NullCryptoStream extends BaseCryptoStream implements EncryptableStream {
35 * Protected constructor
39 protected function __construct () {
40 // Call parent constructor
41 parent::__construct(__CLASS__);
45 * Creates an instance of this node class
47 * @return $streamInstance An instance of this node class
49 public static final function createNullCryptoStream () {
51 $streamInstance = new NullCryptoStream();
53 // Return the instance
54 return $streamInstance;
58 * Encrypt the string with fixed salt
60 * @param $str The unencrypted string
61 * @param $key Optional key, if none provided, a random key will be generated
62 * @return $encrypted Encrypted string
64 public function encryptStream ($str, $key = NULL) {
65 // Just handle it over
66 $encrypted = (string) $str;
73 * Decrypt the string with fixed salt
75 * @param $encrypted Encrypted string
76 * @return $str The unencrypted string
78 public function decryptStream ($encrypted) {
79 // Just handle it over
80 $str = (string) $encrypted;
87 * Streams the data and maybe does something to it
89 * @param $data The data (string mostly) to "stream"
90 * @return $data The data (string mostly) to "stream"
91 * @throws UnsupportedOperationException If this method is called (which is a mistake)
93 public function streamData (string $data) {
94 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
95 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);