*
* The MIT License (MIT)
*
- * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
+ * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
function random_bytes($bytes)
{
try {
+ /** @var int $bytes */
$bytes = RandomCompat_intval($bytes);
} catch (TypeError $ex) {
throw new TypeError(
* \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be
* generated in one invocation.
*/
+ /** @var string|bool $buf */
if ($bytes > 2147483647) {
$buf = '';
for ($i = 0; $i < $bytes; $i += 1073741824) {
$buf .= \Sodium\randombytes_buf($n);
}
} else {
+ /** @var string|bool $buf */
$buf = \Sodium\randombytes_buf($bytes);
}
- if ($buf !== false) {
+ if (is_string($buf)) {
if (RandomCompat_strlen($buf) === $bytes) {
return $buf;
}