Source.php 2.1 KB

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