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)); } /** * @internal * * @return non-empty-string */ abstract public function algorithm(): string; /** * @internal * * @return positive-int */ abstract public function minimumBitsLengthForKey(): int; }