MediaWiki  1.29.1
MWCryptHashTest.php
Go to the documentation of this file.
1 <?php
7 class MWCryptHashTest extends PHPUnit_Framework_TestCase {
8 
9  public function testHashLength() {
10  if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
11  $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
12  }
13 
14  $this->assertEquals( 64, MWCryptHash::hashLength(), 'Raw hash length' );
15  $this->assertEquals( 128, MWCryptHash::hashLength( false ), 'Hex hash length' );
16  }
17 
18  public function testHash() {
19  if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
20  $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
21  }
22 
23  $data = 'foobar';
24  // @codingStandardsIgnoreStart Generic.Files.LineLength
25  $hash = '9923afaec3a86f865bb231a588f453f84e8151a2deb4109aebc6de4284be5bebcff4fab82a7e51d920237340a043736e9d13bab196006dcca0fe65314d68eab9';
26  // @codingStandardsIgnoreEnd
27 
28  $this->assertEquals(
29  hex2bin( $hash ),
30  MWCryptHash::hash( $data ),
31  'Raw hash'
32  );
33  $this->assertEquals(
34  $hash,
35  MWCryptHash::hash( $data, false ),
36  'Hex hash'
37  );
38  }
39 
40  public function testHmac() {
41  if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
42  $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
43  }
44 
45  $data = 'foobar';
46  $key = 'secret';
47  // @codingStandardsIgnoreStart Generic.Files.LineLength
48  $hash = 'ddc94177b2020e55ce2049199fd9cc6327f416ff6dc621cc34cb43d9bec61d73372b4790c0e24957f565ecaf2d42821e6303619093e99cbe14a3b9250bda5f81';
49  // @codingStandardsIgnoreEnd
50 
51  $this->assertEquals(
52  hex2bin( $hash ),
53  MWCryptHash::hmac( $data, $key ),
54  'Raw hmac'
55  );
56  $this->assertEquals(
57  $hash,
58  MWCryptHash::hmac( $data, $key, false ),
59  'Hex hmac'
60  );
61  }
62 
63 }
MWCryptHashTest\testHmac
testHmac()
Definition: MWCryptHashTest.php:40
MWCryptHash\hmac
static hmac( $data, $key, $raw=true)
Generate an acceptably unstable one-way-hmac of some text making use of the best hash algorithm that ...
Definition: MWCryptHash.php:106
MWCryptHashTest\testHashLength
testHashLength()
Definition: MWCryptHashTest.php:9
MWCryptHash\hash
static hash( $data, $raw=true)
Generate an acceptably unstable one-way-hash of some text making use of the best hash algorithm that ...
Definition: MWCryptHash.php:93
MWCryptHash\hashLength
static hashLength( $raw=true)
Return the byte-length output of the hash algorithm we are using in self::hash and self::hmac.
Definition: MWCryptHash.php:76
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MWCryptHashTest\testHash
testHash()
Definition: MWCryptHashTest.php:18
MWCryptHash\hashAlgo
static hashAlgo()
Decide on the best acceptable hash algorithm we have available for hash()
Definition: MWCryptHash.php:44
MWCryptHashTest
Hash.
Definition: MWCryptHashTest.php:7