Merge "Hard deprecate functionality replaced with random_bytes()"

This commit is contained in:
jenkins-bot 2018-10-24 22:13:06 +00:00 committed by Gerrit Code Review
commit 0d2dd9cf37
4 changed files with 17 additions and 1 deletions

View file

@ -518,6 +518,7 @@ class MediaWikiServices extends ServiceContainer {
* @return CryptRand
*/
public function getCryptRand() {
wfDeprecated( __METHOD__, '1.32' );
return $this->getService( 'CryptRand' );
}

View file

@ -46,6 +46,7 @@ class CryptRand {
* @return string
*/
protected function initialRandomState() {
wfDeprecated( __METHOD__, '1.32' );
return '';
}
@ -59,6 +60,7 @@ class CryptRand {
* @author Tim Starling
*/
protected function driftHash( $data ) {
wfDeprecated( __METHOD__, '1.32' );
return '';
}
@ -70,6 +72,7 @@ class CryptRand {
* @return string A new weak random state
*/
protected function randomState() {
wfDeprecated( __METHOD__, '1.32' );
return '';
}
@ -83,6 +86,7 @@ class CryptRand {
* @return bool Always true
*/
public function wasStrong() {
wfDeprecated( __METHOD__, '1.32' );
return true;
}
@ -96,6 +100,7 @@ class CryptRand {
* @return string Raw binary random data
*/
public function generate( $bytes ) {
wfDeprecated( __METHOD__, '1.32' );
$bytes = floor( $bytes );
return random_bytes( $bytes );
}
@ -108,6 +113,7 @@ class CryptRand {
* @return string Hexadecimal random data
*/
public function generateHex( $chars ) {
wfDeprecated( __METHOD__, '1.32' );
return MWCryptRand::generateHex( $chars );
}
}

View file

@ -32,6 +32,7 @@ class MWCryptRand {
* @return CryptRand
*/
protected static function singleton() {
wfDeprecated( __METHOD__, '1.32' );
return MediaWikiServices::getInstance()->getCryptRand();
}
@ -45,6 +46,7 @@ class MWCryptRand {
* @return bool Always true
*/
public static function wasStrong() {
wfDeprecated( __METHOD__, '1.32' );
return true;
}
@ -58,6 +60,7 @@ class MWCryptRand {
* @return string Raw binary random data
*/
public static function generate( $bytes ) {
wfDeprecated( __METHOD__, '1.32' );
return random_bytes( floor( $bytes ) );
}

View file

@ -11,6 +11,7 @@ use MediaWiki\Services\ServiceDisabledException;
* @group MediaWiki
*/
class MediaWikiServicesTest extends MediaWikiTestCase {
private $deprecatedServices = [ 'CryptRand' ];
/**
* @return Config
@ -276,6 +277,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase {
$getterCases[$name] = [
'get' . $service,
$class,
in_array( $service, $this->deprecatedServices )
];
}
@ -285,7 +287,11 @@ class MediaWikiServicesTest extends MediaWikiTestCase {
/**
* @dataProvider provideGetters
*/
public function testGetters( $getter, $type ) {
public function testGetters( $getter, $type, $isDeprecated = false ) {
if ( $isDeprecated ) {
$this->hideDeprecated( MediaWikiServices::class . "::$getter" );
}
// Test against the default instance, since the dummy will not know the default services.
$services = MediaWikiServices::getInstance();
$service = $services->$getter();