<commit_before><?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * PHPUnit3.2 test framework script for the Crypt_GPG package.
 *
 * These tests require the PHPUnit 3.2 package to be installed. PHPUnit is
 * installable using PEAR. See the
 * {@link http://www.phpunit.de/pocket_guide/3.2/en/installation.html manual}
 * for detailed installation instructions.
 *
 * To run these tests, use:
 * <code>
 * $ phpunit PhpDriver
 * </code>
 *
 * LICENSE:
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of the
 * License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * @category  Encryption
 * @package   Crypt_GPG
 * @author    <NAME> <<EMAIL>>
 * @copyright 2005-2008 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 * @link      http://pear.php.net/package/Crypt_GPG
 */

/**
 * PHPUnit3 framework
 */
require_once 'PHPUnit/Framework.php';

/**
 * The Crypt_GPG class to test
 */
require_once 'Crypt/GPG.php';

/**
 * Tests the native PHP implementation of the Crypt_GPG object.
 *
 * @todo Aassert delete tests worked.
 * @todo Assert sign tests worked.
 * @todo Assert verify tests worked.
 * @todo Assert get public/private keys worked.
 * @todo Add tests for Exception API.
 */
class PhpDriver extends PHPUnit_Framework_TestCase
{
    // {{{ class constants

    const HOMEDIR = './test-keychain';

    // }}}
    // {{{ private properties

    private $_gpg;

    // }}}
    // {{{ setUp()

    public function setUp()
    {
        // {{{ pubring data
        $pubring_data = <<<TEXT
<KEY>

TEXT;
        // }}}
        // {{{ secring data
        $secring_data = <<<TEXT
<KEY>

TEXT;
        // }}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4ZeS8mgb3MBnxNI5109q6nzdpy+edZNK4pBWLd5
<KEY>

TEXT;
        // }}}

        mkdir(self::HOMEDIR);

        $pubring = fopen(self::HOMEDIR . '/pubring.gpg', 'wb');
        fwrite($pubring, base64_decode(str_replace("\n", '', $pubring_data)));
        fclose($pubring);

        $secring = fopen(self::HOMEDIR . '/secring.gpg', 'wb');
        fwrite($secring, base64_decode(str_replace("\n", '', $secring_data)));
        fclose($secring);

        $trustdb = fopen(self::HOMEDIR . '/trustdb.gpg', 'wb');
        fwrite($trustdb, base64_decode(str_replace("\n", '', $trustdb_data)));
        fclose($trustdb);

        $random_seed = fopen(self::HOMEDIR . '/random_seed', 'wb');
        fwrite($random_seed, base64_decode(
            str_replace("\n", '', $random_seed_data)));

        fclose($random_seed);

        $this->_gpg = Crypt_GPG::factory('php',
            array('homedir' => self::HOMEDIR));
    }

    // }}}
    // {{{ tearDown()

    public function tearDown()
    {
        unset($this->_gpg);

        if (file_exists(self::HOMEDIR . '/pubring.gpg~')) {
            unlink(self::HOMEDIR . '/pubring.gpg~');
        }

        if (file_exists(self::HOMEDIR . '/secring.gpg~')) {
            unlink(self::HOMEDIR . '/secring.gpg~');
        }

        if (file_exists(self::HOMEDIR . '/trustdb.gpg~')) {
            unlink(self::HOMEDIR . '/trustdb.gpg~');
        }

        unlink(self::HOMEDIR . '/pubring.gpg');
        unlink(self::HOMEDIR . '/secring.gpg');
        unlink(self::HOMEDIR . '/trustdb.gpg');
        unlink(self::HOMEDIR . '/random_seed');
        rmdir(self::HOMEDIR);
    }

    // }}}

    // tests
    // {{{ testImportPrivateKey()

    public function testImportPrivateKey()
    {
        $key_id = '<EMAIL>';

        // {{{ private key data
        $private_key_data = <<<TEXT
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: GnuPG v1.4.6 (GNU/Linux)

<KEY>
-----END PGP PRIVATE KEY BLOCK-----

TEXT;
        // }}}

        // delete key if it exists
        try {
            $this->_gpg->deletePrivateKey($key_id);
        } catch (Exception $e) {
        }

        $this->_gpg->importKey($private_key_data);
    }

    // }}}
    // {{{ testEncrypt()

    public function testEncrypt()
    {
        $data = 'Hello, Alice! Goodbye, Bob!';
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';

        $encrypted_data = $this->_gpg->encrypt($key_id, $data);
        $decrypted_data = $this->_gpg->decrypt($encrypted_data, $passphrase);

        $this->assertEquals($data, $decrypted_data);
    }

    //}}}
    // {{{ testDecrypt()

    public function testDecrypt()
    {
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';
        $data = 'Hello, Alice! Goodbye, Bob!';

        // {{{ encrypted data

        $encrypted_data = <<<TEXT
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.6 (GNU/Linux)

<KEY>
CVG1c1Y/vLYOXVgPeuHokwwTau0nmpKIOCxMUymBu8N66UK+8RvAPekoCLlKjNg0
<KEY>
-----END PGP MESSAGE-----

TEXT;
        // }}}

        $decrypted_data = $this->_gpg->decrypt($encrypted_data, $passphrase);
        $this->assertEquals($data, $decrypted_data);
    }

    // }}}
    // {{{ testDeletePublicKey()

    public function testDeletePublicKey()
    {
        $key_id = '<EMAIL>';
        $this->_gpg->deletePrivateKey($key_id);
        $this->_gpg->deletePublicKey($key_id);
    }

    // }}}
    // {{{ testDeletePrivateKey()

    public function testDeletePrivateKey()
    {
        $key_id = '<EMAIL>';
        $this->_gpg->deletePrivateKey($key_id);
    }

    // }}}
    // {{{ testNormalSign()

    public function testNormalSign()
    {
        $data = 'Hello, Alice! Goodbye, Bob!';
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';
        $signed_data = $this->_gpg->sign($key_id, $data, $passphrase);
    }

    // }}}
    // {{{ testClearSign()

    public function testClearSign()
    {
        $data = 'Hello, Alice! Goodbye, Bob!';
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';
        $signed_data = $this->_gpg->sign($key_id, $data, $passphrase,
            Crypt_GPG::SIGN_MODE_CLEAR);
    }

    // }}}
    // {{{ testDetachedSignature()

    public function testDetachedSignature()
    {
        $data = 'Hello, Alice! Goodbye, Bob!';
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';
        $signature_data = $this->_gpg->sign($key_id, $data, $passphrase,
            Crypt_GPG::SIGN_MODE_DETACHED);
    }

    // }}}
    // {{{ testVerifyNormalSignedData()

    public function testVerifyNormalSignedData()
    {
        // {{{ normal signed data
        $normal_signed_data = <<<TEXT
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.6 (GNU/Linux)

owGbwMvMwCRo4/yG5Z3E5jTG04pJDO6dpxw9UnNy8nUUHHMyk1MVFdzz81OSKlN1
FJzykxQ77JlZwWpgmgSZ2ooYFlwTFtr268isPxVt/Ud7nGdP/14t95dhntKV6UvZ
I7+eqPxjwKS5xPOpp8szTgA=
=AnIj
-----END PGP MESSAGE-----

TEXT;
        // }}}

        $signature = $this->_gpg->verify($normal_signed_data);
    }
<commit_msg>Clean up some tests and add unit tests for most exceptions.<commit_after><?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * PHPUnit3.2 test framework script for the Crypt_GPG package.
 *
 * These tests require the PHPUnit 3.2 package to be installed. PHPUnit is
 * installable using PEAR. See the
 * {@link http://www.phpunit.de/pocket_guide/3.2/en/installation.html manual}
 * for detailed installation instructions.
 *
 * To run these tests, use:
 * <code>
 * $ phpunit PhpDriver
 * </code>
 *
 * LICENSE:
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of the
 * License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * @category  Encryption
 * @package   Crypt_GPG
 * @author    <NAME> <<EMAIL>>
 * @copyright 2005-2008 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 * @link      http://pear.php.net/package/Crypt_GPG
 */

/**
 * PHPUnit3 framework
 */
require_once 'PHPUnit/Framework.php';

/**
 * The Crypt_GPG class to test
 */
require_once 'Crypt/GPG.php';

/**
 * Tests the native PHP implementation of the Crypt_GPG object.
 *
 * @todo Aassert delete tests worked.
 * @todo Assert sign tests worked.
 * @todo Assert verify tests worked.
 * @todo Assert get public/private keys worked.
 * @todo Add tests for encrypt() Exception API.
 * @todo Add tests for sign() Exception API.
 */
class PhpDriver extends PHPUnit_Framework_TestCase
{
    // {{{ class constants

    const HOMEDIR = './test-keychain';

    // }}}
    // {{{ private properties

    private $_gpg;

    // }}}
    // {{{ setUp()

    public function setUp()
    {
        // {{{ pubring data
        $pubring_data = <<<TEXT
<KEY>

TEXT;
        // }}}
        // {{{ secring data
        $secring_data = <<<TEXT
<KEY>

TEXT;
        // }}}
        // {{{ trustdb data
        $trustdb_data = <<<TEXT
AWdwZwMDAQUBAAAAR4nAbAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQoAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAoAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADABrvPK9dKSoLw3eE5c8
Q+wE7hizZgAAAAAAAAAfAAAAAAAAAAAAAA0AysbMxl08eg2k9oEgzz2Nnf/w
QncAAAAAAAAAAAAAAAAAAAAAAAA=

TEXT;
        // }}}
        // {{{ random_seed data
        $random_seed_data = <<<TEXT
psHHMYiKI5UfHNUp1mQf9oNSGguXQ47Us6ouzC8T/PMMOKSgNbXg+2SnHJWl
sNrDYPiQKxXT7wxM186v7K2Krub0nSKXclSMniBJG1Joo0vcuJOlDS<KEY>

TEXT;
        // }}}

        mkdir(self::HOMEDIR);

        $pubring = fopen(self::HOMEDIR . '/pubring.gpg', 'wb');
        fwrite($pubring, base64_decode(str_replace("\n", '', $pubring_data)));
        fclose($pubring);

        $secring = fopen(self::HOMEDIR . '/secring.gpg', 'wb');
        fwrite($secring, base64_decode(str_replace("\n", '', $secring_data)));
        fclose($secring);

        $trustdb = fopen(self::HOMEDIR . '/trustdb.gpg', 'wb');
        fwrite($trustdb, base64_decode(str_replace("\n", '', $trustdb_data)));
        fclose($trustdb);

        $random_seed = fopen(self::HOMEDIR . '/random_seed', 'wb');
        fwrite($random_seed, base64_decode(
            str_replace("\n", '', $random_seed_data)));

        fclose($random_seed);

        $this->_gpg = Crypt_GPG::factory('php',
            array('homedir' => self::HOMEDIR));
    }

    // }}}
    // {{{ tearDown()

    public function tearDown()
    {
        unset($this->_gpg);

        if (file_exists(self::HOMEDIR . '/pubring.gpg~')) {
            unlink(self::HOMEDIR . '/pubring.gpg~');
        }

        if (file_exists(self::HOMEDIR . '/secring.gpg~')) {
            unlink(self::HOMEDIR . '/secring.gpg~');
        }

        if (file_exists(self::HOMEDIR . '/trustdb.gpg~')) {
            unlink(self::HOMEDIR . '/trustdb.gpg~');
        }

        unlink(self::HOMEDIR . '/pubring.gpg');
        unlink(self::HOMEDIR . '/secring.gpg');
        unlink(self::HOMEDIR . '/trustdb.gpg');
        unlink(self::HOMEDIR . '/random_seed');
        rmdir(self::HOMEDIR);
    }

    // }}}

    // tests
    // {{{ testImportKeyPrivateKey()

    public function testImportKeyPrivateKey()
    {
        $key_id = '<EMAIL>';

        // {{{ private key data
        $private_key_data = <<<TEXT
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: GnuPG v1.4.6 (GNU/Linux)

<KEY>
-----END PGP PRIVATE KEY BLOCK-----

TEXT;
        // }}}

        // delete key if it exists
        try {
            $this->_gpg->deletePrivateKey($key_id);
        } catch (Exception $e) {
        }

        $this->_gpg->importKey($private_key_data);
    }

    // }}}
    // {{{ testImportKeyDuplicateKeyImportException()

    /**
     * @expectedException Crypt_GPG_DuplicateKeyImportException
     */
    public function testImportKeyDuplicateKeyImportException()
    {
        // {{{ private key data
        $private_key_data = <<<TEXT
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: GnuPG v1.4.6 (GNU/Linux)

<KEY>
-----END PGP PRIVATE KEY BLOCK-----

TEXT;
        // }}}

        $this->_gpg->importKey($private_key_data);
    }

    // }}}
    // {{{ testImportKeyNoDataException()

    /**
     * @expectedException Crypt_GPG_NoDataException()
     */
    public function testImportKeyNoDataException()
    {
        $key_data = 'Invalid OpenPGP data.';
        $this->_gpg->importKey($key_data);
    }

    // }}}
    // {{{ testExportPublicKey()

    public function testExportPublicKey()
    {
        $key_id = '<EMAIL>';

        // {{{ expected key data
        $expected_key_data = <<<TEXT
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.6 (GNU/Linux)

<KEY>
=QS+L
-----END PGP PUBLIC KEY BLOCK-----

TEXT;
        // }}}

        $key_data = $this->_gpg->exportPublicKey($key_id);
        $this->assertEquals($expected_key_data, $key_data);
    }

    // }}}
    // {{{ testExportPublicKeyNotFoundException()

    /**
     * @expectedException Crypt_GPG_KeyNotFoundException
     */
    public function testExportPublicKeyNotFoundException()
    {
        $key_id = '<EMAIL>';
        $key_data = $this->_gpg->exportPublicKey($key_id);
    }

    // }}}
    // {{{ testEncrypt()

    public function testEncrypt()
    {
        $data = 'Hello, Alice! Goodbye, Bob!';
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';

        $encrypted_data = $this->_gpg->encrypt($key_id, $data);
        $decrypted_data = $this->_gpg->decrypt($encrypted_data, $passphrase);

        $this->assertEquals($data, $decrypted_data);
    }

    //}}}
    // {{{ testDecrypt()

    public function testDecrypt()
    {
        $passphrase = '<PASSWORD>';
        $expected_decrypted_data = 'Hello, Alice! Goodbye, Bob!';

        // {{{ encrypted data

        $encrypted_data = <<<TEXT
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.6 (GNU/Linux)

<KEY>
-----END PGP MESSAGE-----

TEXT;
        // }}}

        $decrypted_data = $this->_gpg->decrypt($encrypted_data, $passphrase);
        $this->assertEquals($expected_decrypted_data, $decrypted_data);
    }

    // }}}
    // {{{ testDecryptKeyNotFoundException()

    /**
     * @expectedException Crypt_GPG_KeyNotFoundException
     */
    public function testDecryptKeyNotFoundException()
    {
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';

        // {{{ encrypted data

        $encrypted_data = <<<TEXT
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.6 (GNU/Linux)

hQIOA9iRsCBTswBBEAgA48W4igBuoGyFW9IMrWl7CEfUKwC/rRXJbK1MbESlHsA0
CVG1c1Y/vLYOXVgPeuHokwwTau0nmpKIOCxMUymBu8N66UK+8RvAPekoCLlKjNg0
iOVPu+62bPvVWHgKvWM4Kj2MKXGhC1m4OaHonaDffVMTmsa4ndEUoOV9TQb/nBNt
L7JZ+N/KXie9nIoqJgvA1Gb0zuMkFUsLaJ+e3HThRyQUyzZ7k5LLBOTgEKW3urtK
m9lOPTyqOCKEsNflT3XI3823do3EF//damROGNLtMcI92vQA2cY/X3reoJjN5Nb+
yLOVkSjVGxJIXE2tPtKwJC6dELy2xTCPL0aagliqiQgAzB6/NLfos89XD4y3cvcq
a8pfdKwGd9fsUGFtntd8Jf8moWOkLJbh1vRUyxn5eSJKHiu52FjrOCSQOWLax/qZ
RHQM1h1MK6isLHysLgq6naLUyJVXmpL9HSrUYaCP4+jefNeC2nRAonYAr18nfAHF
1AiRzDE3+MDy8vRZLWOitsrhqYDrCyg+x7qvgLjK5F5SSc8ZwyE3Rlee+NbRjXH3
fzAE/l6P9GlZrZUL5inEUDBm+DB/LQcnB9K32XD/7Lkeh92Ih6d/Ykbctc0bzuD4
CnkU/rA4z5e8s81CopOW65FchxkLK8YFGf623IURbrga7sVW0wj13AbLcmVO5fiS
xNJWASwiaUHH6Lll3gHdcJJlMW9THKzOk2UzV56t4ZaqJPrYwWMONHS60P+UVtl2
HQpCFn/UK5EjrXyd9DHdYHGRL2n8O3xjhu1GVuuA4sb3B46nKzxXzcU=
=q3cD
-----END PGP MESSAGE-----

TEXT;
        // }}}

        $this->_gpg->deletePrivateKey($key_id);
        $decrypted_data = $this->_gpg->decrypt($encrypted_data, $passphrase);
    }

    // }}}
    // {{{ testDecryptNoDataException()

    /**
     * @expectedException Crypt_GPG_NoDataException
     */
    public function testDecryptNoDataException()
    {
        $passphrase = '<PASSWORD>';
        $encrypted_data = 'Invalid OpenPGP data.';
        $decrypted_data = $this->_gpg->decrypt($encrypted_data, $passphrase);
    }

    // }}}
    // {{{ testDecryptBadPassphraseException_missing()

    /**
     * @expectedException Crypt_GPG_BadPassphraseException
     */
    public function testDecryptBadPassphraseException_missing()
    {
        // {{{ encrypted data

        $encrypted_data = <<<TEXT
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.6 (GNU/Linux)

hQIOA9iRsCBTswBBEAgA48W4igBuoGyFW9IMrWl7CEfUKwC/rRXJbK1MbESlHsA0
CV<KEY>
-----END PGP MESSAGE-----

TEXT;
        // }}}

        $decrypted_data = $this->_gpg->decrypt($encrypted_data);
    }

    // }}}
    // {{{ testDecryptBadPassphraseException_bad()

    /**
     * @expectedException Crypt_GPG_BadPassphraseException
     */
    public function testDecryptBadPassphraseException_bad()
    {
        $passphrase = '<PASSWORD>';

        // {{{ encrypted data

        $encrypted_data = <<<TEXT
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.6 (GNU/Linux)

hQIOA9iRsCBTswBBEAgA48W4igBuoGyFW9IMrWl7CEfUKwC/rRXJbK1MbESlHsA0
CVG1c1Y/vLYOXVgPeuHokwwTau0nmpKIOCxMUymBu8N66UK+8RvAPekoCLlKjNg0
iOVPu+62bPvVWHgKvWM4Kj2MKXGhC1m4OaHonaDffVMTmsa4ndEUoOV9TQb/nBNt
L7JZ+N/KXie9nIoqJgvA1Gb0zuMkFUsLaJ+e3HThRyQUyzZ7k5LLBOTgEKW3urtK
m9lOPTyqOCKEsNflT3XI3823do3EF//damROGNLtMcI92vQA2cY/X3reoJjN5Nb+
yLOVkSjVGxJIXE2tPtKwJC6dELy2xTCPL0aagliqiQgAzB6/NLfos89XD4y3cvcq
a8pfdKwGd9fsUGFtntd8Jf8moWOkLJbh1vRUyxn5eSJKHiu52FjrOCSQOWLax/qZ
RHQM1h1MK6isLHysLgq6naLUyJVXmpL9HSrUYaCP4+jefNeC2nRAonYAr18nfAHF
1AiRzDE3+MDy8vRZLWOitsrhqYDrCyg+x7qvgLjK5F5SSc8ZwyE3Rlee+NbRjXH3
fzAE/l6P9GlZrZUL5inEUDBm+DB/LQcnB9K32XD/7Lkeh92Ih6d/Ykbctc0bzuD4
CnkU/rA4z5e8s81CopOW65FchxkLK8YFGf623IURbrga7sVW0wj13AbLcmVO5fiS
xNJWASwiaUHH6Lll3gHdcJJlMW9THKzOk2UzV56t4ZaqJPrYwWMONHS60P+UVtl2
HQpCFn/UK5EjrXyd9DHdYHGRL2n8O3xjhu1GVuuA4sb3B46nKzxXzcU=
=q3cD
-----END PGP MESSAGE-----

TEXT;
        // }}}

        $decrypted_data = $this->_gpg->decrypt($encrypted_data, $passphrase);
    }

    // }}}
    // {{{ testDeletePublicKey()

    public function testDeletePublicKey()
    {
        $key_id = '<EMAIL>';
        $this->_gpg->deletePrivateKey($key_id);
        $this->_gpg->deletePublicKey($key_id);
    }

    // }}}
    // {{{ testDeletePublicKeyNotFoundException()

    /**
     * @expectedException Crypt_GPG_KeyNotFoundException
     */
    public function testDeletePublicKeyNotFoundException()
    {
        $key_id = '<EMAIL>';
        $this->_gpg->deletePublicKey($key_id);
    }

    // }}}
    // {{{ testDeletePrivateKey()

    public function testDeletePrivateKey()
    {
        $key_id = '<EMAIL>';
        $this->_gpg->deletePrivateKey($key_id);
    }

    // }}}
    // {{{ testDeletePrivateKeyNotFoundException()

    /**
     * @expectedException Crypt_GPG_KeyNotFoundException
     */
    public function testDeletePrivateKeyNotFoundException()
    {
        $key_id = '<EMAIL>';
        $this->_gpg->deletePrivateKey($key_id);
    }

    // }}}
    // {{{ testNormalSign()

    public function testNormalSign()
    {
        $data = 'Hello, Alice! Goodbye, Bob!';
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';
        $signed_data = $this->_gpg->sign($key_id, $data, $passphrase);
    }

    // }}}
    // {{{ testClearSign()

    public function testClearSign()
    {
        $data = 'Hello, Alice! Goodbye, Bob!';
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';
        $signed_data = $this->_gpg->sign($key_id, $data, $passphrase,
            Crypt_GPG::SIGN_MODE_CLEAR);
    }

    // }}}
    // {{{ testDetachedSignature()

    public function testDetachedSignature()
    {
        $data = 'Hello, Alice! Goodbye, Bob!';
        $key_id = '<EMAIL>';
        $passphrase = '<PASSWORD>';
        $signature_data = $this->_gpg->sign($key_id, $data, $passphrase,
            Crypt_GPG::SIGN_MODE_DETACHED);
    }

    // }}}
    // {{{ testVerifyNoDataException()

    /**
     * @expectedException Crypt_GPG_NoDataException
     */
    public function testVerifyNoDataException()
    {
        $signed_data = 'Invalid OpenPGP data.';
        $signature = $this->_gpg->verify($signed_data);
    }

    // }}}
    // {{{ testVerifyNormalSignedData()

    public function testVerifyNormalSignedData()
    {
        // {{{ normal signed data
        $normal_signed_data = <<<TEXT
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.6 (GNU/Linux)

owGbwMvMwCRo4/yG5Z3E5jTG04pJDO6dpxw9UnNy8nUUHHMyk1MVFdzz81OSKlN1
FJzykxQ77JlZwWpgmgSZ2ooYFlwTFtr268isPxVt/Ud7nGdP/14t95dhntKV6UvZ
I7+eqPxjwKS5xPOpp8szTgA=
=AnIj
-----END PGP MESSAGE-----

TEXT;
        // }}}

        $signature = $this->_gpg->verify($normal_signed_data);
    }

{'fraction_non_alphanumeric': 0.12662272010353057, 'fraction_numerical': 0.02179803453714563, 'mean_word_length': 3.310266689907617, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 104, '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': '5245054', 'n_tokens_mistral': 9077, 'n_tokens_neox': 8530, 'n_words': 1364}