pssht  latest
SSH server library written in PHP
Fixed.php
1 <?php
2 
3 /*
4 * This file is part of pssht.
5 *
6 * (c) François Poirotte <clicky@erebot.net>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 
12 namespace fpoirotte\Pssht\Random;
13 
17 class Fixed implements RandomInterface
18 {
20  protected $data;
21 
28  public function __construct($data)
29  {
30  if (!is_string($data) || strlen($data) === 0) {
31  throw new \InvalidArgumentException();
32  }
33 
34  $this->data = $data;
35  }
36 
37  public function getBytes($count)
38  {
39  if (!is_int($count) || $count <= 0) {
40  throw new \InvalidArgumentException();
41  }
42 
43  return substr(
44  str_repeat($this->data, (int) ($count / strlen($this->data) + 1)),
45  0,
46  $count
47  );
48  }
49 }
$data
Fixed data to return.
Definition: Fixed.php:20