<commit_before><?php

namespace SpomkyLabs\Jose\Tests;

use Base64Url\Base64Url;
use SpomkyLabs\Jose\Algorithm\ContentEncryption\A128GCM;
use SpomkyLabs\Jose\Algorithm\ContentEncryption\A192GCM;
use SpomkyLabs\Jose\Algorithm\ContentEncryption\A256GCM;

class AESGCMContentEncryptionTest extends \PHPUnit_Framework_TestCase
{
    public function testA128GCMEncryptAndDecrypt()
    {
        $header = array("alg" => "ECDH-ES", "enc" => "A128GCM");
        $tag = null;

        $algorithm = new A128GCM();

        $cek                 = openssl_random_pseudo_bytes(128/8);
        $iv                  = openssl_random_pseudo_bytes(96/8);
        $plaintext           = "<NAME> Charlie";

        $cyphertext = $algorithm->encryptContent($plaintext, $cek, $iv, null, $header, $tag);

        $this->assertNotNull($tag);
        $this->assertEquals($plaintext, $algorithm->decryptContent($cyphertext, $cek, $iv, null, $header, $tag));
    }

    public function testA192GCMEncryptAndDecrypt()
    {
        $header = array("alg" => "ECDH-ES", "enc" => "A192GCM");
        $tag = null;

        $algorithm = new A192GCM();

        $cek                 = openssl_random_pseudo_bytes(192/8);
        $iv                  = openssl_random_pseudo_bytes(96/8);
        $plaintext           = "<NAME> Charlie";

        $cyphertext = $algorithm->encryptContent($plaintext, $cek, $iv, null, $header, $tag);

        $this->assertNotNull($tag);
        $this->assertEquals($plaintext, $algorithm->decryptContent($cyphertext, $cek, $iv, null, $header, $tag));
    }

    public function testA256GCMEncryptAndDecrypt()
    {
        $header = array("alg" => "ECDH-ES", "enc" => "A256GCM");
        $tag = null;

        $algorithm = new A256GCM();

        $cek                 = openssl_random_pseudo_bytes(256/8);
        $iv                  = openssl_random_pseudo_bytes(96/8);
        $plaintext           = "<NAME> Charlie";

        $cyphertext = $algorithm->encryptContent($plaintext, $cek, $iv, null, $header, $tag);

        $this->assertNotNull($tag);
        $this->assertEquals($plaintext, $algorithm->decryptContent($cyphertext, $cek, $iv, null, $header, $tag));
    }

    /**
     * @see https://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-39#appendix-A.1
     */
    public function testA256GCMDecryptTestVector()
    {
        $algorithm = new A256GCM();

        $header              = array("alg" => "RSA-OAEP", "enc" => "A256GCM");<commit_msg>Some HHVM tests mark as incomplete<commit_after><?php

namespace SpomkyLabs\Jose\Tests;

use Base64Url\Base64Url;
use SpomkyLabs\Jose\Algorithm\ContentEncryption\A128GCM;
use SpomkyLabs\Jose\Algorithm\ContentEncryption\A192GCM;
use SpomkyLabs\Jose\Algorithm\ContentEncryption\A256GCM;

class AESGCMContentEncryptionTest extends \PHPUnit_Framework_TestCase
{
    public function testA128GCMEncryptAndDecrypt()
    {
        if (true === $this->isHHVM()) {
            $this->markTestIncomplete("PHP Crypto extension not available on HHVM.");
            return;
        }
        $header = array("alg" => "ECDH-ES", "enc" => "A128GCM");
        $tag = null;

        $algorithm = new A128GCM();

        $cek                 = openssl_random_pseudo_bytes(128/8);
        $iv                  = openssl_random_pseudo_bytes(96/8);
        $plaintext           = "<NAME> Charlie";

        $cyphertext = $algorithm->encryptContent($plaintext, $cek, $iv, null, $header, $tag);

        $this->assertNotNull($tag);
        $this->assertEquals($plaintext, $algorithm->decryptContent($cyphertext, $cek, $iv, null, $header, $tag));
    }

    public function testA192GCMEncryptAndDecrypt()
    {
        if (true === $this->isHHVM()) {
            $this->markTestIncomplete("PHP Crypto extension not available on HHVM.");
            return;
        }
        $header = array("alg" => "ECDH-ES", "enc" => "A192GCM");
        $tag = null;

        $algorithm = new A192GCM();

        $cek                 = openssl_random_pseudo_bytes(192/8);
        $iv                  = openssl_random_pseudo_bytes(96/8);
        $plaintext           = "<NAME>";

        $cyphertext = $algorithm->encryptContent($plaintext, $cek, $iv, null, $header, $tag);

        $this->assertNotNull($tag);
        $this->assertEquals($plaintext, $algorithm->decryptContent($cyphertext, $cek, $iv, null, $header, $tag));
    }

    public function testA256GCMEncryptAndDecrypt()
    {
        if (true === $this->isHHVM()) {
            $this->markTestIncomplete("PHP Crypto extension not available on HHVM.");
            return;
        }
        $header = array("alg" => "ECDH-ES", "enc" => "A256GCM");
        $tag = null;

        $algorithm = new A256GCM();

        $cek                 = openssl_random_pseudo_bytes(256/8);
        $iv                  = openssl_random_pseudo_bytes(96/8);
        $plaintext           = "<NAME>";

        $cyphertext = $algorithm->encryptContent($plaintext, $cek, $iv, null, $header, $tag);

        $this->assertNotNull($tag);
        $this->assertEquals($plaintext, $algorithm->decryptContent($cyphertext, $cek, $iv, null, $header, $tag));
    }

    /**
     * @see https://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-39#appendix-A.1
     */
    public function testA256GCMDecryptTestVector()
    {
        if (true === $this->isHHVM()) {
            $this->markTestIncomplete("PHP Crypto extension not available on HHVM.");
            return;
        }
        $algorithm = new A256GCM();

        $header              = array("alg" => "RSA-OAEP", "enc" => "A256GCM");
{'fraction_non_alphanumeric': 0.14930742939377586, 'fraction_numerical': 0.02626371649577262, 'mean_word_length': 2.49685534591195, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 57, 'https://': 2, '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': '4424987', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1776, 'n_words': 312}