blob: dc66c64ad308fba08c17d3fa660da15647d40ebb [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2
3namespace RobThree\Auth\Providers\Rng;
4
5class OpenSSLRNGProvider implements IRNGProvider
6{
7 private $requirestrong;
8
9 function __construct($requirestrong = true) {
10 $this->requirestrong = $requirestrong;
11 }
12
13 public function getRandomBytes($bytecount) {
14 $result = openssl_random_pseudo_bytes($bytecount, $crypto_strong);
15 if ($this->requirestrong && ($crypto_strong === false))
16 throw new \RNGException('openssl_random_pseudo_bytes returned non-cryptographically strong value');
17 if ($result === false)
18 throw new \RNGException('openssl_random_pseudo_bytes returned an invalid value');
19 return $result;
20 }
21
22 public function isCryptographicallySecure() {
23 return $this->requirestrong;
24 }
25}