Skip to content

Commit

Permalink
Fix stubs. Remove UndefinedClass suppression.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Feb 3, 2017
1 parent cfa429f commit 1e71c3e
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 45 deletions.
5 changes: 5 additions & 0 deletions lib/random_bytes_com_dotnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ function random_bytes($bytes)
}

$buf = '';
if (!class_exists('COM')) {
throw new Error(
'COM does not exist'
);
}
$util = new COM('CAPICOM.Utilities.1');
$execCount = 0;

Expand Down
2 changes: 1 addition & 1 deletion lib/random_bytes_libsodium_legacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function random_bytes($bytes)
$buf = Sodium::randombytes_buf($bytes);
}

if ($buf !== false) {
if (is_string($buf)) {
if (RandomCompat_strlen($buf) === $bytes) {
return $buf;
}
Expand Down
8 changes: 1 addition & 7 deletions other/ide_stubs/COM.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ class COM
*/
public function GetRandom($bytes, $dummy)
{
static $fp = null;
if (!$fp) {
$fp = fopen('/dev/urandom', 'rb');
}
return fread($fp, $bytes);
return '';
}
}

throw new Exception('Attempting to include IDE stub files in a project.');
2 changes: 2 additions & 0 deletions other/ide_stubs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

These exist to reduce false positive errors on PHPStorm and other IDEs.

They also exist so Psalm has some idea what's going on.

Don't use them in your project.
2 changes: 0 additions & 2 deletions other/ide_stubs/com_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ class com_exception extends Exception
{

}

throw new Exception('Attempting to include IDE stub files in a project.');
112 changes: 78 additions & 34 deletions other/ide_stubs/libsodium.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,90 @@
<?php
namespace Sodium;

/**
* This does nothing if the libsodium extension is loaded, so it's harmless.
*
* This file alone is released under CC0 and WTFPL dual licensing.
*/
if (!extension_loaded('libsodium')) {
namespace Sodium {
if (!extension_loaded('libsodium')) {

/**
* Generate a string of random bytes
* /dev/urandom
*
* @param int $length
* @return string
*/
function randombytes_buf(
$length
) {
return '';
}
/**
* Generate a string of random bytes
* /dev/urandom
*
* @param int $length
* @return string
*/
function randombytes_buf(
$length
)
{
return '';
}

/**
* Generate a 16-bit integer
* /dev/urandom
*
* @return int
*/
function randombytes_random16() {
return '';
}
/**
* Generate a 16-bit integer
* /dev/urandom
*
* @return int
*/
function randombytes_random16()
{
return '';
}

/**
* Generate an unbiased random integer between 0 and a specified value
* /dev/urandom
*
* @param int $upperBoundNonInclusive
* @return int
*/
function randombytes_uniform(
$upperBoundNonInclusive
) {
return 0;
/**
* Generate an unbiased random integer between 0 and a specified value
* /dev/urandom
*
* @param int $upperBoundNonInclusive
* @return int
*/
function randombytes_uniform(
$upperBoundNonInclusive
)
{
return 0;
}
}
}
namespace {
class Sodium
{

/**
* Generate a string of random bytes
* /dev/urandom
*
* @param int $length
* @return string
*/
public static function randombytes_buf($length)
{
return '';
}

/**
* Generate a 16-bit integer
* /dev/urandom
*
* @return int
*/
public static function randombytes_random16()
{
return '';
}

/**
* Generate an unbiased random integer between 0 and a specified value
* /dev/urandom
*
* @param int $upperBoundNonInclusive
* @return int
*/
public static function randombytes_uniform($upperBoundNonInclusive = 0)
{
return 0;
}
}
}
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</projectFiles>
<issueHandlers>
<DuplicateClass errorLevel="info" />
<UndefinedClass errorLevel="info" />
<FailedTypeResolution errorLevel="info" />
<InvalidArgument errorLevel="info" />
<InvalidOperand errorLevel="info" />
Expand Down

0 comments on commit 1e71c3e

Please sign in to comment.