From 75160b12821f7f4299cce7f0b69c83c1502ae071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 27 May 2024 13:08:29 +0200 Subject: 2024-02-19 upstream --- .../jwt-signature/Serializer/CompactSerializer.php | 194 ++++++++++----------- 1 file changed, 97 insertions(+), 97 deletions(-) (limited to 'vendor/web-token/jwt-signature/Serializer/CompactSerializer.php') diff --git a/vendor/web-token/jwt-signature/Serializer/CompactSerializer.php b/vendor/web-token/jwt-signature/Serializer/CompactSerializer.php index 7e26d79..9518543 100644 --- a/vendor/web-token/jwt-signature/Serializer/CompactSerializer.php +++ b/vendor/web-token/jwt-signature/Serializer/CompactSerializer.php @@ -1,97 +1,97 @@ -jsonConverter = $jsonConverter ?? new \Jose\Component\Core\Util\JsonConverter(); - } - - public function displayName(): string - { - return 'JWS Compact'; - } - - public function name(): string - { - return self::NAME; - } - - public function serialize(JWS $jws, ?int $signatureIndex = null): string - { - if (null === $signatureIndex) { - $signatureIndex = 0; - } - $signature = $jws->getSignature($signatureIndex); - if (!empty($signature->getHeader())) { - throw new \LogicException('The signature contains unprotected header parameters and cannot be converted into compact JSON.'); - } - if (!$this->isPayloadEncoded($signature->getProtectedHeader()) && !empty($jws->getEncodedPayload())) { - if (1 !== \preg_match('/^[\x{20}-\x{2d}|\x{2f}-\x{7e}]*$/u', $jws->getPayload())) { - throw new \LogicException('Unable to convert the JWS with non-encoded payload.'); - } - } - - return \sprintf( - '%s.%s.%s', - $signature->getEncodedProtectedHeader(), - $jws->getEncodedPayload(), - Base64Url::encode($signature->getSignature()) - ); - } - - public function unserialize(string $input): JWS - { - $parts = \explode('.', $input); - if (3 !== \count($parts)) { - throw new \InvalidArgumentException('Unsupported input'); - } - - try { - $encodedProtectedHeader = $parts[0]; - $protectedHeader = $this->jsonConverter->decode(Base64Url::decode($parts[0])); - if (empty($parts[1])) { - $payload = null; - $encodedPayload = null; - } else { - $encodedPayload = $parts[1]; - $payload = $this->isPayloadEncoded($protectedHeader) ? Base64Url::decode($encodedPayload) : $encodedPayload; - } - $signature = Base64Url::decode($parts[2]); - - $jws = JWS::create($payload, $encodedPayload, empty($parts[1])); - $jws = $jws->addSignature($signature, $protectedHeader, $encodedProtectedHeader); - - return $jws; - } catch (\Error | \Exception $e) { - throw new \InvalidArgumentException('Unsupported input'); - } - } -} +jsonConverter = $jsonConverter ?? new \Jose\Component\Core\Util\JsonConverter(); + } + + public function displayName(): string + { + return 'JWS Compact'; + } + + public function name(): string + { + return self::NAME; + } + + public function serialize(JWS $jws, ?int $signatureIndex = null): string + { + if (null === $signatureIndex) { + $signatureIndex = 0; + } + $signature = $jws->getSignature($signatureIndex); + if (!empty($signature->getHeader())) { + throw new \LogicException('The signature contains unprotected header parameters and cannot be converted into compact JSON.'); + } + if (!$this->isPayloadEncoded($signature->getProtectedHeader()) && !empty($jws->getEncodedPayload())) { + if (1 !== \preg_match('/^[\x{20}-\x{2d}|\x{2f}-\x{7e}]*$/u', $jws->getPayload())) { + throw new \LogicException('Unable to convert the JWS with non-encoded payload.'); + } + } + + return \sprintf( + '%s.%s.%s', + $signature->getEncodedProtectedHeader(), + $jws->getEncodedPayload(), + Base64Url::encode($signature->getSignature()) + ); + } + + public function unserialize(string $input): JWS + { + $parts = \explode('.', $input); + if (3 !== \count($parts)) { + throw new \InvalidArgumentException('Unsupported input'); + } + + try { + $encodedProtectedHeader = $parts[0]; + $protectedHeader = $this->jsonConverter->decode(Base64Url::decode($parts[0])); + if (empty($parts[1])) { + $payload = null; + $encodedPayload = null; + } else { + $encodedPayload = $parts[1]; + $payload = $this->isPayloadEncoded($protectedHeader) ? Base64Url::decode($encodedPayload) : $encodedPayload; + } + $signature = Base64Url::decode($parts[2]); + + $jws = JWS::create($payload, $encodedPayload, empty($parts[1])); + $jws = $jws->addSignature($signature, $protectedHeader, $encodedProtectedHeader); + + return $jws; + } catch (\Error | \Exception $e) { + throw new \InvalidArgumentException('Unsupported input'); + } + } +} -- cgit v1.2.3