MCPcopy Create free account
hub / github.com/error311/FileRise / decryptFileInPlace

Method decryptFileInPlace

src/FileRise/Support/CryptoAtRest.php:324–347  ·  view source on GitHub ↗
(string $path)

Source from the content-addressed store, hash-verified

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.

Callers 1

encryptionJobTickMethod · 0.80

Calls 3

isAvailableMethod · 0.95
isEncryptedFileMethod · 0.95
decryptFileToPathMethod · 0.95

Tested by

no test coverage detected