|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* The Random Number Source interface. |
|
4
|
|
|
* |
|
5
|
|
|
* All random number sources must implement this interface |
|
6
|
|
|
* |
|
7
|
|
|
* PHP version 5.3 |
|
8
|
|
|
* |
|
9
|
|
|
* @category PHPPasswordLib |
|
10
|
|
|
* @package Random |
|
11
|
|
|
* @author Anthony Ferrara <[email protected]> |
|
12
|
|
|
* @copyright 2011 The Authors |
|
13
|
|
|
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
|
14
|
|
|
* @license http://www.gnu.org/licenses/lgpl-2.1.html LGPL v 2.1 |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace RandomLibTest\Mocks\Random; |
|
18
|
|
|
|
|
19
|
|
|
use SecurityLib\Strength; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The Random Number Source interface. |
|
23
|
|
|
* |
|
24
|
|
|
* All random number sources must implement this interface |
|
25
|
|
|
* |
|
26
|
|
|
* @category PHPPasswordLib |
|
27
|
|
|
* @package Random |
|
28
|
|
|
* @author Anthony Ferrara <[email protected]> |
|
29
|
|
|
*/ |
|
30
|
|
|
class Source extends \RandomLibTest\Mocks\AbstractMock implements \RandomLib\Source { |
|
31
|
|
|
|
|
32
|
|
|
public static $strength = null; |
|
33
|
|
|
|
|
34
|
|
|
public static function init() { |
|
35
|
|
|
static::$strength = new Strength(Strength::VERYLOW); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Return an instance of Strength indicating the strength of the source |
|
40
|
|
|
* |
|
41
|
|
|
* @return Strength An instance of one of the strength classes |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function getStrength() { |
|
44
|
|
|
return static::$strength; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Generate a random string of the specified size |
|
50
|
|
|
* |
|
51
|
|
|
* Note: If the source fails to generate enough data, the result must be |
|
52
|
|
|
* padded to the requested length. |
|
53
|
|
|
* |
|
54
|
|
|
* @param int $size The size of the requested random string |
|
55
|
|
|
* |
|
56
|
|
|
* @return string A string of the requested size |
|
57
|
|
|
*/ |
|
58
|
|
|
public function generate($size) { |
|
59
|
|
|
return $this->__call('generate', array($size)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
|