WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/08/2017 11:47:04 AM (4 years ago)
Author:
dd32
Message:

External Libraries: Update Random_Compat from 1.2.1 to 2.0.11.

Notably this fixes PHP7 parse errors of the files and removes the OpenSSL functionality.
Full Changes: https://github.com/paragonie/random_compat/compare/v1.2.1...v2.0.11

Props jrdelarosa.
See #42439.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/random_compat/random_bytes_mcrypt.php

    r36886 r42130  
    55 *
    66 * The MIT License (MIT)
    7  * 
    8  * Copyright (c) 2015 Paragon Initiative Enterprises
     7 *
     8 * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
    99 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    2727 */
    2828
     29if (!is_callable('random_bytes')) {
     30    /**
     31     * Powered by ext/mcrypt (and thankfully NOT libmcrypt)
     32     *
     33     * @ref https://bugs.php.net/bug.php?id=55169
     34     * @ref https://github.com/php/php-src/blob/c568ffe5171d942161fc8dda066bce844bdef676/ext/mcrypt/mcrypt.c#L1321-L1386
     35     *
     36     * @param int $bytes
     37     *
     38     * @throws Exception
     39     *
     40     * @return string
     41     */
     42    function random_bytes($bytes)
     43    {
     44        try {
     45            $bytes = RandomCompat_intval($bytes);
     46        } catch (TypeError $ex) {
     47            throw new TypeError(
     48                'random_bytes(): $bytes must be an integer'
     49            );
     50        }
    2951
    30 /**
    31  * Powered by ext/mcrypt (and thankfully NOT libmcrypt)
    32  *
    33  * @ref https://bugs.php.net/bug.php?id=55169
    34  * @ref https://github.com/php/php-src/blob/c568ffe5171d942161fc8dda066bce844bdef676/ext/mcrypt/mcrypt.c#L1321-L1386
    35  *
    36  * @param int $bytes
    37  *
    38  * @throws Exception
    39  *
    40  * @return string
    41  */
    42 function random_bytes($bytes)
    43 {
    44     try {
    45         $bytes = RandomCompat_intval($bytes);
    46     } catch (TypeError $ex) {
    47         throw new TypeError(
    48             'random_bytes(): $bytes must be an integer'
     52        if ($bytes < 1) {
     53            throw new Error(
     54                'Length must be greater than 0'
     55            );
     56        }
     57
     58        $buf = @mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
     59        if (
     60            $buf !== false
     61            &&
     62            RandomCompat_strlen($buf) === $bytes
     63        ) {
     64            /**
     65             * Return our random entropy buffer here:
     66             */
     67            return $buf;
     68        }
     69
     70        /**
     71         * If we reach here, PHP has failed us.
     72         */
     73        throw new Exception(
     74            'Could not gather sufficient random data'
    4975        );
    5076    }
    51 
    52     if ($bytes < 1) {
    53         throw new Error(
    54             'Length must be greater than 0'
    55         );
    56     }
    57 
    58     $buf = @mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
    59     if (
    60         $buf !== false
    61         &&
    62         RandomCompat_strlen($buf) === $bytes
    63     ) {
    64         /**
    65          * Return our random entropy buffer here:
    66          */
    67         return $buf;
    68     }
    69 
    70     /**
    71      * If we reach here, PHP has failed us.
    72      */
    73     throw new Exception(
    74         'Could not gather sufficient random data'
    75     );
    7677}
Note: See TracChangeset for help on using the changeset viewer.