| Total Complexity | 7 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class Padding |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Padding blocksize. |
||
| 16 | * |
||
| 17 | * @var int |
||
| 18 | */ |
||
| 19 | protected $_blocksize; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Constructor. |
||
| 23 | * |
||
| 24 | * @param int $blocksize Blocksize |
||
| 25 | */ |
||
| 26 | 17 | public function __construct(int $blocksize = 8) |
|
| 29 | 17 | } |
|
| 30 | |||
| 31 | /** |
||
| 32 | * Add padding. |
||
| 33 | * |
||
| 34 | * @param string $data |
||
| 35 | * |
||
| 36 | * @return string Data padded to blocksize |
||
| 37 | */ |
||
| 38 | 11 | public function add(string $data): string |
|
| 39 | { |
||
| 40 | 11 | $n = $this->_blocksize - strlen($data) % $this->_blocksize; |
|
| 41 | 11 | return $data . str_repeat(chr($n), $n); |
|
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Remove padding. |
||
| 46 | * |
||
| 47 | * @param string $data |
||
| 48 | * |
||
| 49 | * @throws \UnexpectedValueException |
||
| 50 | * |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | 15 | public function remove(string $data): string |
|
| 68 | } |
||
| 69 | } |
||
| 70 |