Changeset 114557 in spip-zone


Ignore:
Timestamp:
Mar 18, 2019, 9:10:52 AM (5 months ago)
Author:
bystrano@…
Message:

mise à jour du polyfill de random_bytes pour PHP<7

On utilise composer pour récupérer le code. Du coup pour les prochaines maj il
suffira de faire "composer update".

Location:
_plugins_/incarner/trunk
Files:
17 added
4 deleted
3 edited
1 copied
14 moved

Legend:

Unmodified
Added
Removed
  • _plugins_/incarner/trunk/incarner_fonctions.php

    r113724 r114557  
    6060        }
    6161
    62         // Support de la fonction random_bytes pour PHP < 7.0
    63         include_spip('lib/random_compat-2.0.10/lib/random');
    64 
    6562        $nouvelle_cle = urlencode(bin2hex(random_bytes(16)));
    6663
  • _plugins_/incarner/trunk/incarner_options.php

    r98773 r114557  
    1010 */
    1111
     12require __DIR__ . '/vendor/autoload.php';
     13
    1214$GLOBALS['liste_des_authentifications']['incarner'] = 'incarner';
    1315
  • _plugins_/incarner/trunk/paquet.xml

    r114556 r114557  
    22        prefix="incarner"
    33        categorie="outil"
    4         version="1.3.5"
     4        version="1.3.6"
    55        etat="stable"
    66        compatibilite="[3.0.11;3.2.*]"
  • _plugins_/incarner/trunk/vendor/composer/LICENSE

    r114556 r114557  
    1 The MIT License (MIT)
    21
    3 Copyright (c) 2015 Paragon Initiative Enterprises
     2Copyright (c) Nils Adermann, Jordi Boggiano
    43
    54Permission is hereby granted, free of charge, to any person obtaining a copy
     
    76in the Software without restriction, including without limitation the rights
    87to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    9 copies of the Software, and to permit persons to whom the Software is
    10 furnished to do so, subject to the following conditions:
     8copies of the Software, and to permit persons to whom the Software is furnished
     9to do so, subject to the following conditions:
    1110
    1211The above copyright notice and this permission notice shall be included in all
     
    1817AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    1918LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    21 SOFTWARE.
     19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     20THE SOFTWARE.
    2221
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/composer.json

    r114556 r114557  
    55    "csprng",
    66    "random",
     7    "polyfill",
    78    "pseudorandom"
    89  ],
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/byte_safe_strings.php

    r114556 r114557  
    66 * The MIT License (MIT)
    77 *
    8  * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
     8 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
    99 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    2929if (!is_callable('RandomCompat_strlen')) {
    3030    if (
    31         defined('MB_OVERLOAD_STRING') &&
    32         ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING
     31        defined('MB_OVERLOAD_STRING')
     32            &&
     33        ((int) ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING
    3334    ) {
    3435        /**
     
    8384    if (
    8485        defined('MB_OVERLOAD_STRING')
    85         &&
    86         ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING
     86            &&
     87        ((int) ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING
    8788    ) {
    8889        /**
     
    9495         * @param string $binary_string
    9596         * @param int $start
    96          * @param int $length (optional)
     97         * @param int|null $length (optional)
    9798         *
    9899         * @throws TypeError
     
    119120                 * PHP 5.3, so we have to find the length ourselves.
    120121                 */
     122                /** @var int $length */
    121123                $length = RandomCompat_strlen($binary_string) - $start;
    122124            } elseif (!is_int($length)) {
     
    134136            }
    135137
    136             return (string) mb_substr($binary_string, $start, $length, '8bit');
     138            return (string) mb_substr(
     139                (string) $binary_string,
     140                (int) $start,
     141                (int) $length,
     142                '8bit'
     143            );
    137144        }
    138145
     
    146153         * @param string $binary_string
    147154         * @param int $start
    148          * @param int $length (optional)
     155         * @param int|null $length (optional)
    149156         *
    150157         * @throws TypeError
     
    173180                }
    174181
    175                 return (string) substr($binary_string, $start, $length);
     182                return (string) substr(
     183                    (string )$binary_string,
     184                    (int) $start,
     185                    (int) $length
     186                );
    176187            }
    177188
    178             return (string) substr($binary_string, $start);
     189            return (string) substr(
     190                (string) $binary_string,
     191                (int) $start
     192            );
    179193        }
    180194    }
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/cast_to_int.php

    r114556 r114557  
    66 * The MIT License (MIT)
    77 *
    8  * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
     8 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
    99 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    2828
    2929if (!is_callable('RandomCompat_intval')) {
    30    
     30
    3131    /**
    3232     * Cast to an integer if we can, safely.
    33      * 
     33     *
    3434     * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX)
    3535     * (non-inclusive), it will sanely cast it to an int. If you it's equal to
     
    3737     * lose precision, so the <= and => operators might accidentally let a float
    3838     * through.
    39      * 
     39     *
    4040     * @param int|float $number    The number we want to convert to an int
    41      * @param boolean   $fail_open Set to true to not throw an exception
    42      * 
     41     * @param bool      $fail_open Set to true to not throw an exception
     42     *
    4343     * @return float|int
     44     * @psalm-suppress InvalidReturnType
    4445     *
    4546     * @throws TypeError
     
    5051            $number += 0;
    5152        } elseif (is_numeric($number)) {
     53            /** @psalm-suppress InvalidOperand */
    5254            $number += 0;
    5355        }
     56        /** @var int|float $number */
    5457
    5558        if (
    5659            is_float($number)
    57             &&
     60                &&
    5861            $number > ~PHP_INT_MAX
    59             &&
     62                &&
    6063            $number < PHP_INT_MAX
    6164        ) {
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/error_polyfill.php

    r114556 r114557  
    11<?php
    22/**
    3  * Random_* Compatibility Library 
     3 * Random_* Compatibility Library
    44 * for using the new PHP 7 random_* API in PHP 5 projects
    5  * 
     5 *
    66 * The MIT License (MIT)
    77 *
    8  * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
    9  * 
     8 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
     9 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
    1111 * of this software and associated documentation files (the "Software"), to deal
     
    3131    class Error extends Exception
    3232    {
    33        
     33
    3434    }
    3535}
     
    3939        class TypeError extends Error
    4040        {
    41            
     41
    4242        }
    4343    } else {
    4444        class TypeError extends Exception
    4545        {
    46            
     46
    4747        }
    4848    }
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/random.php

    r114556 r114557  
    44 * for using the new PHP 7 random_* API in PHP 5 projects
    55 *
    6  * @version 2.0.10
    7  * @released 2017-03-13
     6 * @version 2.0.17
     7 * @released 2018-07-04
    88 *
    99 * The MIT License (MIT)
    1010 *
    11  * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
     11 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
    1212 *
    1313 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    5555$RandomCompatDIR = dirname(__FILE__);
    5656
    57 require_once $RandomCompatDIR . '/byte_safe_strings.php';
    58 require_once $RandomCompatDIR . '/cast_to_int.php';
    59 require_once $RandomCompatDIR . '/error_polyfill.php';
     57require_once $RandomCompatDIR . DIRECTORY_SEPARATOR . 'byte_safe_strings.php';
     58require_once $RandomCompatDIR . DIRECTORY_SEPARATOR . 'cast_to_int.php';
     59require_once $RandomCompatDIR . DIRECTORY_SEPARATOR . 'error_polyfill.php';
    6060
    6161if (!is_callable('random_bytes')) {
     
    7777        // See random_bytes_libsodium.php
    7878        if (PHP_VERSION_ID >= 50300 && is_callable('\\Sodium\\randombytes_buf')) {
    79             require_once $RandomCompatDIR . '/random_bytes_libsodium.php';
     79            require_once $RandomCompatDIR . DIRECTORY_SEPARATOR . 'random_bytes_libsodium.php';
    8080        } elseif (method_exists('Sodium', 'randombytes_buf')) {
    81             require_once $RandomCompatDIR . '/random_bytes_libsodium_legacy.php';
     81            require_once $RandomCompatDIR . DIRECTORY_SEPARATOR . 'random_bytes_libsodium_legacy.php';
    8282        }
    8383    }
     
    118118
    119119            // See random_bytes_dev_urandom.php
    120             require_once $RandomCompatDIR . '/random_bytes_dev_urandom.php';
     120            require_once $RandomCompatDIR . DIRECTORY_SEPARATOR . 'random_bytes_dev_urandom.php';
    121121        }
    122122        // Unset variables after use
     
    160160    ) {
    161161        // See random_bytes_mcrypt.php
    162         require_once $RandomCompatDIR . '/random_bytes_mcrypt.php';
     162        require_once $RandomCompatDIR . DIRECTORY_SEPARATOR . 'random_bytes_mcrypt.php';
    163163    }
    164164    $RandomCompatUrandom = null;
     
    185185                if (method_exists($RandomCompatCOMtest, 'GetRandom')) {
    186186                    // See random_bytes_com_dotnet.php
    187                     require_once $RandomCompatDIR . '/random_bytes_com_dotnet.php';
     187                    require_once $RandomCompatDIR . DIRECTORY_SEPARATOR . 'random_bytes_com_dotnet.php';
    188188                }
    189189            } catch (com_exception $e) {
     
    204204         *
    205205         * @param mixed $length
    206          * @return void
     206         * @psalm-suppress InvalidReturnType
    207207         * @throws Exception
     208         * @return string
    208209         */
    209210        function random_bytes($length)
     
    213214                'There is no suitable CSPRNG installed on your system'
    214215            );
     216            return '';
    215217        }
    216218    }
     
    218220
    219221if (!is_callable('random_int')) {
    220     require_once $RandomCompatDIR . '/random_int.php';
     222    require_once $RandomCompatDIR . DIRECTORY_SEPARATOR . 'random_int.php';
    221223}
    222224
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/random_bytes_com_dotnet.php

    r114556 r114557  
    11<?php
    22/**
    3  * Random_* Compatibility Library 
     3 * Random_* Compatibility Library
    44 * for using the new PHP 7 random_* API in PHP 5 projects
    5  * 
     5 *
    66 * The MIT License (MIT)
    7  * 
    8  * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
    9  * 
     7 *
     8 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
     9 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
    1111 * of this software and associated documentation files (the "Software"), to deal
     
    1414 * copies of the Software, and to permit persons to whom the Software is
    1515 * furnished to do so, subject to the following conditions:
    16  * 
     16 *
    1717 * The above copyright notice and this permission notice shall be included in
    1818 * all copies or substantial portions of the Software.
    19  * 
     19 *
    2020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    2121 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     
    4242    {
    4343        try {
     44            /** @var int $bytes */
    4445            $bytes = RandomCompat_intval($bytes);
    4546        } catch (TypeError $ex) {
     
    5556        }
    5657
     58        /** @var string $buf */
    5759        $buf = '';
    5860        if (!class_exists('COM')) {
     
    6163            );
    6264        }
     65        /** @var COM $util */
    6366        $util = new COM('CAPICOM.Utilities.1');
    6467        $execCount = 0;
     
    6972         */
    7073        do {
    71             $buf .= base64_decode($util->GetRandom($bytes, 0));
     74            $buf .= base64_decode((string) $util->GetRandom($bytes, 0));
    7275            if (RandomCompat_strlen($buf) >= $bytes) {
    7376                /**
    7477                 * Return our random entropy buffer here:
    7578                 */
    76                 return RandomCompat_substr($buf, 0, $bytes);
     79                return (string) RandomCompat_substr($buf, 0, $bytes);
    7780            }
    7881            ++$execCount;
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/random_bytes_dev_urandom.php

    r114556 r114557  
    11<?php
    22/**
    3  * Random_* Compatibility Library 
     3 * Random_* Compatibility Library
    44 * for using the new PHP 7 random_* API in PHP 5 projects
    5  * 
     5 *
    66 * The MIT License (MIT)
    77 *
    8  * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
    9  * 
     8 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
     9 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
    1111 * of this software and associated documentation files (the "Software"), to deal
     
    1414 * copies of the Software, and to permit persons to whom the Software is
    1515 * furnished to do so, subject to the following conditions:
    16  * 
     16 *
    1717 * The above copyright notice and this permission notice shall be included in
    1818 * all copies or substantial portions of the Software.
    19  * 
     19 *
    2020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    2121 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     
    3737     *
    3838     * Why we use /dev/urandom and not /dev/random
     39     * @ref https://www.2uo.de/myths-about-urandom
    3940     * @ref http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers
    4041     *
     
    4748    function random_bytes($bytes)
    4849    {
     50        /** @var resource $fp */
    4951        static $fp = null;
     52
    5053        /**
    5154         * This block should only be run once
     
    5356        if (empty($fp)) {
    5457            /**
    55              * We use /dev/urandom if it is a char device.
    56              * We never fall back to /dev/random
     58             * We don't want to ever read C:\dev\random, only /dev/urandom on
     59             * Unix-like operating systems. While we guard against this
     60             * condition in random.php, it doesn't hurt to be defensive in depth
     61             * here.
     62             *
     63             * To that end, we only try to open /dev/urandom if we're on a Unix-
     64             * like operating system (which means the directory separator is set
     65             * to "/" not "\".
    5766             */
    58             $fp = fopen('/dev/urandom', 'rb');
    59             if (!empty($fp)) {
    60                 $st = fstat($fp);
    61                 if (($st['mode'] & 0170000) !== 020000) {
    62                     fclose($fp);
    63                     $fp = false;
     67            if (DIRECTORY_SEPARATOR === '/') {
     68                if (!is_readable('/dev/urandom')) {
     69                    throw new Exception(
     70                        'Environment misconfiguration: ' .
     71                        '/dev/urandom cannot be read.'
     72                    );
     73                }
     74                /**
     75                 * We use /dev/urandom if it is a char device.
     76                 * We never fall back to /dev/random
     77                 */
     78                /** @var resource|bool $fp */
     79                $fp = fopen('/dev/urandom', 'rb');
     80                if (is_resource($fp)) {
     81                    /** @var array<string, int> $st */
     82                    $st = fstat($fp);
     83                    if (($st['mode'] & 0170000) !== 020000) {
     84                        fclose($fp);
     85                        $fp = false;
     86                    }
    6487                }
    6588            }
    6689
    67             if (!empty($fp)) {
     90            if (is_resource($fp)) {
    6891                /**
    6992                 * stream_set_read_buffer() does not exist in HHVM
     
    84107
    85108        try {
     109            /** @var int $bytes */
    86110            $bytes = RandomCompat_intval($bytes);
    87111        } catch (TypeError $ex) {
     
    104128         * page load.
    105129         */
    106         if (!empty($fp)) {
     130        if (is_resource($fp)) {
    107131            /**
    108132             * @var int
     
    124148                $read = fread($fp, $remaining);
    125149                if (!is_string($read)) {
    126                     if ($read === false) {
    127                         /**
    128                          * We cannot safely read from the file. Exit the
    129                          * do-while loop and trigger the exception condition
    130                          *
    131                          * @var string|bool
    132                          */
    133                         $buf = false;
    134                         break;
    135                     }
     150                    /**
     151                     * We cannot safely read from the file. Exit the
     152                     * do-while loop and trigger the exception condition
     153                     *
     154                     * @var string|bool
     155                     */
     156                    $buf = false;
     157                    break;
    136158                }
    137159                /**
     
    140162                $remaining -= RandomCompat_strlen($read);
    141163                /**
    142                  * @var string|bool
     164                 * @var string $buf
    143165                 */
    144                 $buf = $buf . $read;
     166                $buf .= $read;
    145167            } while ($remaining > 0);
    146168
    147169            /**
    148170             * Is our result valid?
     171             * @var string|bool $buf
    149172             */
    150173            if (is_string($buf)) {
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/random_bytes_libsodium.php

    r114556 r114557  
    11<?php
    22/**
    3  * Random_* Compatibility Library 
     3 * Random_* Compatibility Library
    44 * for using the new PHP 7 random_* API in PHP 5 projects
    5  * 
     5 *
    66 * The MIT License (MIT)
    77 *
    8  * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
    9  * 
     8 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
     9 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
    1111 * of this software and associated documentation files (the "Software"), to deal
     
    1414 * copies of the Software, and to permit persons to whom the Software is
    1515 * furnished to do so, subject to the following conditions:
    16  * 
     16 *
    1717 * The above copyright notice and this permission notice shall be included in
    1818 * all copies or substantial portions of the Software.
    19  * 
     19 *
    2020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    2121 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     
    4444    {
    4545        try {
     46            /** @var int $bytes */
    4647            $bytes = RandomCompat_intval($bytes);
    4748        } catch (TypeError $ex) {
     
    6162         * generated in one invocation.
    6263         */
     64        /** @var string|bool $buf */
    6365        if ($bytes > 2147483647) {
    6466            $buf = '';
     
    7072            }
    7173        } else {
     74            /** @var string|bool $buf */
    7275            $buf = \Sodium\randombytes_buf($bytes);
    7376        }
    7477
    75         if ($buf !== false) {
     78        if (is_string($buf)) {
    7679            if (RandomCompat_strlen($buf) === $bytes) {
    7780                return $buf;
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/random_bytes_libsodium_legacy.php

    r114556 r114557  
    11<?php
    22/**
    3  * Random_* Compatibility Library 
     3 * Random_* Compatibility Library
    44 * for using the new PHP 7 random_* API in PHP 5 projects
    5  * 
     5 *
    66 * The MIT License (MIT)
    77 *
    8  * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
    9  * 
     8 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
     9 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
    1111 * of this software and associated documentation files (the "Software"), to deal
     
    1414 * copies of the Software, and to permit persons to whom the Software is
    1515 * furnished to do so, subject to the following conditions:
    16  * 
     16 *
    1717 * The above copyright notice and this permission notice shall be included in
    1818 * all copies or substantial portions of the Software.
    19  * 
     19 *
    2020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    2121 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     
    4444    {
    4545        try {
     46            /** @var int $bytes */
    4647            $bytes = RandomCompat_intval($bytes);
    4748        } catch (TypeError $ex) {
     
    7172                    ? 1073741824
    7273                    : $bytes - $i;
    73                 $buf .= Sodium::randombytes_buf($n);
     74                $buf .= Sodium::randombytes_buf((int) $n);
    7475            }
    7576        } else {
    76             $buf .= Sodium::randombytes_buf($bytes);
     77            $buf .= Sodium::randombytes_buf((int) $bytes);
    7778        }
    7879
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/random_bytes_mcrypt.php

    r114556 r114557  
    11<?php
    22/**
    3  * Random_* Compatibility Library 
     3 * Random_* Compatibility Library
    44 * for using the new PHP 7 random_* API in PHP 5 projects
    5  * 
     5 *
    66 * The MIT License (MIT)
    77 *
    8  * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
    9  * 
     8 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
     9 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
    1111 * of this software and associated documentation files (the "Software"), to deal
     
    1414 * copies of the Software, and to permit persons to whom the Software is
    1515 * furnished to do so, subject to the following conditions:
    16  * 
     16 *
    1717 * The above copyright notice and this permission notice shall be included in
    1818 * all copies or substantial portions of the Software.
    19  * 
     19 *
    2020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    2121 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     
    4343    {
    4444        try {
     45            /** @var int $bytes */
    4546            $bytes = RandomCompat_intval($bytes);
    4647        } catch (TypeError $ex) {
     
    5657        }
    5758
    58         $buf = @mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
     59        /** @var string|bool $buf */
     60        $buf = @mcrypt_create_iv((int) $bytes, (int) MCRYPT_DEV_URANDOM);
    5961        if (
    60             $buf !== false
    61             &&
     62            is_string($buf)
     63                &&
    6264            RandomCompat_strlen($buf) === $bytes
    6365        ) {
  • _plugins_/incarner/trunk/vendor/paragonie/random_compat/lib/random_int.php

    r114556 r114557  
    88     * The MIT License (MIT)
    99     *
    10      * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
     10     * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
    1111     *
    1212     * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    5252
    5353        try {
     54            /** @var int $min */
    5455            $min = RandomCompat_intval($min);
    5556        } catch (TypeError $ex) {
     
    6061
    6162        try {
     63            /** @var int $max */
    6264            $max = RandomCompat_intval($max);
    6365        } catch (TypeError $ex) {
     
    7981
    8082        if ($max === $min) {
    81             return $min;
     83            return (int) $min;
    8284        }
    8385
     
    9193         */
    9294        $attempts = $bits = $bytes = $mask = $valueShift = 0;
     95        /** @var int $attempts */
     96        /** @var int $bits */
     97        /** @var int $bytes */
     98        /** @var int $mask */
     99        /** @var int $valueShift */
    93100
    94101        /**
     
    96103         * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to
    97104         * a float and we will lose some precision.
     105         *
     106         * @var int|float $range
    98107         */
    99108        $range = $max - $min;
     
    116125             */
    117126            $bytes = PHP_INT_SIZE;
     127            /** @var int $mask */
    118128            $mask = ~0;
    119129
     
    130140                ++$bits;
    131141                $range >>= 1;
     142                /** @var int $mask */
    132143                $mask = $mask << 1 | 1;
    133144            }
     
    135146        }
    136147
     148        /** @var int $val */
    137149        $val = 0;
    138150        /**
     
    140152         * random integers until one falls between $min and $max
    141153         */
     154        /** @psalm-suppress RedundantCondition */
    142155        do {
    143156            /**
     
    170183                $val |= ord($randomByteString[$i]) << ($i * 8);
    171184            }
     185            /** @var int $val */
    172186
    173187            /**
     
    186200        } while (!is_int($val) || $val > $max || $val < $min);
    187201
    188         return (int)$val;
     202        return (int) $val;
    189203    }
    190204}
Note: See TracChangeset for help on using the changeset viewer.