CoreFiles by mySites.guru
ChallengeOptions.php55 lines, 1,705 bytes, from Joomla_6.2.0-rc2-Release_Candidate-Full_Package.zip
Raw History Compare with 6.2.0-rc1
md5
bdd036f78571033c6ea0056acce516ff
sha1
368b68899f8fe02de768a0332ae7c8538a5743e3
sha256
1c628a2887e21b1b963f5ba5b3397a12c3c19861b1a6d30c3f785459be0cd36d
<?php

declare(strict_types=1);

namespace AltchaOrg\Altcha;

use AltchaOrg\Altcha\Hasher\Algorithm;

/**
 * @phpstan-import-type ChallengeParams from BaseChallengeOptions
 */
class ChallengeOptions extends BaseChallengeOptions
{
    private const DEFAULT_SALT_LENGTH = 12;

    /**
     * Options for creation of a new challenge with sane defaults.
     *
     * @param int                     $maxNumber  Maximum number for the random number generator (default: 1,000,000)
     * @param Algorithm               $algorithm  Hashing algorithm to use (`SHA-1`, `SHA-256`, `SHA-512`, default:
     *                                            `SHA-256`).
     * @param null|\DateTimeInterface $expires    Optional expiration time for the challenge.
     * @param ChallengeParams         $params     Optional URL-encoded query parameters.
     * @param int<1, max>             $saltLength Length of the random salt (default: 12 bytes).
     */
    public function __construct(
        Algorithm $algorithm = Algorithm::SHA256,
        int $maxNumber = self::DEFAULT_MAX_NUMBER,
        ?\DateTimeInterface $expires = null,
        array $params = [],
        int $saltLength = self::DEFAULT_SALT_LENGTH,
    ) {
        parent::__construct(
            $algorithm,
            $maxNumber,
            $expires,
            bin2hex(self::randomBytes($saltLength)),
            self::randomInt($maxNumber),
            $params
        );
    }

    private static function randomInt(int $max): int
    {
        return random_int(0, $max);
    }

    /**
     * @param int<1, max> $length
     */
    private static function randomBytes(int $length): string
    {
        return random_bytes($length);
    }
}

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