|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yiisoft\Security; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Mock for the hash_hmac() function |
|
7
|
|
|
* @param $algo |
|
8
|
|
|
* @param $data |
|
9
|
|
|
* @param $key |
|
10
|
|
|
* @param bool $raw_output |
|
11
|
|
|
* @return string |
|
12
|
|
|
*/ |
|
13
|
|
|
function hash_hmac($algo, $data, $key, $raw_output = false) |
|
14
|
|
|
{ |
|
15
|
|
|
return MockHelper::$mock_hash_hmac ?? \hash_hmac($algo, $data, $key, $raw_output); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
function extension_loaded($name) |
|
19
|
|
|
{ |
|
20
|
|
|
return MockHelper::$mock_extension_loaded ?? \extension_loaded($name); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
function openssl_encrypt($data, $method, $key, $options = 0, $iv = "") |
|
24
|
|
|
{ |
|
25
|
|
|
return MockHelper::$mock_openssl_encrypt ?? \openssl_encrypt($data, $method, $key, $options, $iv); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
function openssl_decrypt($data, $method, $password, $options = 1, $iv = "") |
|
29
|
|
|
{ |
|
30
|
|
|
return MockHelper::$mock_openssl_decrypt ?? \openssl_decrypt($data, $method, $password, $options, $iv); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
class MockHelper |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @var int value to be returned by mocked hash_hmac() function. |
|
37
|
|
|
* null means normal hash_hmac() behavior. |
|
38
|
|
|
*/ |
|
39
|
|
|
public static $mock_hash_hmac; |
|
40
|
|
|
/** |
|
41
|
|
|
* @var int value to be returned by mocked extension_loaded() function. |
|
42
|
|
|
* null means normal extension_loaded() behavior. |
|
43
|
|
|
*/ |
|
44
|
|
|
public static $mock_extension_loaded; |
|
45
|
|
|
/** |
|
46
|
|
|
* @var int value to be returned by mocked openssl_encrypt() function. |
|
47
|
|
|
* null means normal openssl_encrypt() behavior. |
|
48
|
|
|
*/ |
|
49
|
|
|
public static $mock_openssl_encrypt; |
|
50
|
|
|
/** |
|
51
|
|
|
* @var int value to be returned by mocked openssl_decrypt() function. |
|
52
|
|
|
* null means normal openssl_decrypt() behavior. |
|
53
|
|
|
*/ |
|
54
|
|
|
public static $mock_openssl_decrypt; |
|
55
|
|
|
|
|
56
|
|
|
public static function resetMocks() |
|
57
|
|
|
{ |
|
58
|
|
|
static::$mock_hash_hmac = null; |
|
59
|
|
|
static::$mock_extension_loaded = null; |
|
60
|
|
|
static::$mock_openssl_encrypt = null; |
|
61
|
|
|
static::$mock_openssl_decrypt = null; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|