()
| 110 | } |
| 111 | |
| 112 | public static function getMasterKeyOrNull(): ?string |
| 113 | { |
| 114 | if (!self::isAvailable()) { |
| 115 | return null; |
| 116 | } |
| 117 | if (self::$cachedKey !== null) { |
| 118 | return self::$cachedKey; |
| 119 | } |
| 120 | |
| 121 | $env = getenv('FR_ENCRYPTION_MASTER_KEY'); |
| 122 | if (is_string($env) && $env !== '') { |
| 123 | $k = self::parseKeyString($env); |
| 124 | if ($k !== null) { |
| 125 | self::$cachedKey = $k; |
| 126 | return $k; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | $kf = self::keyFilePath(); |
| 131 | if (is_file($kf)) { |
| 132 | $bin = @file_get_contents($kf); |
| 133 | if (is_string($bin) && strlen($bin) === SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES) { |
| 134 | self::$cachedKey = $bin; |
| 135 | return $bin; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return null; |
| 140 | } |
| 141 | |
| 142 | public static function requireMasterKey(): string |
| 143 | { |
no test coverage detected