Total Complexity | 4 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class RandomGeneratorFactory |
||
10 | { |
||
11 | /** |
||
12 | * @param bool $debug |
||
13 | * @return DebugDecorator|RandomNumberGeneratorInterface |
||
14 | */ |
||
15 | public static function getRandomGenerator(bool $debug = false): RandomNumberGeneratorInterface |
||
16 | { |
||
17 | return self::wrapAdapter( |
||
18 | new RandomNumberGenerator( |
||
19 | MathAdapterFactory::getAdapter($debug) |
||
20 | ), |
||
21 | 'random_bytes', |
||
22 | $debug |
||
23 | ); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @param PrivateKeyInterface $privateKey |
||
28 | * @param \GMP $messageHash |
||
29 | * @param string $algorithm |
||
30 | * @param bool $debug |
||
31 | * @return DebugDecorator|RandomNumberGeneratorInterface |
||
32 | */ |
||
33 | public static function getHmacRandomGenerator(PrivateKeyInterface $privateKey, \GMP $messageHash, string $algorithm, bool $debug = false): RandomNumberGeneratorInterface |
||
34 | { |
||
35 | return self::wrapAdapter( |
||
36 | new HmacRandomNumberGenerator( |
||
37 | MathAdapterFactory::getAdapter($debug), |
||
38 | $privateKey, |
||
39 | $messageHash, |
||
40 | $algorithm |
||
41 | ), |
||
42 | 'rfc6979', |
||
43 | $debug |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @param RandomNumberGeneratorInterface $generator |
||
49 | * @param string $name |
||
50 | * @param bool $debug |
||
51 | * @return DebugDecorator|RandomNumberGeneratorInterface |
||
52 | */ |
||
53 | private static function wrapAdapter(RandomNumberGeneratorInterface $generator, string $name, bool $debug = false): RandomNumberGeneratorInterface |
||
60 | } |
||
61 | } |
||
62 |