diff --git a/src/Symfony/Component/Mime/Crypto/DkimSigner.php b/src/Symfony/Component/Mime/Crypto/DkimSigner.php index dfb6f226b5e51..f0f7091ed4168 100644 --- a/src/Symfony/Component/Mime/Crypto/DkimSigner.php +++ b/src/Symfony/Component/Mime/Crypto/DkimSigner.php @@ -65,7 +65,7 @@ public function sign(Message $message, array $options = []): Message { $options += $this->defaultOptions; if (!\in_array($options['algorithm'], [self::ALGO_SHA256, self::ALGO_ED25519], true)) { - throw new InvalidArgumentException('Invalid DKIM signing algorithm "%s".', $options['algorithm']); + throw new InvalidArgumentException(sprintf('Invalid DKIM signing algorithm "%s".', $options['algorithm'])); } $headersToIgnore['return-path'] = true; $headersToIgnore['x-transport'] = true; @@ -205,7 +205,7 @@ private function hashBody(AbstractPart $body, string $bodyCanon, int $maxLength) } // Add trailing Line return if last line is non empty - if (\strlen($currentLine) > 0) { + if ('' !== $currentLine) { hash_update($hash, "\r\n"); $length += \strlen("\r\n"); } diff --git a/src/Symfony/Component/Mime/Tests/Crypto/DkimSignerTest.php b/src/Symfony/Component/Mime/Tests/Crypto/DkimSignerTest.php index e48b0c8e4e3c0..e0eaa54f18757 100644 --- a/src/Symfony/Component/Mime/Tests/Crypto/DkimSignerTest.php +++ b/src/Symfony/Component/Mime/Tests/Crypto/DkimSignerTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Crypto\DkimSigner; use Symfony\Component\Mime\Email; +use Symfony\Component\Mime\Message; /** * @group time-sensitive @@ -90,6 +91,21 @@ public function getSignData() ]; } + public function testSignWithUnsupportedAlgorithm() + { + $message = $this->createMock(Message::class); + + $signer = new DkimSigner(self::$pk, 'testdkim.symfony.net', 'sf', [ + 'algorithm' => 'unsupported-value', + ]); + + $this->expectExceptionObject( + new \LogicException('Invalid DKIM signing algorithm "unsupported-value".') + ); + + $signer->sign($message, []); + } + /** * @dataProvider getCanonicalizeHeaderData */