Remove CryptRand and related stuff
authorMax Semenik <maxsem.wiki@gmail.com>
Sun, 17 Mar 2019 07:34:10 +0000 (00:34 -0700)
committerReedy <reedy@wikimedia.org>
Thu, 11 Apr 2019 17:20:09 +0000 (18:20 +0100)
Deprecated in 1.31 and not used anywhere.

Change-Id: Idc2e9cec907e39cacc391fdd7e2718bd880081ae

RELEASE-NOTES-1.34
autoload.php
includes/MediaWikiServices.php
includes/ServiceWiring.php
includes/libs/CryptRand.php [deleted file]
includes/utils/MWCryptRand.php
tests/phpunit/includes/MediaWikiServicesTest.php

index 3c471c2..9fb74dc 100644 (file)
@@ -68,6 +68,11 @@ because of Phabricator reports.
 
 === Breaking changes in 1.34 ===
 * Preferences class, deprecated in 1.31, has been removed.
+* The following parts of code, deprecated in 1.32, were removed in favor of
+  built-in PHP functions:
+  * CryptRand class
+  * CryptRand service
+  * Functions of the MWCryptRand class: singleton(), wasStrong() and generate().
 * …
 
 === Deprecations in 1.34 ===
index a5ce46b..a74a0b8 100644 (file)
@@ -327,7 +327,6 @@ $wgAutoloadLocalClasses = [
        'CreditsAction' => __DIR__ . '/includes/actions/CreditsAction.php',
        'CrhConverter' => __DIR__ . '/languages/classes/LanguageCrh.php',
        'CryptHKDF' => __DIR__ . '/includes/libs/CryptHKDF.php',
-       'CryptRand' => __DIR__ . '/includes/libs/CryptRand.php',
        'CssContent' => __DIR__ . '/includes/content/CssContent.php',
        'CssContentHandler' => __DIR__ . '/includes/content/CssContentHandler.php',
        'CsvStatsOutput' => __DIR__ . '/maintenance/language/StatOutputs.php',
index 22f0c63..c296a72 100644 (file)
@@ -6,7 +6,6 @@ use CommentStore;
 use Config;
 use ConfigFactory;
 use CryptHKDF;
-use CryptRand;
 use DateFormatterFactory;
 use EventRelayerGroup;
 use GenderCache;
@@ -517,16 +516,6 @@ class MediaWikiServices extends ServiceContainer {
                return $this->getService( 'CryptHKDF' );
        }
 
-       /**
-        * @since 1.28
-        * @deprecated since 1.32, use random_bytes()/random_int()
-        * @return CryptRand
-        */
-       public function getCryptRand() {
-               wfDeprecated( __METHOD__, '1.32' );
-               return $this->getService( 'CryptRand' );
-       }
-
        /**
         * @since 1.33
         * @return DateFormatterFactory
index 1eb3551..c55fc68 100644 (file)
@@ -134,10 +134,6 @@ return [
                return new CryptHKDF( $secret, $config->get( 'HKDFAlgorithm' ), $cache, $context );
        },
 
-       'CryptRand' => function () : CryptRand {
-               return new CryptRand();
-       },
-
        'DateFormatterFactory' => function () : DateFormatterFactory {
                return new DateFormatterFactory;
        },
diff --git a/includes/libs/CryptRand.php b/includes/libs/CryptRand.php
deleted file mode 100644 (file)
index da0cae2..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-/**
- * A cryptographic random generator class used for generating secret keys
- *
- * This is based in part on Drupal code as well as what we used in our own code
- * prior to introduction of this class.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @author Daniel Friesen
- * @file
- */
-
-/**
- * @deprecated since 1.32, use random_bytes()/random_int()
- */
-class CryptRand {
-       /**
-        * @deprecated since 1.32, unused
-        */
-       const MIN_ITERATIONS = 1000;
-
-       /**
-        * @deprecated since 1.32, unused
-        */
-       const MSEC_PER_BYTE = 0.5;
-
-       /**
-        * Initialize an initial random state based off of whatever we can find
-        *
-        * @deprecated since 1.32, unused and does nothing
-        *
-        * @return string
-        */
-       protected function initialRandomState() {
-               wfDeprecated( __METHOD__, '1.32' );
-               return '';
-       }
-
-       /**
-        * Randomly hash data while mixing in clock drift data for randomness
-        *
-        * @deprecated since 1.32, unused and does nothing
-        *
-        * @param string $data The data to randomly hash.
-        * @return string The hashed bytes
-        * @author Tim Starling
-        */
-       protected function driftHash( $data ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               return '';
-       }
-
-       /**
-        * Return a rolling random state initially build using data from unstable sources
-        *
-        * @deprecated since 1.32, unused and does nothing
-        *
-        * @return string A new weak random state
-        */
-       protected function randomState() {
-               wfDeprecated( __METHOD__, '1.32' );
-               return '';
-       }
-
-       /**
-        * Return a boolean indicating whether or not the source used for cryptographic
-        * random bytes generation in the previously run generate* call
-        * was cryptographically strong.
-        *
-        * @deprecated since 1.32, always returns true
-        *
-        * @return bool Always true
-        */
-       public function wasStrong() {
-               wfDeprecated( __METHOD__, '1.32' );
-               return true;
-       }
-
-       /**
-        * Generate a run of cryptographically random data and return
-        * it in raw binary form.
-        * You can use CryptRand::wasStrong() if you wish to know if the source used
-        * was cryptographically strong.
-        *
-        * @param int $bytes The number of bytes of random data to generate
-        * @return string Raw binary random data
-        */
-       public function generate( $bytes ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               $bytes = floor( $bytes );
-               return random_bytes( $bytes );
-       }
-
-       /**
-        * Generate a run of cryptographically random data and return
-        * it in hexadecimal string format.
-        *
-        * @param int $chars The number of hex chars of random data to generate
-        * @return string Hexadecimal random data
-        */
-       public function generateHex( $chars ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               return MWCryptRand::generateHex( $chars );
-       }
-}
index ec8bf5c..673586d 100644 (file)
  * @file
  */
 
-use MediaWiki\MediaWikiServices;
-
 class MWCryptRand {
-       /**
-        * @deprecated since 1.32
-        * @return CryptRand
-        */
-       protected static function singleton() {
-               wfDeprecated( __METHOD__, '1.32' );
-               return MediaWikiServices::getInstance()->getCryptRand();
-       }
-
-       /**
-        * Return a boolean indicating whether or not the source used for cryptographic
-        * random bytes generation in the previously run generate* call
-        * was cryptographically strong.
-        *
-        * @deprecated since 1.32, always returns true
-        *
-        * @return bool Always true
-        */
-       public static function wasStrong() {
-               wfDeprecated( __METHOD__, '1.32' );
-               return true;
-       }
-
-       /**
-        * Generate a run of cryptographically random data and return
-        * it in raw binary form.
-        *
-        * @deprecated since 1.32, use random_bytes()
-        *
-        * @param int $bytes The number of bytes of random data to generate
-        * @return string Raw binary random data
-        */
-       public static function generate( $bytes ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               return random_bytes( floor( $bytes ) );
-       }
 
        /**
         * Generate a run of cryptographically random data and return
index 9d6164c..8fa0cd6 100644 (file)
@@ -11,7 +11,7 @@ use Wikimedia\Services\ServiceDisabledException;
  * @group MediaWiki
  */
 class MediaWikiServicesTest extends MediaWikiTestCase {
-       private $deprecatedServices = [ 'CryptRand' ];
+       private $deprecatedServices = [];
 
        /**
         * @return Config