| Conditions | 3 |
| Paths | 3 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | public function generateString($length) |
||
| 45 | { |
||
| 46 | $cryptoStrong = false; |
||
| 47 | //Create Binary String |
||
| 48 | $binaryString = openssl_random_pseudo_bytes($length, $cryptoStrong); |
||
| 49 | |||
| 50 | //Unable to create binary string |
||
| 51 | if ($binaryString === false) { |
||
| 52 | throw new DropboxClientException(static::ERROR_MESSAGE . 'openssl_random_pseudo_bytes() returned an unknown error.'); |
||
| 53 | } |
||
| 54 | |||
| 55 | //Binary String is not cryptographically strong |
||
| 56 | if ($cryptoStrong !== true) { |
||
| 57 | throw new DropboxClientException(static::ERROR_MESSAGE . 'openssl_random_pseudo_bytes() returned a pseudo-random string but it was not cryptographically secure and cannot be used.'); |
||
| 58 | } |
||
| 59 | |||
| 60 | //Convert binary to hex |
||
| 61 | return $this->binToHex($binaryString, $length); |
||
| 62 | } |
||
| 63 | } |
||
| 64 |