AbstractSource.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * PHP version 5.3
  12. *
  13. * @category PHPSecurityLib
  14. * @package Random
  15. *
  16. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  17. * @author Paragon Initiative Enterprises <security@paragonie.com>
  18. * @copyright 2011 The Authors
  19. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  20. *
  21. * @version Build @@version@@
  22. */
  23. namespace RandomLib;
  24. use SecurityLib\Strength;
  25. /**
  26. * An abstract mixer to implement a common mixing strategy
  27. *
  28. * @category PHPSecurityLib
  29. * @package Random
  30. */
  31. abstract class AbstractSource implements \RandomLib\Source
  32. {
  33. /**
  34. * Return an instance of Strength indicating the strength of the source
  35. *
  36. * @return \SecurityLib\Strength An instance of one of the strength classes
  37. */
  38. public static function getStrength()
  39. {
  40. return new Strength(Strength::VERYLOW);
  41. }
  42. /**
  43. * If the source is currently available.
  44. * Reasons might be because the library is not installed
  45. *
  46. * @return bool
  47. */
  48. public static function isSupported()
  49. {
  50. return true;
  51. }
  52. /**
  53. * Returns a string of zeroes, useful when no entropy is available.
  54. *
  55. * @param int $size The size of the requested random string
  56. *
  57. * @return string A string of the requested size
  58. */
  59. protected static function emptyValue($size)
  60. {
  61. return (string) \str_repeat(\chr(0), $size);
  62. }
  63. }