Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4076479
MWCryptHashTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
MWCryptHashTest.php
View Options
<?php
namespace
Wikimedia\Tests
;
use
MediaWikiUnitTestCase
;
use
MWCryptHash
;
/**
* @group Hash
*
* @covers \MWCryptHash
*/
class
MWCryptHashTest
extends
MediaWikiUnitTestCase
{
public
function
testHashLength
()
{
if
(
MWCryptHash
::
hashAlgo
()
!==
'whirlpool'
)
{
$this
->
markTestSkipped
(
'Hash algorithm isn
\'
t whirlpool'
);
}
$this
->
assertEquals
(
64
,
MWCryptHash
::
hashLength
(),
'Raw hash length'
);
$this
->
assertEquals
(
128
,
MWCryptHash
::
hashLength
(
false
),
'Hex hash length'
);
}
public
function
testHash
()
{
if
(
MWCryptHash
::
hashAlgo
()
!==
'whirlpool'
)
{
$this
->
markTestSkipped
(
'Hash algorithm isn
\'
t whirlpool'
);
}
$data
=
'foobar'
;
$hash
=
'9923afaec3a86f865bb231a588f453f84e8151a2deb4109aebc6de4284be5bebcff4fab82a7e51d920237340a043736e9d13bab196006dcca0fe65314d68eab9'
;
$this
->
assertEquals
(
hex2bin
(
$hash
),
MWCryptHash
::
hash
(
$data
),
'Raw hash'
);
$this
->
assertEquals
(
$hash
,
MWCryptHash
::
hash
(
$data
,
false
),
'Hex hash'
);
}
public
function
testHmac
()
{
if
(
MWCryptHash
::
hashAlgo
()
!==
'whirlpool'
)
{
$this
->
markTestSkipped
(
'Hash algorithm isn
\'
t whirlpool'
);
}
$data
=
'foobar'
;
$key
=
'secret'
;
$hash
=
'ddc94177b2020e55ce2049199fd9cc6327f416ff6dc621cc34cb43d9bec61d73372b4790c0e24957f565ecaf2d42821e6303619093e99cbe14a3b9250bda5f81'
;
$this
->
assertEquals
(
hex2bin
(
$hash
),
MWCryptHash
::
hmac
(
$data
,
$key
),
'Raw hmac'
);
$this
->
assertEquals
(
$hash
,
MWCryptHash
::
hmac
(
$data
,
$key
,
false
),
'Hex hmac'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 17 2026, 20:50 (9 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4b/a7/6358c46f1dcd780d3adb6b01da3e
Default Alt Text
MWCryptHashTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment