MediaWiki REL1_33
MWCryptHashTest.php
Go to the documentation of this file.
1<?php
2
8class MWCryptHashTest extends PHPUnit\Framework\TestCase {
9
10 use MediaWikiCoversValidator;
11
12 public function testHashLength() {
13 if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
14 $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
15 }
16
17 $this->assertEquals( 64, MWCryptHash::hashLength(), 'Raw hash length' );
18 $this->assertEquals( 128, MWCryptHash::hashLength( false ), 'Hex hash length' );
19 }
20
21 public function testHash() {
22 if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
23 $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
24 }
25
26 $data = 'foobar';
27 // phpcs:ignore Generic.Files.LineLength
28 $hash = '9923afaec3a86f865bb231a588f453f84e8151a2deb4109aebc6de4284be5bebcff4fab82a7e51d920237340a043736e9d13bab196006dcca0fe65314d68eab9';
29
30 $this->assertEquals(
31 hex2bin( $hash ),
33 'Raw hash'
34 );
35 $this->assertEquals(
36 $hash,
37 MWCryptHash::hash( $data, false ),
38 'Hex hash'
39 );
40 }
41
42 public function testHmac() {
43 if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
44 $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
45 }
46
47 $data = 'foobar';
48 $key = 'secret';
49 // phpcs:ignore Generic.Files.LineLength
50 $hash = 'ddc94177b2020e55ce2049199fd9cc6327f416ff6dc621cc34cb43d9bec61d73372b4790c0e24957f565ecaf2d42821e6303619093e99cbe14a3b9250bda5f81';
51
52 $this->assertEquals(
53 hex2bin( $hash ),
54 MWCryptHash::hmac( $data, $key ),
55 'Raw hmac'
56 );
57 $this->assertEquals(
58 $hash,
59 MWCryptHash::hmac( $data, $key, false ),
60 'Hex hmac'
61 );
62 }
63
64}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
static hashAlgo()
Decide on the best acceptable hash algorithm we have available for hash()
static hashLength( $raw=true)
Return the byte-length output of the hash algorithm we are using in self::hash and self::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 ...
static hash( $data, $raw=true)
Generate an acceptably unstable one-way-hash of some text making use of the best hash algorithm that ...
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)