<commit_before><?php

class JOSE_JWS_Test extends JOSE_TestCase {
    var $plain_jwt;
    var $rsa_keys;

    function setUp() {
        parent::setUp();
        $this->plain_jwt = new JOSE_JWT(array(
            'foo' => 'bar'
        ));

    }

    function testSignHS256() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign('shared-secret', 'HS256');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignHS384() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign('shared-secret', 'HS384');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignHS512() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign('shared-secret', 'HS512');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignRS256() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'RS256');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignRS384() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'RS384');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignRS512() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'RS512');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignPS256() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'PS256');
        # NOTE: RSA-PSS generates different signature each time
        $this->assertEquals(explode('.', $expected)[0], explode('.', $jws->toString())[0]);
    }

    function testSignPS384() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'PS384');
        # NOTE: RSA-PSS generates different signature each time
        $this->assertEquals(explode('.', $expected)[0], explode('.', $jws->toString())[0]);
    }

    function testSignPS512() {
        $expected = '<KEY>9Dxy8fw';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'PS512');
        # NOTE: RSA-PSS generates different signature each time
        $this->assertEquals(explode('.', $expected)[0], explode('.', $jws->toString())[0]);
    }

    function testSignRS256WithInvalidPrivateKey() {
        $jws = new JOSE_JWS($this->plain_jwt);
        $this->setExpectedException('JOSE_Exception');
        $jws = $jws->sign('invalid pem', 'RS256');
    }

    function testSignES256() {
        $jws = new JOSE_JWS($this->plain_jwt);
        $this->setExpectedException('JOSE_Exception_UnexpectedAlgorithm');
        $jws = $jws->sign('es key should be here', 'ES256');
    }

    function testSignUnknowAlg() {
        $jws = new JOSE_JWS($this->plain_jwt);<commit_msg>php 5.3 is too legacy<commit_after><?php

class JOSE_JWS_Test extends JOSE_TestCase {
    var $plain_jwt;
    var $rsa_keys;

    function setUp() {
        parent::setUp();
        $this->plain_jwt = new JOSE_JWT(array(
            'foo' => 'bar'
        ));

    }

    function testSignHS256() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign('shared-secret', 'HS256');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignHS384() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign('shared-secret', 'HS384');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignHS512() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign('shared-secret', 'HS512');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignRS256() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'RS256');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignRS384() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'RS384');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignRS512() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'RS512');
        $this->assertEquals($expected, $jws->toString());
    }

    function testSignPS256() {
        $expected = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJQUzI1NiJ9.eyJmb28iOiJiYXIifQ.jukVdy99ZcyKvnkeeZ96c9J8c8FhyAO1ElSn6qHYzxTOjUXWxaaOU_5PZBA-_Bl7SUiLUGS4zv_C2IuH6ZN70MO2omWTcCV544Z2ZesMGsm5ll3kdPeaqtaj1IafDujDRmAJHpUoH2F3GXRAcSmVtj8c9VwJocVdeS-L43wa7uaymT330GRyKajWh8huwMZdgSVJemxct4Y-N2saDvLiVDQwjDWjxNP_eaAh-VFf6sIsK-BRcSRJr-GhwqGcpsvkE7OGbissYlB0fvl6MgxP_fic8ka84SQzX7WcM_zuEgI_J6O4CGPG21lQhJp-Fmme_a7RVDmu0F2kg3cGk81nYA';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'PS256');
        # NOTE: RSA-PSS generates different signature each time
        $expected_segments = explode('.', $expected);
        $given_segments = explode('.', $jws->toString());
        $this->assertEquals($expected_segments[0], $given_segments[0]);
        $this->assertEquals($expected_segments[1], $given_segments[1]);
    }

    function testSignPS384() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'PS384');
        # NOTE: RSA-PSS generates different signature each time
        $expected_segments = explode('.', $expected);
        $given_segments = explode('.', $jws->toString());
        $this->assertEquals($expected_segments[0], $given_segments[0]);
        $this->assertEquals($expected_segments[1], $given_segments[1]);
    }

    function testSignPS512() {
        $expected = '<KEY>';
        $jws = new JOSE_JWS($this->plain_jwt);
        $jws = $jws->sign($this->rsa_keys['private'], 'PS512');
        # NOTE: RSA-PSS generates different signature each time
        $expected_segments = explode('.', $expected);
        $given_segments = explode('.', $jws->toString());
        $this->assertEquals($expected_segments[0], $given_segments[0]);
        $this->assertEquals($expected_segments[1], $given_segments[1]);
    }

    function testSignRS256WithInvalidPrivateKey() {
        $jws = new JOSE_JWS($this->plain_jwt);
        $this->setExpectedException('JOSE_Exception');
        $jws = $jws->sign('invalid pem', 'RS256');
    }

    function testSignES256() {
        $jws = new JOSE_JWS($this->plain_jwt);
        $this->setExpectedException('JOSE_Exception_UnexpectedAlgorithm');
        $jws = $jws->sign('es key should be here', 'ES256');
    }

    function testSignUnknowAlg() {
        $jws = new JOSE_JWS($this->plain_jwt);
{'fraction_non_alphanumeric': 0.17775006927126627, 'fraction_numerical': 0.02978664449986146, 'mean_word_length': 3.0601799775028122, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 125, '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': '2606248', 'n_tokens_mistral': 2706, 'n_tokens_neox': 2540, 'n_words': 381}