Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
6 / 6 |
DefaultAlgorithm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
6 / 6 |
generate | |
100.00% |
1 / 1 |
4 | |
100.00% |
6 / 6 |
<?php | |
/** | |
* OAuth 2.0 Secure key interface | |
* | |
* @package league/oauth2-server | |
* @author Alex Bilbie <hello@alexbilbie.com> | |
* @copyright Copyright (c) Alex Bilbie | |
* @license http://mit-license.org/ | |
* @link https://github.com/thephpleague/oauth2-server | |
*/ | |
namespace League\OAuth2\Server\Util\KeyAlgorithm; | |
class DefaultAlgorithm implements KeyAlgorithmInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function generate($len = 40) | |
{ | |
$stripped = ''; | |
do { | |
$bytes = openssl_random_pseudo_bytes($len, $strong); | |
// We want to stop execution if the key fails because, well, that is bad. | |
if ($bytes === false || $strong === false) { | |
// @codeCoverageIgnoreStart | |
throw new \Exception('Error Generating Key'); | |
// @codeCoverageIgnoreEnd | |
} | |
$stripped .= str_replace(['/', '+', '='], '', base64_encode($bytes)); | |
} while (strlen($stripped) < $len); | |
return substr($stripped, 0, $len); | |
} | |
} |