CoreFiles by mySites.guru
Hmac.php34 lines, 944 bytes, from Joomla_6.2.1-Stable-Full_Package.zip
Raw History Compare with 6.2.0
md5
5fa13d2e372d1db5d981f828afe20fa1
sha1
3a692a77c2802a6a4bafb81880941a436af2e97b
sha256
d9891409773a5b98e82e9c02ad8eb569c9717c14c4f95adcce9e27406d3d5aae
<?php
declare(strict_types=1);

namespace Lcobucci\JWT\Signer;

use Lcobucci\JWT\Signer;

use function hash_equals;
use function hash_hmac;
use function strlen;

abstract class Hmac implements Signer
{
    final public function sign(string $payload, Key $key): string
    {
        $actualKeyLength   = 8 * strlen($key->contents());
        $expectedKeyLength = $this->minimumBitsLengthForKey();
        if ($actualKeyLength < $expectedKeyLength) {
            throw InvalidKeyProvided::tooShort($expectedKeyLength, $actualKeyLength);
        }

        return hash_hmac($this->algorithm(), $payload, $key->contents(), true);
    }

    final public function verify(string $expected, string $payload, Key $key): bool
    {
        return hash_equals($expected, $this->sign($payload, $key));
    }

    abstract public function algorithm(): string;

    /** @return positive-int */
    abstract public function minimumBitsLengthForKey(): int;
}

The same content is in 158 releases, Joomla 5.0.0-alpha1 to 6.3.0-alpha1. See them all, or every version of this file.