Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92650516
PhabricatorHashTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 22, 09:41
Size
1006 B
Mime Type
text/x-php
Expires
Sun, Nov 24, 09:41 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22477742
Attached To
rPH Phabricator
PhabricatorHashTestCase.php
View Options
<?php
final
class
PhabricatorHashTestCase
extends
PhabricatorTestCase
{
public
function
testHashForIndex
()
{
$map
=
array
(
'dog'
=>
'Aliif7Qjd5ct'
,
'cat'
=>
'toudDsue3Uv8'
,
'rat'
=>
'RswaKgTjqOuj'
,
'bat'
=>
'rAkJKyX4YdYm'
,
);
foreach
(
$map
as
$input
=>
$expect
)
{
$this
->
assertEqual
(
$expect
,
PhabricatorHash
::
digestForIndex
(
$input
),
pht
(
'Input: %s'
,
$input
));
}
// Test that the encoding produces 6 bits of entropy per byte.
$entropy
=
array
(
'dog'
,
'cat'
,
'rat'
,
'bat'
,
'dig'
,
'fig'
,
'cot'
,
'cut'
,
'fog'
,
'rig'
,
'rug'
,
'dug'
,
'mat'
,
'pat'
,
'eat'
,
'tar'
,
'pot'
,
);
$seen
=
array
();
foreach
(
$entropy
as
$input
)
{
$chars
=
preg_split
(
'//'
,
PhabricatorHash
::
digestForIndex
(
$input
));
foreach
(
$chars
as
$char
)
{
$seen
[
$char
]
=
true
;
}
}
$this
->
assertEqual
(
(
1
<<
6
),
count
(
$seen
),
pht
(
'Distinct characters in hash of: %s'
,
$input
));
}
}
Event Timeline
Log In to Comment