(string $path)
| 322 | } |
| 323 | |
| 324 | public static function decryptFileInPlace(string $path): void |
| 325 | { |
| 326 | if (!self::isAvailable()) { |
| 327 | throw new \RuntimeException('libsodium secretstream is not available on this PHP build.'); |
| 328 | } |
| 329 | if (!is_file($path)) { |
| 330 | throw new \RuntimeException('File not found for decryption.'); |
| 331 | } |
| 332 | if (!self::isEncryptedFile($path)) { |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | $dir = dirname($path); |
| 337 | $base = basename($path); |
| 338 | $tmp = $dir . DIRECTORY_SEPARATOR . '.' . $base . '.frtmpdec.' . bin2hex(random_bytes(6)); |
| 339 | |
| 340 | self::decryptFileToPath($path, $tmp); |
| 341 | |
| 342 | $mode = @fileperms($path); |
| 343 | @rename($tmp, $path); |
| 344 | if (is_int($mode) && $mode > 0) { |
| 345 | @chmod($path, $mode & 0777); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Stream-decrypt an encrypted file into an output stream resource. |
no test coverage detected