blob: 60b1c007b2fb650dcd1660a574bb47e278ee5aa8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<?php
/**
* Testing the untestable - Session ID generation
*/
class ReferenceSessionIdHashes
{
// Session ID hashes
protected static $sidHashes = null;
/**
* Generates session ID hashes for all algorithms & bit representations
*/
public static function genAllHashes()
{
foreach (hash_algos() as $algo) {
self::$sidHashes[$algo] = array();
foreach (array(4, 5, 6) as $bpc) {
self::$sidHashes[$algo][$bpc] = self::genSidHash($algo, $bpc);
}
}
}
/**
* Generates a session ID for a given hash algorithm and bit representation
*
* @param string $function name of the hash function
* @param int $bits_per_character representation type
*
* @return string the generated session ID
*/
protected static function genSidHash($function, $bits_per_character)
{
if (session_id()) {
session_destroy();
}
ini_set('session.hash_function', $function);
ini_set('session.hash_bits_per_character', $bits_per_character);
session_start();
return session_id();
}
/**
* Returns the reference hash array
*
* @return array session IDs generated for all available algorithms and bit
* representations
*/
public static function getHashes()
{
return self::$sidHashes;
}
}
|