Skip to content

Commit

Permalink
Fix logic
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Jan 18, 2024
1 parent 0d65924 commit 1d651b9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/Helper/ValidateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function validateBase64(string $base64, int $type = self::TYPE_TO_SIGN):
if (count($withMime[0]) !== 2) {
throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)]));
}
if ($withMime[0][0] !== 'data:application/pdf' || $withMime[0][1] !== 'base64') {
if ($withMime[0][1] !== 'base64') {
throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)]));
}
$base64 = $withMime[1];
Expand All @@ -174,10 +174,9 @@ public function validateBase64(string $base64, int $type = self::TYPE_TO_SIGN):

$mimeType = $this->mimeTypeDetector->detectString($string);

if (
($type === self::TYPE_TO_SIGN && $mimeType !== 'application/pdf')
|| (in_array($type, [self::TYPE_VISIBLE_ELEMENT_USER, self::TYPE_VISIBLE_ELEMENT_PDF]) && $mimeType !== 'image/png')
) {
if ($type === self::TYPE_TO_SIGN && $mimeType !== 'application/pdf') {
throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)]));
} elseif ($mimeType !== 'image/png' && in_array($type, [self::TYPE_VISIBLE_ELEMENT_USER, self::TYPE_VISIBLE_ELEMENT_PDF])) {
throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)]));
}
}
Expand Down

0 comments on commit 1d651b9

Please sign in to comment.