]> git.mxchange.org Git - core.git/blob - framework/main/classes/streams/crypto/null/class_NullCryptoStream.php
38337ba537c342cb896f6e3da5287ff5054d7efc
[core.git] / framework / main / classes / streams / crypto / null / class_NullCryptoStream.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Stream\Crypto\Null;
4
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;
9
10 /**
11  * A null-encryption stream does not encrypt anything but can be used if e.e.
12  * mcrypt is not installed.
13  *
14  * @author              Roland Haeder <webmaster@shipsimu.org>
15  * @version             0.0.0
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
19  *
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.
24  *
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.
29  *
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/>.
32  */
33 class NullCryptoStream extends BaseCryptoStream implements EncryptableStream {
34         /**
35          * Protected constructor
36          *
37          * @return      void
38          */
39         protected function __construct () {
40                 // Call parent constructor
41                 parent::__construct(__CLASS__);
42         }
43
44         /**
45          * Creates an instance of this node class
46          *
47          * @return      $streamInstance         An instance of this node class
48          */
49         public static final function createNullCryptoStream () {
50                 // Get a new instance
51                 $streamInstance = new NullCryptoStream();
52
53                 // Return the instance
54                 return $streamInstance;
55         }
56
57         /**
58          * Encrypt the string with fixed salt
59          *
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
63          */
64         public function encryptStream ($str, $key = NULL) {
65                 // Just handle it over
66                 $encrypted = (string) $str;
67
68                 // Return it
69                 return $encrypted;
70         }
71
72         /**
73          * Decrypt the string with fixed salt
74          *
75          * @param       $encrypted      Encrypted string
76          * @return      $str            The unencrypted string
77          */
78         public function decryptStream ($encrypted) {
79                 // Just handle it over
80                 $str = (string) $encrypted;
81
82                 // Return it
83                 return $str;
84         }
85
86         /**
87          * Streams the data and maybe does something to it
88          *
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)
92          */
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);
96         }
97
98 }