~fkooman/php-jwt

d913b73e2d09695449e3f5504db20b371bc125e0 — François Kooman 5 years ago 3f82b26
also benchmark signature validation
5 files changed, 44 insertions(+), 3 deletions(-)

M benchmarks/SignBench.php
A benchmarks/keys/eddsa.key
A benchmarks/keys/hs256.key
R benchmarks/{data/rsa.pub => keys/rs256.crt}
R benchmarks/{data/rsa.key => keys/rs256.key}
M benchmarks/SignBench.php => benchmarks/SignBench.php +42 -3
@@ 46,17 46,17 @@ class SignBench

    public function initHS256()
    {
        $this->hs256 = new HS256(HS256SecretKey::generate());
        $this->hs256 = new HS256(HS256SecretKey::fromEncodedString(\file_get_contents(__DIR__.'/keys/hs256.key')));
    }

    public function initRS256()
    {
        $this->rs256 = new RS256(RS256PublicKey::load(__DIR__.'/data/rsa.pub'), RS256PrivateKey::load(__DIR__.'/data/rsa.key'));
        $this->rs256 = new RS256(RS256PublicKey::load(__DIR__.'/keys/rs256.crt'), RS256PrivateKey::load(__DIR__.'/keys/rs256.key'));
    }

    public function initEdDSA()
    {
        $secretKey = EdDSASecretKey::generate();
        $secretKey = EdDSASecretKey::fromEncodedString(\file_get_contents(__DIR__.'/keys/eddsa.key'));
        $this->eddsa = new EdDSA($secretKey->getPublicKey(), $secretKey);
    }



@@ 81,6 81,19 @@ class SignBench
     *
     * @return void
     */
    public function benchVerifyHS256()
    {
        $this->hs256->decode('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.Jyw18klPA0nFJpoRFua0mAyCyq_AwG0Y7AUiAzqrtmc');
    }

    /**
     * @Revs(1000)
     * @Iterations(5)
     * @OutputTimeUnit("seconds")
     * @OutputMode("throughput")
     *
     * @return void
     */
    public function benchSignRS256()
    {
        $this->rs256->encode(['foo' => 'bar']);


@@ 94,8 107,34 @@ class SignBench
     *
     * @return void
     */
    public function benchVerifyRS256()
    {
        $this->rs256->decode('eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.n_jnlmY2z7EjRogmcNvqVVjd8beDohEOrb03AHapeoOmUPISQrpwQ91yfZ7c5aoa8R1HvFtv7SYfAPRHXaDB1tKeCafD1fCyuH6d2PDqy68TRzA-ILsa78zqtigNQ3w72yarZ4BTZu2OuJdJ7TJg-OXn8cYeUIWN9gn7dF4zT0NjHAhsaF1QQEfkDu44YVvjmZo-uqDlFSezmkNpUGffap-hMb7z_4FwfIWxExjYKUwKOxUD8Hx8R6uJ0KoV_hLQOjFUfKM6EDtv2PPCiOm-5gWxnoL9s4sF-01W1On0RQhhJDAeRLXCpZfT_NylpYd_gUL2WQkxSD3MVUFtHjRpxQ');
    }

    /**
     * @Revs(1000)
     * @Iterations(5)
     * @OutputTimeUnit("seconds")
     * @OutputMode("throughput")
     *
     * @return void
     */
    public function benchSignEdDSA()
    {
        $this->eddsa->encode(['foo' => 'bar']);
    }

    /**
     * @Revs(1000)
     * @Iterations(5)
     * @OutputTimeUnit("seconds")
     * @OutputMode("throughput")
     *
     * @return void
     */
    public function benchVerifyEdDSA()
    {
        $this->eddsa->decode('eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.9DE3hlp2G1IG5E8sX3VfANjmOdPTip6rKsYO2CAEOr1GNsZmGi_eA-pmZmibkMRibVwmtkcUDtNjQDoBAACwCw');
    }
}

A benchmarks/keys/eddsa.key => benchmarks/keys/eddsa.key +1 -0
@@ 0,0 1,1 @@
KsYaMvYg6JmKxDBAfUT6Ml34epT77DmACEJxnuKIZVDkB1m_75c-WGYW9QzTOcd-gvqvzZG2Q1OrRAf5DzausQ
\ No newline at end of file

A benchmarks/keys/hs256.key => benchmarks/keys/hs256.key +1 -0
@@ 0,0 1,1 @@
uZ7G8r-Mzo8eIAruwYc8fWGyVwelzfV0mUB1rJfKf48
\ No newline at end of file

R benchmarks/data/rsa.pub => benchmarks/keys/rs256.crt +0 -0
R benchmarks/data/rsa.key => benchmarks/keys/rs256.key +0 -0