diff --git a/src/FileEncryptor.php b/src/FileEncryptor.php index 2332b55..a0dde05 100644 --- a/src/FileEncryptor.php +++ b/src/FileEncryptor.php @@ -13,6 +13,9 @@ public function __construct( private string $filename, #[SensitiveParameter] private string $secret ) { + if (!file_exists($this->filename)) { + throw new FileEncryptorException("File not found"); + } } /** @@ -26,7 +29,7 @@ public function encryptFile(): bool $plainText = file_get_contents($this->filename); if (!$plainText) { - throw new FileEncryptorException('File not found or has no content'); + throw new FileEncryptorException('File has no content'); } if (ctype_xdigit($plainText)) { throw new FileEncryptorException('file is already encrypted'); @@ -65,7 +68,7 @@ public function decryptFile(): bool $encryptedData = file_get_contents($this->filename); if (!$encryptedData) { - throw new FileEncryptorException('File not found or has no content'); + throw new FileEncryptorException('File has no content'); } if (!ctype_xdigit($encryptedData)) {