mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-10 00:42:40 +01:00
[Wilds] Use "random_bytes()" if it is available (after PHP7)
Summary: Ref T13209. In PHP7 and newer, the function `random_bytes()` gives us simple access to cryptographic randomness across platforms. Prefer it if it's available. Notably, the other sources often aren't available on Windows, and particularly aren't available on a clean/default install with modern software versions. So the major motivation is to make things work better out-of-the-box on Windows. Test Plan: On Windows, saw Filesystem unit tests which call `readRandomBytes()` now pass. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13209 Differential Revision: https://secure.phabricator.com/D19726
This commit is contained in:
parent
9ac0b69798
commit
5a4c489916
1 changed files with 8 additions and 3 deletions
|
@ -421,6 +421,12 @@ final class Filesystem extends Phobject {
|
||||||
throw new Exception(pht('You must generate at least 1 byte of entropy.'));
|
throw new Exception(pht('You must generate at least 1 byte of entropy.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Under PHP7, the "random_bytes()" function provides a simpler and more
|
||||||
|
// portable way to accomplish what the rest of this function accomplishes.
|
||||||
|
if (function_exists('random_bytes')) {
|
||||||
|
return random_bytes($number_of_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
// Try to use `openssl_random_pseudo_bytes()` if it's available. This source
|
// Try to use `openssl_random_pseudo_bytes()` if it's available. This source
|
||||||
// is the most widely available source, and works on Windows/Linux/OSX/etc.
|
// is the most widely available source, and works on Windows/Linux/OSX/etc.
|
||||||
|
|
||||||
|
@ -481,9 +487,8 @@ final class Filesystem extends Phobject {
|
||||||
pht(
|
pht(
|
||||||
'%s requires the PHP OpenSSL extension to be installed and enabled '.
|
'%s requires the PHP OpenSSL extension to be installed and enabled '.
|
||||||
'to access an entropy source. On Windows, this extension is usually '.
|
'to access an entropy source. On Windows, this extension is usually '.
|
||||||
'installed but not enabled by default. Enable it in your "s".',
|
'installed but not enabled by default. Enable it in your "php.ini".',
|
||||||
__METHOD__.'()',
|
__METHOD__.'()'));
|
||||||
'php.ini'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
|
Loading…
Reference in a new issue