<commit_before><?php

namespace SimpleDAV;

class CSRFToken {

    const Timeout = 1200; // 20 Minutes

    private static function clearExpired() {
        if (!isset($_SESSION['csrf'])) {
            return;
        }

        $expiration = \time() - self::Timeout;
        foreach ($_SESSION['csrf'] as $token => $time) {
            if ($time < $expiration) {
                unset($_SESSION['csrf'][$token]);
            }
        }
    }

    public static function generate() {
        if (empty($_SESSION['csrf'])) {
            $_SESSION['csrf'] = [];
        }

        $token = \hash('sha256', \mcrypt_create_iv(16, \MCRYPT_DEV_URANDOM));
        $_SESSION['csrf'][$token] = \time();
        return $token;
    }

    public static function check($token) {
        self::clearExpired();

        if (!isset($token)) {
            return false;
        }

        $expiration = time() - self::Timeout;
        return isset($_SESSION['csrf'][$token]) && $_SESSION['csrf'][$token] >= $expiration;
    }

}<commit_msg>convert csrf timeout constant to uppercase<commit_after><?php

namespace SimpleDAV;

class CSRFToken {

    const TIMEOUT = 1200; // 20 Minutes

    private static function clearExpired() {
        if (!isset($_SESSION['csrf'])) {
            return;
        }

        $expiration = \time() - self::TIMEOUT;
        foreach ($_SESSION['csrf'] as $token => $time) {
            if ($time < $expiration) {
                unset($_SESSION['csrf'][$token]);
            }
        }
    }

    public static function generate() {
        if (empty($_SESSION['csrf'])) {
            $_SESSION['csrf'] = [];
        }

        $token = \hash('sha256', \mcrypt_create_iv(16, \MCRYPT_DEV_URANDOM));
        $_SESSION['csrf'][$token] = \time();
        return $token;
    }

    public static function check($token) {
        self::clearExpired();

        if (!isset($token)) {
            return false;
        }

        $expiration = time() - self::TIMEOUT;
        return isset($_SESSION['csrf'][$token]) && $_SESSION['csrf'][$token] >= $expiration;
    }

}
{'fraction_non_alphanumeric': 0.16642616642616642, 'fraction_numerical': 0.010582010582010581, 'mean_word_length': 2.076923076923077, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3694990', 'n_tokens_mistral': 646, 'n_tokens_neox': 611, 'n_words': 125}