1 | <?php |
||
42 | class Factory extends \SecurityLib\AbstractFactory |
||
43 | { |
||
44 | |||
45 | /** |
||
46 | * @var array A list of available random number mixing strategies |
||
47 | */ |
||
48 | protected $mixers = array(); |
||
49 | |||
50 | /** |
||
51 | * @var array A list of available random number sources |
||
52 | */ |
||
53 | protected $sources = array(); |
||
54 | |||
55 | /** |
||
56 | * Build a new instance of the factory, loading core mixers and sources |
||
57 | * |
||
58 | * @return void |
||
|
|||
59 | */ |
||
60 | public function __construct() |
||
65 | |||
66 | /** |
||
67 | * Get a generator for the requested strength |
||
68 | * |
||
69 | * @param Strength $strength The requested strength of the random number |
||
70 | * |
||
71 | * @throws RuntimeException If an appropriate mixing strategy isn't found |
||
72 | * |
||
73 | * @return Generator The instantiated generator |
||
74 | */ |
||
75 | public function getGenerator(\SecurityLib\Strength $strength) |
||
82 | |||
83 | /** |
||
84 | * Get a high strength random number generator |
||
85 | * |
||
86 | * High Strength keys should ONLY be used for generating extremely strong |
||
87 | * cryptographic keys. Generating them is very resource intensive and may |
||
88 | * take several minutes or more depending on the requested size. |
||
89 | * |
||
90 | * @return Generator The instantiated generator |
||
91 | */ |
||
92 | public function getHighStrengthGenerator() |
||
96 | |||
97 | /** |
||
98 | * Get a low strength random number generator |
||
99 | * |
||
100 | * Low Strength should be used anywhere that random strings are needed in a |
||
101 | * non-cryptographical setting. They are not strong enough to be used as |
||
102 | * keys or salts. They are however useful for one-time use tokens. |
||
103 | * |
||
104 | * @return Generator The instantiated generator |
||
105 | */ |
||
106 | public function getLowStrengthGenerator() |
||
110 | |||
111 | /** |
||
112 | * Get a medium strength random number generator |
||
113 | * |
||
114 | * Medium Strength should be used for most needs of a cryptographic nature. |
||
115 | * They are strong enough to be used as keys and salts. However, they do |
||
116 | * take some time and resources to generate, so they should not be over-used |
||
117 | * |
||
118 | * @return Generator The instantiated generator |
||
119 | */ |
||
120 | public function getMediumStrengthGenerator() |
||
124 | |||
125 | /** |
||
126 | * Get all loaded mixing strategies |
||
127 | * |
||
128 | * @return array An array of mixers |
||
129 | */ |
||
130 | public function getMixers() |
||
134 | |||
135 | /** |
||
136 | * Get all loaded random number sources |
||
137 | * |
||
138 | * @return array An array of sources |
||
139 | */ |
||
140 | public function getSources() |
||
144 | |||
145 | /** |
||
146 | * Register a mixing strategy for this factory instance |
||
147 | * |
||
148 | * @param string $name The name of the stategy |
||
149 | * @param string $class The class name of the implementation |
||
150 | * |
||
151 | * @return Factory $this The current factory instance |
||
152 | */ |
||
153 | public function registerMixer($name, $class) |
||
164 | |||
165 | /** |
||
166 | * Register a random number source for this factory instance |
||
167 | * |
||
168 | * Note that this class must implement the Source interface |
||
169 | * |
||
170 | * @param string $name The name of the stategy |
||
171 | * @param string $class The class name of the implementation |
||
172 | * |
||
173 | * @return Factory $this The current factory instance |
||
174 | */ |
||
175 | public function registerSource($name, $class) |
||
186 | |||
187 | /** |
||
188 | * Find a sources based upon the requested strength |
||
189 | * |
||
190 | * @param Strength $strength The strength mixer to find |
||
191 | * |
||
192 | * @throws RuntimeException if a valid source cannot be found |
||
193 | * |
||
194 | * @return Source The found source |
||
195 | */ |
||
196 | protected function findSources(\SecurityLib\Strength $strength) |
||
211 | |||
212 | /** |
||
213 | * Find a mixer based upon the requested strength |
||
214 | * |
||
215 | * @param Strength $strength The strength mixer to find |
||
216 | * |
||
217 | * @throws RuntimeException if a valid mixer cannot be found |
||
218 | * |
||
219 | * @return Mixer The found mixer |
||
220 | */ |
||
221 | protected function findMixer(\SecurityLib\Strength $strength) |
||
245 | |||
246 | /** |
||
247 | * Load all core mixing strategies |
||
248 | * |
||
249 | * @return void |
||
250 | */ |
||
251 | protected function loadMixers() |
||
259 | |||
260 | /** |
||
261 | * Load all core random number sources |
||
262 | * |
||
263 | * @return void |
||
264 | */ |
||
265 | protected function loadSources() |
||
273 | } |
||
274 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.