]> git.mxchange.org Git - core.git/blob - framework/main/classes/streams/crypto/null/class_NullCryptoStream.php
Continued:
[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            Ignored
62          * @return      $encrypted      Encrypted string
63          */
64         public function encryptStream (string $str, string $key = NULL) {
65                 // Return it
66                 return $str;
67         }
68
69         /**
70          * Decrypt the string with fixed salt
71          *
72          * @param       $encrypted      Encrypted string
73          * @param       $key            Ignored
74          * @return      $str            The unencrypted string
75          */
76         public function decryptStream (string $encrypted, string $key = NULL) {
77                 // Return it
78                 return $encrypted;
79         }
80
81         /**
82          * Streams the data and maybe does something to it
83          *
84          * @param       $data   The data (string mostly) to "stream"
85          * @return      $data   The data (string mostly) to "stream"
86          * @throws      UnsupportedOperationException   If this method is called (which is a mistake)
87          */
88         public function streamData (string $data) {
89                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
90                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
91         }
92
93 }