CryptoFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createAES() 0 10 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\Cryptography\Factory;
6
7
use FRZB\Component\Cryptography\Helper\Random;
8
use phpseclib\Crypt\AES;
9
use phpseclib\Crypt\Base as Crypto;
10
11
class CryptoFactory implements CryptoFactoryInterface
12
{
13
    private const DEFAULT_LENGTH = 128;
14
15 11
    public function __construct(
16
        private readonly Random $randomCrypto,
17
    ) {
18 11
    }
19
20 11
    public function createAES(?string $iv = null, ?string $key = null): Crypto
21
    {
22 11
        $iv ??= $this->randomCrypto->secureString(self::DEFAULT_LENGTH);
23 11
        $key ??= $this->randomCrypto->secureString(self::DEFAULT_LENGTH);
24
25 11
        $crypto = new AES(Crypto::MODE_CBC);
26 11
        $crypto->setIV($iv);
27 11
        $crypto->setKey($key);
28
29 11
        return $crypto;
30
    }
31
}
32