OpenSSL   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 18
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isSupported() 0 4 1
A readBytes() 0 10 2
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