![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/demo.cartinsight.co/vendor/lcobucci/jwt/src/Validation/Constraint/ |
<?php declare(strict_types=1); namespace Lcobucci\JWT\Validation\Constraint; use DateInterval; use DateTimeInterface; use Lcobucci\Clock\Clock; use Lcobucci\JWT\Token; use Lcobucci\JWT\Validation\ConstraintViolation; use Lcobucci\JWT\Validation\ValidAt as ValidAtInterface; final class LooseValidAt implements ValidAtInterface { private Clock $clock; private DateInterval $leeway; public function __construct(Clock $clock, ?DateInterval $leeway = null) { $this->clock = $clock; $this->leeway = $this->guardLeeway($leeway); } private function guardLeeway(?DateInterval $leeway): DateInterval { if ($leeway === null) { return new DateInterval('PT0S'); } if ($leeway->invert === 1) { throw LeewayCannotBeNegative::create(); } return $leeway; } public function assert(Token $token): void { $now = $this->clock->now(); $this->assertIssueTime($token, $now->add($this->leeway)); $this->assertMinimumTime($token, $now->add($this->leeway)); $this->assertExpiration($token, $now->sub($this->leeway)); } /** @throws ConstraintViolation */ private function assertExpiration(Token $token, DateTimeInterface $now): void { if ($token->isExpired($now)) { throw ConstraintViolation::error('The token is expired', $this); } } /** @throws ConstraintViolation */ private function assertMinimumTime(Token $token, DateTimeInterface $now): void { if (! $token->isMinimumTimeBefore($now)) { throw ConstraintViolation::error('The token cannot be used yet', $this); } } /** @throws ConstraintViolation */ private function assertIssueTime(Token $token, DateTimeInterface $now): void { if (! $token->hasBeenIssuedBefore($now)) { throw ConstraintViolation::error('The token was issued in the future', $this); } } }