File: VerifySignatureBench.php

package info (click to toggle)
php-lcobucci-jwt 5.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,280 kB
  • sloc: php: 6,674; makefile: 49
file content (34 lines) | stat: -rw-r--r-- 933 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types=1);

namespace Lcobucci\JWT\Tests\Benchmark;

use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Signer\Key;
use PhpBench\Attributes as Bench;

#[Bench\BeforeMethods('initialize')]
final class VerifySignatureBench extends AlgorithmsBench
{
    private Signer $algorithm;
    private Key $key;
    /** @var non-empty-string */
    private string $signature;

    /** @param array{algorithm: string} $params */
    public function initialize(array $params): void
    {
        $this->algorithm = $this->resolveAlgorithm($params['algorithm']);
        $this->key       = $this->resolveVerificationKey($params['algorithm']);

        $this->signature = $this->algorithm->sign(
            self::PAYLOAD,
            $this->resolveSigningKey($params['algorithm']),
        );
    }

    protected function runBenchmark(): void
    {
        $this->algorithm->verify($this->signature, self::PAYLOAD, $this->key);
    }
}