CoreFiles by mySites.guru
BaseChallengeOptions.php48 lines, 1,101 bytes, from Joomla_6.2.0-beta3-Beta-Full_Package.zip
Raw History Compare with 6.2.0-beta2
md5
925d7b877ac23d8597462426387c28d6
sha1
b0774b0acf3d484039be27af2225e3eb7ab0b50d
sha256
381cae01ccd4787155c06efad1efcfd451a8fecbd8d83bf1eee0a902fc28ba51
<?php

declare(strict_types=1);

namespace AltchaOrg\Altcha;

use AltchaOrg\Altcha\Hasher\Algorithm;

/**
 * @phpstan-type ChallengeParams array<string, null|scalar>
 */
class BaseChallengeOptions
{
    public const DEFAULT_MAX_NUMBER = 1000000;

    public readonly string $salt;

    /**
     * Options for creation of a new challenge.
     *
     * @see ChallengeOptions for options with sane defaults.
     *
     * @param ChallengeParams $params
     */
    public function __construct(
        public readonly Algorithm $algorithm,
        public readonly int $maxNumber,
        public readonly ?\DateTimeInterface $expires,
        string $salt,
        public readonly int $number,
        public readonly array $params,
    ) {
        if ($expires) {
            $params['expires'] = $expires->getTimestamp();
        }

        if (!empty($params)) {
            $salt .= '?' . http_build_query($params);
        }

        // Add a delimiter to prevent parameter splicing
        if (!str_ends_with($salt, '&')) {
            $salt .= '&';
        }

        $this->salt = $salt;
    }
}

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