Updated 'core'.
[hub.git] / application / hub / main / feature / hubcoin_reward / class_HubcoinRewardFeature.php
1 <?php
2 /**
3  * A HubcoinReward Feature class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class HubcoinRewardFeature extends BaseFeature implements Feature {
25         /**
26          * Protected constructor
27          *
28          * @return      void
29          */
30         protected function __construct () {
31                 // Call parent constructor
32                 parent::__construct(__CLASS__);
33         }
34
35         /**
36          * Creates an instance of this Feature class and prepares it for usage
37          *
38          * @return      $featureInstance        An instance of this Feature class
39          */
40         public final static function createHubcoinRewardFeature () {
41                 // Get a new instance
42                 $featureInstance = new HubcoinRewardFeature();
43
44                 // Return the prepared instance
45                 return $featureInstance;
46         }
47
48         /**
49          * Checks whether this feature can be made available to other classes.
50          *
51          * @return      $isAvailable    Whether this feature is available
52          */
53         public function isFeatureAvailable () {
54                 // Debug message
55                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
56
57                 // Testing this feature is pretty simple:
58                 $isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === TRUE) && (extension_loaded('scrypt')) && (is_callable('scrypt')));
59
60                 // Debug message
61                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isAvailable=%d - EXIT!', __METHOD__, __LINE__, intval($isAvailable)));
62
63                 // Return status
64                 return $isAvailable;
65         }
66
67         /**
68          * Feature method 'generateHash'
69          *
70          * @param       $data   Data to hash
71          * @return      $hash   Finished hash
72          */
73         public function featureMethodGenerateHash ($data) {
74                 // Debug message
75                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d - CALLED!', __METHOD__, __LINE__, strlen($data)));
76
77                 // Make sure the feature is available
78                 assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
79
80                 // Call inner class
81                 $hash = Scrypt::hashScrypt($data);
82
83                 // Debug message
84                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: hash=%s - EXIT!', __METHOD__, __LINE__, $hash));
85
86                 // Return generated hash
87                 return $hash;
88         }
89
90         /**
91          * Feature method 'checkHash'
92          *
93          * @param       $data           Data to check hash for
94          * @param       $hash           Previously generated hash for valdiation
95          * @return      $isValid        Whether the given hash matches a new one from given data
96          */
97         public function featureMethodCheckHash ($data, $hash) {
98                 // Debug message
99                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
100
101                 // Make sure the feature is available
102                 assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
103
104                 // Determine it
105                 $isValid = Scrypt::checkScrypt($data, $hash);
106
107                 // Debug message
108                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isValid=%d - EXIT!', __METHOD__, __LINE__, intval($isValid)));
109
110                 // Return status
111                 return $isValid;
112         }
113 }
114
115 // [EOF]
116 ?>