From 1d651b92392086dfb6028e6dd309a00f14d7b440 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 18 Jan 2024 02:01:49 -0300 Subject: [PATCH] Fix logic Signed-off-by: Vitor Mattos --- lib/Helper/ValidateHelper.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Helper/ValidateHelper.php b/lib/Helper/ValidateHelper.php index a1dda54854..54e7ad0bbe 100644 --- a/lib/Helper/ValidateHelper.php +++ b/lib/Helper/ValidateHelper.php @@ -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]; @@ -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)])); } }