<commit_before><?php
/**
 * \Elabftw\Elabftw\TrustedTimestamps
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME>
 * @copyright 2015 <NAME>, <NAME>
 * @see https://www.elabftw.net Official website
 * @license AGPL-3.0
 * @package elabftw
 */
namespace Elabftw\Elabftw;

use \DateTime;
use \Exception;
use \Elabftw\Elabftw\Update;
use Defuse\Crypto\Crypto as Crypto;
use Defuse\Crypto\Key as Key;

/**
 * Timestamp an experiment with RFC 3161
 * Based on:
 * http://www.d-mueller.de/blog/dealing-with-trusted-timestamps-in-php-rfc-3161
 */
class TrustedTimestamps extends Entity
{
    /** instance of Config*/
    private $Config;

    /** array with config of the team */
    private $teamConfigArr;

    /** our database connection */
    protected $pdo;

    /** instance of Entity */
    public $Entity;

    /** ELAB_ROOT . uploads/ . $pdfFileName */
    private $pdfPath;
    /** elabid-timestamped.pdf */
    private $pdfRealName;
    /** a hash */
    private $pdfLongName;

    /** config (url, login, password, cert) */
    private $stampParams = array();
    /** things that get deleted with destruct method */
    private $tmpfiles = array();

    /** where we store the request file */
    private $requestfilePath;
    /** where we store the asn1 token */
    private $responsefilePath;

    /** our answer from TSA */
    private $binaryResponseString;
    /** the time of the timestamp */
    private $responseTime;

    /** hash algo for file */
    private $hashAlgorithm = 'sha256';

    /**
     * Give me an experiment id and a db and I make good pdf for you
     *
     * @param Config $config
     * @param Teams $teams
     * @param int $id The id of the experiment
     */
    public function __construct(Config $config, Teams $teams, Entity $entity)
    {
        $this->Config = $config;
        $this->Entity = $entity;
        $this->teamConfigArr = $teams->read();

        $this->pdo = Db::getConnection();

        // will be used in sqlUpdate()
        $this->setId($id);
        $this->canOrExplode('write');

        $this->generatePdf();

        // initialize with info from config
        $this->stampParams = $this->getTimestampParameters();
    }

    /**
     * Delete all temporary files created by TrustedTimestamps
     *
     */
    public function __destruct()
    {
        foreach ($this->tmpfiles as $file) {
            unlink($file);
        }
    }

    /**
     * Generate the pdf to timestamp.
     *
     * @throws Exception if it cannot make the pdf
     */
    private function generatePdf()
    {
        try {<commit_msg>fix setId<commit_after><?php
/**
 * \Elabftw\Elabftw\TrustedTimestamps
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME>
 * @copyright 2015 <NAME>, <NAME>
 * @see https://www.elabftw.net Official website
 * @license AGPL-3.0
 * @package elabftw
 */
namespace Elabftw\Elabftw;

use \DateTime;
use \Exception;
use \Elabftw\Elabftw\Update;
use Defuse\Crypto\Crypto as Crypto;
use Defuse\Crypto\Key as Key;

/**
 * Timestamp an experiment with RFC 3161
 * Based on:
 * http://www.d-mueller.de/blog/dealing-with-trusted-timestamps-in-php-rfc-3161
 */
class TrustedTimestamps extends Entity
{
    /** instance of Config*/
    private $Config;

    /** array with config of the team */
    private $teamConfigArr;

    /** our database connection */
    protected $pdo;

    /** instance of Entity */
    public $Entity;

    /** ELAB_ROOT . uploads/ . $pdfFileName */
    private $pdfPath;
    /** elabid-timestamped.pdf */
    private $pdfRealName;
    /** a hash */
    private $pdfLongName;

    /** config (url, login, password, cert) */
    private $stampParams = array();
    /** things that get deleted with destruct method */
    private $tmpfiles = array();

    /** where we store the request file */
    private $requestfilePath;
    /** where we store the asn1 token */
    private $responsefilePath;

    /** our answer from TSA */
    private $binaryResponseString;
    /** the time of the timestamp */
    private $responseTime;

    /** hash algo for file */
    private $hashAlgorithm = 'sha256';

    /**
     * Give me an experiment id and a db and I make good pdf for you
     *
     * @param Config $config
     * @param Teams $teams
     * @param int $id The id of the experiment
     */
    public function __construct(Config $config, Teams $teams, Entity $entity)
    {
        $this->Config = $config;
        $this->Entity = $entity;
        $this->teamConfigArr = $teams->read();

        $this->pdo = Db::getConnection();

        // will be used in sqlUpdate()
        $this->setId($this->Entity->id);
        $this->canOrExplode('write');

        $this->generatePdf();

        // initialize with info from config
        $this->stampParams = $this->getTimestampParameters();
    }

    /**
     * Delete all temporary files created by TrustedTimestamps
     *
     */
    public function __destruct()
    {
        foreach ($this->tmpfiles as $file) {
            unlink($file);
        }
    }

    /**
     * Generate the pdf to timestamp.
     *
     * @throws Exception if it cannot make the pdf
     */
    private function generatePdf()
    {
        try {
{'fraction_non_alphanumeric': 0.13256704980842912, 'fraction_numerical': 0.006896551724137931, 'mean_word_length': 2.3771021992238035, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '2742293', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1582, 'n_words': 467}