Skip to content

Commit cde144c

Browse files
authored
File encryptor (#9)
prevent the FileEncryptor object from being instantiated if the specified file does not exist. Signed-off-by: rahul <[email protected]>
1 parent 013d836 commit cde144c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/FileEncryptor.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public function __construct(
1313
private string $filename,
1414
#[SensitiveParameter] private string $secret
1515
) {
16+
if (!file_exists($this->filename)) {
17+
throw new FileEncryptorException("File not found");
18+
}
1619
}
1720

1821
/**
@@ -26,7 +29,7 @@ public function encryptFile(): bool
2629
$plainText = file_get_contents($this->filename);
2730

2831
if (!$plainText) {
29-
throw new FileEncryptorException('File not found or has no content');
32+
throw new FileEncryptorException('File has no content');
3033
}
3134
if (ctype_xdigit($plainText)) {
3235
throw new FileEncryptorException('file is already encrypted');
@@ -65,7 +68,7 @@ public function decryptFile(): bool
6568
$encryptedData = file_get_contents($this->filename);
6669

6770
if (!$encryptedData) {
68-
throw new FileEncryptorException('File not found or has no content');
71+
throw new FileEncryptorException('File has no content');
6972
}
7073

7174
if (!ctype_xdigit($encryptedData)) {

0 commit comments

Comments
 (0)