<commit_before><?php

namespace SocialiteProviders\Jira;

use League\OAuth1\Client\Signature\Signature;
use League\OAuth1\Client\Signature\SignatureInterface;

class RsaSha1Signature extends Signature implements SignatureInterface
{
    private $certPath = '';

    /**
     * {@inheritdoc}
     */
    public function method()
    {
        return 'RSA-SHA1';
    }

    /**
     * {@inheritdoc}
     */
    public function sign($uri, array $parameters = [], $method = 'POST')
    {
        $url = $this->createUrl($uri);
        $baseString = $this->baseString($url, $method, $parameters);

        // Fetch the private key cert based on the request
        $certificate = openssl_pkey_get_private("file://$this->certPath");

        if ($certificate === false) {
            throw new \Exception('Cannot get private key.');
        }

        // Pull the private key ID from the certificate
        $privatekeyid = openssl_get_privatekey($certificate);

        // Sign using the key
        openssl_sign($baseString, $signature, $privatekeyid);

        // Release the key resource
        openssl_free_key($privatekeyid);

        return base64_encode($signature);
    }

    /**
     * Set cert path.
     *
     * @param $certPath
     */
    public function setCertPath($certPath)
    {
        $this->certPath = $certPath;
    }

    /**
     * Create a Guzzle url for the given URI.
     *
     * @param string $uri
     *
     * @return Url
     */
    protected function createUrl($uri)
    {
        $theUri = new \GuzzleHttp\Psr7\Uri($uri);

        return $theUri;
    }

    /**
     * Generate a base string for a RSA-SHA1 signature
     * based on the given a url, method, and any parameters.
     *
     * @param Url    $url
     * @param string $method
     * @param array  $parameters
     *
     * @return string
     */
    protected function baseString(Url $url, $method = 'POST', array $parameters = [])
    {
        $baseString = rawurlencode($method).'&';
        $schemeHostPath = $url->getScheme().'://'.$url->getHost();
        if ($url->getPort() != '') {
            $schemeHostPath .= ':'.$url->getPort();
        }
        if ($url->getPath() != '') {
            $schemeHostPath .= $url->getPath();
        }
        $baseString .= rawurlencode($schemeHostPath).'&';

        $data = [];
        parse_str($url->getQuery(), $query);<commit_msg>[Jira] Fixes a type error (#25)<commit_after><?php

namespace SocialiteProviders\Jira;

use GuzzleHttp\Psr7\Uri;
use League\OAuth1\Client\Signature\Signature;
use League\OAuth1\Client\Signature\SignatureInterface;

class RsaSha1Signature extends Signature implements SignatureInterface
{
    private $certPath = '';

    /**
     * {@inheritdoc}
     */
    public function method()
    {
        return 'RSA-SHA1';
    }

    /**
     * {@inheritdoc}
     */
    public function sign($uri, array $parameters = [], $method = 'POST')
    {
        $url = $this->createUrl($uri);
        $baseString = $this->baseString($url, $method, $parameters);

        // Fetch the private key cert based on the request
        $certificate = openssl_pkey_get_private("file://$this->certPath");

        if ($certificate === false) {
            throw new \Exception('Cannot get private key.');
        }

        // Pull the private key ID from the certificate
        $privatekeyid = openssl_get_privatekey($certificate);

        // Sign using the key
        openssl_sign($baseString, $signature, $privatekeyid);

        // Release the key resource
        openssl_free_key($privatekeyid);

        return base64_encode($signature);
    }

    /**
     * Set cert path.
     *
     * @param $certPath
     */
    public function setCertPath($certPath)
    {
        $this->certPath = $certPath;
    }

    /**
     * Create a Guzzle url for the given URI.
     *
     * @param string $uri
     *
     * @return Uri
     */
    protected function createUrl($uri)
    {
        $theUri = new Uri($uri);

        return $theUri;
    }

    /**
     * Generate a base string for a RSA-SHA1 signature
     * based on the given a url, method, and any parameters.
     *
     * @param Url    $url
     * @param string $method
     * @param array  $parameters
     *
     * @return string
     */
    protected function baseString(Uri $url, $method = 'POST', array $parameters = [])
    {
        $baseString = rawurlencode($method).'&';
        $schemeHostPath = $url->getScheme().'://'.$url->getHost();
        if ($url->getPort() != '') {
            $schemeHostPath .= ':'.$url->getPort();
        }
        if ($url->getPath() != '') {
            $schemeHostPath .= $url->getPath();
        }
        $baseString .= rawurlencode($schemeHostPath).'&';

        $data = [];
        parse_str($url->getQuery(), $query);
{'fraction_non_alphanumeric': 0.14229001253656498, 'fraction_numerical': 0.0037609694943585457, 'mean_word_length': 2.151415404871626, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '3371133', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1397, 'n_words': 334}