1 | <?php |
||
30 | class Factory extends \SecurityLib\AbstractFactory { |
||
31 | |||
32 | /** |
||
33 | * @var array A list of available random number mixing strategies |
||
34 | */ |
||
35 | protected $mixers = array(); |
||
36 | |||
37 | /** |
||
38 | * @var array A list of available random number sources |
||
39 | */ |
||
40 | protected $sources = array(); |
||
41 | |||
42 | /** |
||
43 | * Build a new instance of the factory, loading core mixers and sources |
||
44 | * |
||
45 | * @return void |
||
|
|||
46 | */ |
||
47 | public function __construct() { |
||
51 | |||
52 | /** |
||
53 | * Get a generator for the requested strength |
||
54 | * |
||
55 | * @param Strength $strength The requested strength of the random number |
||
56 | * |
||
57 | * @return Generator The instantiated generator |
||
58 | * @throws RuntimeException If an appropriate mixing strategy isn't found |
||
59 | */ |
||
60 | public function getGenerator(\SecurityLib\Strength $strength) { |
||
65 | |||
66 | /** |
||
67 | * Get a high strength random number generator |
||
68 | * |
||
69 | * High Strength keys should ONLY be used for generating extremely strong |
||
70 | * cryptographic keys. Generating them is very resource intensive and may |
||
71 | * take several minutes or more depending on the requested size. |
||
72 | * |
||
73 | * @return Generator The instantiated generator |
||
74 | */ |
||
75 | public function getHighStrengthGenerator() { |
||
78 | |||
79 | /** |
||
80 | * Get a low strength random number generator |
||
81 | * |
||
82 | * Low Strength should be used anywhere that random strings are needed in a |
||
83 | * non-cryptographical setting. They are not strong enough to be used as |
||
84 | * keys or salts. They are however useful for one-time use tokens. |
||
85 | * |
||
86 | * @return Generator The instantiated generator |
||
87 | */ |
||
88 | public function getLowStrengthGenerator() { |
||
91 | |||
92 | /** |
||
93 | * Get a medium strength random number generator |
||
94 | * |
||
95 | * Medium Strength should be used for most needs of a cryptographic nature. |
||
96 | * They are strong enough to be used as keys and salts. However, they do |
||
97 | * take some time and resources to generate, so they should not be over-used |
||
98 | * |
||
99 | * @return Generator The instantiated generator |
||
100 | */ |
||
101 | public function getMediumStrengthGenerator() { |
||
104 | |||
105 | /** |
||
106 | * Get all loaded mixing strategies |
||
107 | * |
||
108 | * @return array An array of mixers |
||
109 | */ |
||
110 | public function getMixers() { |
||
113 | |||
114 | /** |
||
115 | * Get all loaded random number sources |
||
116 | * |
||
117 | * @return array An array of sources |
||
118 | */ |
||
119 | public function getSources() { |
||
122 | |||
123 | /** |
||
124 | * Register a mixing strategy for this factory instance |
||
125 | * |
||
126 | * @param string $name The name of the stategy |
||
127 | * @param string $class The class name of the implementation |
||
128 | * |
||
129 | * @return Factory $this The current factory instance |
||
130 | */ |
||
131 | public function registerMixer($name, $class) { |
||
140 | |||
141 | /** |
||
142 | * Register a random number source for this factory instance |
||
143 | * |
||
144 | * Note that this class must implement the Source interface |
||
145 | * |
||
146 | * @param string $name The name of the stategy |
||
147 | * @param string $class The class name of the implementation |
||
148 | * |
||
149 | * @return Factory $this The current factory instance |
||
150 | */ |
||
151 | public function registerSource($name, $class) { |
||
160 | |||
161 | /** |
||
162 | * Find a sources based upon the requested strength |
||
163 | * |
||
164 | * @param Strength $strength The strength mixer to find |
||
165 | * |
||
166 | * @return Source The found source |
||
167 | * @throws RuntimeException if a valid source cannot be found |
||
168 | */ |
||
169 | protected function findSources(\SecurityLib\Strength $strength) { |
||
183 | |||
184 | /** |
||
185 | * Find a mixer based upon the requested strength |
||
186 | * |
||
187 | * @param Strength $strength The strength mixer to find |
||
188 | * |
||
189 | * @return Mixer The found mixer |
||
190 | * @throws RuntimeException if a valid mixer cannot be found |
||
191 | */ |
||
192 | protected function findMixer(\SecurityLib\Strength $strength) { |
||
210 | |||
211 | /** |
||
212 | * Load all core mixing strategies |
||
213 | * |
||
214 | * @return void |
||
215 | */ |
||
216 | protected function loadMixers() { |
||
223 | |||
224 | /** |
||
225 | * Load all core random number sources |
||
226 | * |
||
227 | * @return void |
||
228 | */ |
||
229 | protected function loadSources() { |
||
236 | |||
237 | } |
||
238 | |||
239 |
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.