-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfig.php
More file actions
87 lines (78 loc) · 3.09 KB
/
Copy pathConfig.php
File metadata and controls
87 lines (78 loc) · 3.09 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace BenjaminStout\PHPCrypt;
class Config
{
private static $config = [
'keyPath' => __DIR__ . DS . '..' . DS . 'keys', // Absolute path to key store, no trailing slash (default is ../keys)
'keySodium' => null, // Holds the currently-set Sodium encryption key
'keyOpenssl' => null, // Holds the currently-set OpenSSL encryption key
'keyMcrypt' => null, // Holds the currently-set Mcrypt encryption key
'keyPathSodium' => null, // Unique path to Sodium key (used if valid)
'keyPathOpenssl' => null, // Unique path to OpenSSL key (used if valid)
'keyPathMcrypt' => null, // Unique path to Mcrypt key (used if valid)
'cipherMcrypt' => MCRYPT_3DES, // Mcrypt cipher method
'cipherOpenssl' => null, // OpenSSL cipher method (initialized in constructor)
'modeMcrypt' => MCRYPT_MODE_ECB, // Mcrypt encryption mode
'cipherPrefsOpenssl' => [ // OpenSSL cipher methods in descending order of preference, used by constructor to choose best available cipher
'aes-256-gcm', // Fast, secure, and supports authenticated encryption (unsupported on PHP <= 7.0)
'aes-256-ccm', // Slower than GCM, but supports authenticated encryption (unsupported on PHP <= 7.0)
'aes-256-cbc', // Secure, but does not support authenticated encryption, requiring manual computation
],
];
private static $default = [];
public static function reset()
{
if (!empty(static::$default)) {
static::$config = static::$default;
}
}
public static function backup()
{
if (empty(static::$default)) {
static::$default = static::$config;
}
}
/**
* Merges passed array with config array, overwriting duplicates
*
* @var array $arr
* @return bool success
* @access public
*/
public static function merge($arr)
{
static::backup();
static::$config = array_merge(static::$config, $arr);
return true;
}
/**
* Returns the value from static::$config at index $key if set
* Otherwise, returns null
*
* @var string key
* @return mixed value, else null
* @access public
*/
public static function read($key)
{
return isset(static::$config[$key]) ? static::$config[$key] : null;
}
/**
* Sets the value on static::$config[$key] to $val
* Also supports array of key/value pairs as first arg
*
* @var string key
* @var mixed $val
* @return bool success
* @access public
*/
public static function write($key, $val = null)
{
if (is_array($key)) {
return static::merge($key);
}
static::backup();
static::$config[$key] = $val;
return true;
}
}