Completed
Pull Request — master (#2)
by Milos
04:36
created

OpenSslRandomGenerator::get()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
cc 3
eloc 5
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the tmilos/jose-jwt package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tmilos\JoseJwt\Random;
13
14
use Tmilos\JoseJwt\Error\JoseJwtException;
15
16
class OpenSslRandomGenerator implements RandomGenerator
17
{
18
    /**
19
     * @param int $bytesLength
20
     *
21
     * @return string
22
     */
23
    public function get($bytesLength)
24
    {
25
        $result = openssl_random_pseudo_bytes($bytesLength, $strong);
26
        if (false === $result || false === $strong) {
27
            throw new JoseJwtException('Unable to generate strong random sequence');
28
        }
29
30
        return $result;
31
    }
32
}
33