Skip to content

Commit

Permalink
Add libsodium stub for randombytes
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Feb 3, 2017
1 parent 191b04a commit cfa429f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions other/ide_stubs/libsodium.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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')) {

/**
* 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 an unbiased random integer between 0 and a specified value
* /dev/urandom
*
* @param int $upperBoundNonInclusive
* @return int
*/
function randombytes_uniform(
$upperBoundNonInclusive
) {
return 0;
}
}
1 change: 1 addition & 0 deletions psalm-autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_once 'lib/byte_safe_strings.php';
require_once 'lib/cast_to_int.php';
require_once 'lib/error_polyfill.php';
require_once 'other/ide_stubs/libsodium.php';
require_once 'lib/random.php';

$int = random_int(0, 65536);

0 comments on commit cfa429f

Please sign in to comment.