OpenSSL::isSupported()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Riimu\Kit\SecureRandom\Generator;
4
5
use Riimu\Kit\SecureRandom\GeneratorException;
6
7
/**
8
 * Generates bytes using OpenSSL extension.
9
 *
10
 * OpenSSL generator uses openssl_random_pseudo_bytes to generate bytes. Note
11
 * that whether bytes generated by this function are secure or not is up to
12
 * debate.
13
 *
14
 * @author Riikka Kalliomäki <[email protected]>
15
 * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki
16
 * @license http://opensource.org/licenses/mit-license.php MIT License
17
 */
18
class OpenSSL extends AbstractGenerator
19
{
20 6
    public function isSupported()
21
    {
22 6
        return function_exists('openssl_random_pseudo_bytes');
23
    }
24
25 6
    protected function readBytes($count)
26
    {
27 6
        $bytes = openssl_random_pseudo_bytes($count, $strong);
28
29 6
        if ($strong !== true) {
30 3
            throw new GeneratorException('OpenSSL failed to generate strong bytes');
31
        }
32
33 3
        return $bytes;
34
    }
35
}
36