CoreFiles by mySites.guru
ThrowExceptionIfInvalid.php42 lines, 1,196 bytes, from Joomla_5.3.2-Stable-Full_Package.zip
Raw History Compare with 5.3.1
md5
09a3c7fe5f9c07ebb86e8bf912a07c22
sha1
7ce3e29e81ce7547ab624cb421d5f028fe1d725d
sha256
64ceca60106a958acc87da54f467447b7b5c4361222f86a324898108684b0b62
<?php

declare(strict_types=1);

namespace Webauthn\Counter;

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Throwable;
use Webauthn\Exception\CounterException;
use Webauthn\MetadataService\CanLogData;
use Webauthn\PublicKeyCredentialSource;

final class ThrowExceptionIfInvalid implements CounterChecker, CanLogData
{
    public function __construct(
        private LoggerInterface $logger = new NullLogger()
    ) {
    }

    public function setLogger(LoggerInterface $logger): void
    {
        $this->logger = $logger;
    }

    public function check(PublicKeyCredentialSource $publicKeyCredentialSource, int $currentCounter): void
    {
        try {
            $currentCounter > $publicKeyCredentialSource->getCounter() || throw CounterException::create(
                $currentCounter,
                $publicKeyCredentialSource->getCounter(),
                'Invalid counter.'
            );
        } catch (Throwable $throwable) {
            $this->logger->error('The counter is invalid', [
                'current' => $currentCounter,
                'new' => $publicKeyCredentialSource->getCounter(),
            ]);
            throw $throwable;
        }
    }
}

The same content is in 151 releases, Joomla 5.0.0-beta3 to 6.2.1. See them all, or every version of this file.