for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Mdanter\Ecc\Random;
use Mdanter\Ecc\Crypto\Key\PrivateKeyInterface;
use Mdanter\Ecc\Math\MathAdapterFactory;
class RandomGeneratorFactory
{
/**
* @param bool $debug
* @return DebugDecorator|RandomNumberGeneratorInterface
*/
public static function getRandomGenerator(bool $debug = false): RandomNumberGeneratorInterface
return self::wrapAdapter(
new RandomNumberGenerator(
MathAdapterFactory::getAdapter($debug)
),
'random_bytes',
$debug
);
}
* @param PrivateKeyInterface $privateKey
* @param \GMP $messageHash
* @param string $algorithm
public static function getHmacRandomGenerator(PrivateKeyInterface $privateKey, \GMP $messageHash, string $algorithm, bool $debug = false): RandomNumberGeneratorInterface
new HmacRandomNumberGenerator(
MathAdapterFactory::getAdapter($debug),
$privateKey,
$messageHash,
$algorithm
'rfc6979',
* @param RandomNumberGeneratorInterface $generator
* @param string $name
private static function wrapAdapter(RandomNumberGeneratorInterface $generator, string $name, bool $debug = false): RandomNumberGeneratorInterface
if ($debug === true) {
return new DebugDecorator($generator, $name);
return $generator;