diff --git a/.gitattributes b/.gitattributes
index ee19259..69f425c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -3,4 +3,5 @@ tools/ export-ignore
.gitattributes export-ignore
.github/ export-ignore
.gitignore export-ignore
+.php-cs-fixer.php export-ignore
phpstan.neon export-ignore
\ No newline at end of file
diff --git a/.github/workflows/tests_24.yaml b/.github/workflows/tests_24.yaml
index 3bbff01..7916c78 100644
--- a/.github/workflows/tests_24.yaml
+++ b/.github/workflows/tests_24.yaml
@@ -1,4 +1,4 @@
-name: GnuPG 2.4 + phpstan
+name: GnuPG 2.4 + SA + CS
on:
push:
@@ -36,6 +36,9 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress
+ - name: Execute php-cs-fixer
+ run: php vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --diff --verbose --allow-unsupported-php-version=yes
+
- name: Execute phpstan
run: php -dmemory_limit=256M vendor/bin/phpstan analyse -v
diff --git a/.gitignore b/.gitignore
index c0f18a7..4418b7c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ tests/config.php
tests/debug.log
tests/test-keychain/
tests/.phpunit.result.cache
+.php-cs-fixer.cache
diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
new file mode 100644
index 0000000..6649333
--- /dev/null
+++ b/.php-cs-fixer.php
@@ -0,0 +1,13 @@
+in(__DIR__)
+;
+
+return (new PhpCsFixer\Config())
+ ->setRules([
+ '@PER-CS' => true,
+ '@PHP8x1Migration' => true,
+ ])
+ ->setFinder($finder)
+;
diff --git a/Crypt/GPG.php b/Crypt/GPG.php
index a895578..794682b 100644
--- a/Crypt/GPG.php
+++ b/Crypt/GPG.php
@@ -2,46 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Crypt_GPG is a package to use GPG from PHP
- *
- * This package provides an object oriented interface to GNU Privacy
- * Guard (GPG). It requires the GPG executable to be on the system.
- *
- * Though GPG can support symmetric-key cryptography, this package is intended
- * only to facilitate public-key cryptography.
- *
- * This file contains the main GPG class. The class in this file lets you
- * encrypt, decrypt, sign and verify data; import and delete keys; and perform
- * other useful GPG tasks.
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Nathan Fredrickson
- * @author Michael Gauthier
- * @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @link http://pear.php.net/manual/en/package.encryption.crypt-gpg.php
- * @link http://www.gnupg.org/
- */
-
namespace Crypt;
use Crypt\GPG\Engine;
@@ -65,9 +25,9 @@
* @author Nathan Fredrickson
* @author Michael Gauthier
* @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @link http://www.gnupg.org/
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
+ * @link https://www.gnupg.org/
*/
class GPG
{
@@ -80,7 +40,7 @@ class GPG
* @see self::sign()
* @see self::signFile()
*/
- const SIGN_MODE_NORMAL = 1;
+ public const SIGN_MODE_NORMAL = 1;
/**
* Signing mode for clearsigning data. Clearsigned signatures are ASCII
@@ -91,7 +51,7 @@ class GPG
* @see self::sign()
* @see self::signFile()
*/
- const SIGN_MODE_CLEAR = 2;
+ public const SIGN_MODE_CLEAR = 2;
/**
* Signing mode for creating a detached signature. When using detached
@@ -103,7 +63,7 @@ class GPG
* @see self::sign()
* @see self::signFile()
*/
- const SIGN_MODE_DETACHED = 3;
+ public const SIGN_MODE_DETACHED = 3;
/**
* No formatting is performed.
@@ -112,7 +72,7 @@ class GPG
*
* @see self::getFingerprint()
*/
- const FORMAT_NONE = 1;
+ public const FORMAT_NONE = 1;
/**
* Fingerprint is formatted in the format used by the GnuPG gpg command's
@@ -122,63 +82,61 @@ class GPG
*
* @see self::getFingerprint()
*/
- const FORMAT_CANONICAL = 2;
+ public const FORMAT_CANONICAL = 2;
/**
- * Fingerprint is formatted in the format used when displaying X.509
- * certificates
+ * Fingerprint is formatted in the format used when displaying X.509 certificates
*
* Example: C3:BC:61:5A:D9:C7:66:E5:A8:5C:1F:27:16:D2:74:58:B1:BB:A1:C4
*
* @see self::getFingerprint()
*/
- const FORMAT_X509 = 3;
+ public const FORMAT_X509 = 3;
/**
* Use to specify ASCII armored mode for returned data
*/
- const ARMOR_ASCII = true;
+ public const ARMOR_ASCII = true;
/**
* Use to specify binary mode for returned data
*/
- const ARMOR_BINARY = false;
+ public const ARMOR_BINARY = false;
/**
* Use to specify that line breaks in signed text should be normalized
*/
- const TEXT_NORMALIZED = true;
+ public const TEXT_NORMALIZED = true;
/**
* Use to specify that line breaks in signed text should not be normalized
*/
- const TEXT_RAW = false;
+ public const TEXT_RAW = false;
/**
* Error code returned when there is no error.
*/
- const ERROR_NONE = 0;
+ public const ERROR_NONE = 0;
/**
* Error code returned when an unknown or unhandled error occurs.
*/
- const ERROR_UNKNOWN = 1;
+ public const ERROR_UNKNOWN = 1;
/**
* Error code returned when a bad passphrase is used.
*/
- const ERROR_BAD_PASSPHRASE = 2;
+ public const ERROR_BAD_PASSPHRASE = 2;
/**
* Error code returned when a required passphrase is missing.
*/
- const ERROR_MISSING_PASSPHRASE = 3;
+ public const ERROR_MISSING_PASSPHRASE = 3;
/**
- * Error code returned when a key that is already in the keyring is
- * imported.
+ * Error code returned when a key that is already in the keyring is imported.
*/
- const ERROR_DUPLICATE_KEY = 4;
+ public const ERROR_DUPLICATE_KEY = 4;
/**
* Error code returned the required data is missing for an operation.
@@ -186,55 +144,54 @@ class GPG
* This could be missing key data, missing encrypted data or missing
* signature data.
*/
- const ERROR_NO_DATA = 5;
+ public const ERROR_NO_DATA = 5;
/**
* Error code returned when an unsigned key is used.
*/
- const ERROR_UNSIGNED_KEY = 6;
+ public const ERROR_UNSIGNED_KEY = 6;
/**
* Error code returned when a key that is not self-signed is used.
*/
- const ERROR_NOT_SELF_SIGNED = 7;
+ public const ERROR_NOT_SELF_SIGNED = 7;
/**
* Error code returned when a public or private key that is not in the
* keyring is used.
*/
- const ERROR_KEY_NOT_FOUND = 8;
+ public const ERROR_KEY_NOT_FOUND = 8;
/**
* Error code returned when an attempt to delete public key having a
* private key is made.
*/
- const ERROR_DELETE_PRIVATE_KEY = 9;
+ public const ERROR_DELETE_PRIVATE_KEY = 9;
/**
* Error code returned when one or more bad signatures are detected.
*/
- const ERROR_BAD_SIGNATURE = 10;
+ public const ERROR_BAD_SIGNATURE = 10;
/**
* Error code returned when there is a problem reading GnuPG data files.
*/
- const ERROR_FILE_PERMISSIONS = 11;
+ public const ERROR_FILE_PERMISSIONS = 11;
/**
* Error code returned when a key could not be created.
*/
- const ERROR_KEY_NOT_CREATED = 12;
+ public const ERROR_KEY_NOT_CREATED = 12;
/**
- * Error code returned when bad key parameters are used during key
- * generation.
+ * Error code returned when bad key parameters are used during key generation.
*/
- const ERROR_BAD_KEY_PARAMS = 13;
+ public const ERROR_BAD_KEY_PARAMS = 13;
/**
* URI at which package bugs may be reported.
*/
- const BUG_URI = 'https://github.com/pear/Crypt_GPG/issues';
+ public const BUG_URI = 'https://github.com/pear/Crypt_GPG/issues';
/**
* Engine used to control the GPG subprocess
@@ -251,10 +208,10 @@ class GPG
* The array is of the form:
*
* [
- * $key_id => array(
+ * $key_id => [
* 'fingerprint' => $fingerprint,
* 'passphrase' => null
- * )
+ * ]
* ];
*
*
@@ -270,10 +227,10 @@ class GPG
* The array is of the form:
*
* [
- * $key_id => array(
+ * $key_id => [
* 'fingerprint' => $fingerprint,
* 'passphrase' => $passphrase
- * )
+ * ]
* ];
*
*
@@ -289,10 +246,10 @@ class GPG
* The array is of the form:
*
* [
- * $key_id => array(
+ * $key_id => [
* 'fingerprint' => $fingerprint,
* 'passphrase' => $passphrase
- * )
+ * ]
* ];
*
*
@@ -303,7 +260,7 @@ class GPG
protected $decryptKeys = [];
/**
- * Passphrases used on import/export of private keys in GnuPG 2.1
+ * Passphrases used on import/export of private keys
*
* The array is of the form:
*
@@ -421,8 +378,7 @@ public function getKeyEditor()
* Imports a public or private key into the keyring
*
* Keys may be removed from the keyring using
- * {@link self::deletePublicKey()} or
- * {@link self::deletePrivateKey()}.
+ * {@link self::deletePublicKey()} or {@link self::deletePrivateKey()}.
*
* @param string $data the key data to be imported.
*
@@ -461,8 +417,7 @@ public function importKey($data)
* Imports a public or private key file into the keyring
*
* Keys may be removed from the keyring using
- * {@link self::deletePublicKey()} or
- * {@link self::deletePrivateKey()}.
+ * {@link self::deletePublicKey()} or {@link self::deletePrivateKey()}.
*
* @param string $filename the key file to be imported.
*
@@ -574,10 +529,6 @@ public function exportPublicKey($keyId, $armor = true)
* $keyId (for example, if you use a non-unique uid) only the
* first public key is deleted.
*
- * The private key must be deleted first or an exception will be thrown.
- * In GnuPG >= 2.1 this limitation does not exist.
- * See {@link self::deletePrivateKey()}.
- *
* @param string $keyId either the full uid of the public key, the email
* part of the uid of the public key or the key id of
* the public key. For example,
@@ -612,7 +563,7 @@ public function deletePublicKey($keyId)
$operation = '--delete-key -- ' . escapeshellarg($fingerprint);
$arguments = [
'--batch',
- '--yes'
+ '--yes',
];
$this->engine->reset();
@@ -629,7 +580,7 @@ public function deletePublicKey($keyId)
*
* Calls GPG with the --delete-secret-key command.
*
- * @param string $keyId either the full uid of the private key, the email
+ * @param string $keyId Either the full uid of the private key, the email
* part of the uid of the private key or the key id of
* the private key. For example,
* "Test User (example) ",
@@ -659,7 +610,7 @@ public function deletePrivateKey($keyId)
$operation = '--delete-secret-key -- ' . escapeshellarg($fingerprint);
$arguments = [
'--batch',
- '--yes'
+ '--yes',
];
$this->engine->reset();
@@ -680,15 +631,12 @@ public function deletePrivateKey($keyId)
* a user id, a key id or a key fingerprint. If not
* specified, all keys are returned.
*
- * @return array an array of {@link \Crypt\GPG\Key} objects. If no keys
- * match the specified $keyId an empty array is
- * returned.
+ * @return array A list of keys. If no keys match the specified $keyId
+ * an empty array is returned.
*
* @throws Exceptions\Exception if an unknown or unexpected error occurs.
* Use the debug option and file a bug report if these
* exceptions occur.
- *
- * @see \Crypt\GPG\Key
*/
public function getKeys($keyId = '')
{
@@ -731,7 +679,7 @@ public function getFingerprint($keyId, $format = self::FORMAT_NONE)
$operation = '--list-keys -- ' . escapeshellarg($keyId);
$arguments = [
'--with-colons',
- '--with-fingerprint'
+ '--with-fingerprint',
];
$this->engine->reset();
@@ -747,16 +695,16 @@ public function getFingerprint($keyId, $format = self::FORMAT_NONE)
$fingerprint = $lineExp[9];
switch ($format) {
- case self::FORMAT_CANONICAL:
- $fingerprintExp = str_split($fingerprint, 4);
- $format = '%s %s %s %s %s %s %s %s %s %s';
- $fingerprint = vsprintf($format, $fingerprintExp);
- break;
-
- case self::FORMAT_X509:
- $fingerprintExp = str_split($fingerprint, 2);
- $fingerprint = implode(':', $fingerprintExp);
- break;
+ case self::FORMAT_CANONICAL:
+ $fingerprintExp = str_split($fingerprint, 4);
+ $format = '%s %s %s %s %s %s %s %s %s %s';
+ $fingerprint = vsprintf($format, $fingerprintExp);
+ break;
+
+ case self::FORMAT_X509:
+ $fingerprintExp = str_split($fingerprint, 2);
+ $fingerprint = implode(':', $fingerprintExp);
+ break;
}
break;
@@ -779,13 +727,11 @@ public function getLastSignatureInfo()
/**
* Encrypts string data
*
- * Data is ASCII armored by default but may optionally be returned as
- * binary.
+ * Data is ASCII-armored by default, but may optionally be returned as binary.
*
* @param string $data the data to be encrypted.
* @param bool $armor optional. If true, ASCII armored data is returned;
- * otherwise, binary data is returned. Defaults to
- * true.
+ * otherwise, binary data is returned. Defaults to true.
*
* @return string the encrypted data.
*
@@ -806,8 +752,7 @@ public function encrypt($data, $armor = self::ARMOR_ASCII)
/**
* Encrypts a file
*
- * Encrypted data is ASCII armored by default but may optionally be saved
- * as binary.
+ * Encrypted data is ASCII-armored by default, but may optionally be saved as binary.
*
* @param string $filename the filename of the file to encrypt.
* @param string $encryptedFile optional. The filename of the file in
@@ -818,7 +763,7 @@ public function encrypt($data, $armor = self::ARMOR_ASCII)
* returned; otherwise, binary data is
* returned. Defaults to true.
*
- * @return void|string if the $encryptedFile parameter is null,
+ * @return string|null If the $encryptedFile parameter is null,
* a string containing the encrypted data is returned.
*
* @throws Exceptions\KeyNotFoundException if no encryption key is specified.
@@ -882,14 +827,12 @@ public function encryptAndSign($data, $armor = self::ARMOR_ASCII)
* returned; otherwise, binary data is returned.
* Defaults to true.
*
- * @return void|string if the $signedFile parameter is null, a
- * string containing the encrypted, signed data is
- * returned.
+ * @return string|null if the $signedFile parameter is null, a
+ * string containing the encrypted, signed data is returned.
*
* @throws Exceptions\KeyNotFoundException if no encryption key is specified
* or if no signing key is specified. See
- * {@link self::addEncryptKey()} and
- * {@link self::addSignKey()}.
+ * {@link self::addEncryptKey()} and {@link self::addSignKey()}.
*
* @throws Exceptions\BadPassphraseException if a specified passphrase is
* incorrect or if a required passphrase is not specified.
@@ -903,11 +846,8 @@ public function encryptAndSign($data, $armor = self::ARMOR_ASCII)
*
* @see self::decryptAndVerifyFile()
*/
- public function encryptAndSignFile(
- $filename,
- $signedFile = null,
- $armor = self::ARMOR_ASCII
- ) {
+ public function encryptAndSignFile($filename, $signedFile = null, $armor = self::ARMOR_ASCII)
+ {
return $this->_encryptAndSign($filename, true, $signedFile, $armor);
}
@@ -957,7 +897,7 @@ public function decrypt($encryptedData)
* or unspecified, the decrypted data is
* returned as a string.
*
- * @return void|string if the $decryptedFile parameter is null,
+ * @return string|null if the $decryptedFile parameter is null,
* a string containing the decrypted data is returned.
*
* @throws Exceptions\KeyNotFoundException if the private key needed to
@@ -1161,12 +1101,8 @@ public function getVersion()
* Use the debug option and file a bug report if these
* exceptions occur.
*/
- public function sign(
- $data,
- $mode = self::SIGN_MODE_NORMAL,
- $armor = self::ARMOR_ASCII,
- $textmode = self::TEXT_RAW
- ) {
+ public function sign($data, $mode = self::SIGN_MODE_NORMAL, $armor = self::ARMOR_ASCII, $textmode = self::TEXT_RAW)
+ {
return $this->_sign($data, false, null, $mode, $armor, $textmode);
}
@@ -1204,10 +1140,9 @@ public function sign(
* mode self::SIGN_MODE_CLEAR is
* used as clear-signing always uses textmode.
*
- * @return void|string if the $signedFile parameter is null, a
+ * @return string|null if the $signedFile parameter is null, a
* string containing the signed data (or the signature
- * data if a detached signature is requested) is
- * returned.
+ * data if a detached signature is requested) is returned.
*
* @throws Exceptions\KeyNotFoundException if no signing key is specified.
* See {@link self::addSignKey()}.
@@ -1229,14 +1164,7 @@ public function signFile(
$armor = self::ARMOR_ASCII,
$textmode = self::TEXT_RAW
) {
- return $this->_sign(
- $filename,
- true,
- $signedFile,
- $mode,
- $armor,
- $textmode
- );
+ return $this->_sign($filename, true, $signedFile, $mode, $armor, $textmode);
}
/**
@@ -1252,7 +1180,7 @@ public function signFile(
* signature data. The data that was signed is
* specified in $signedData.
*
- * @return array an array of {@link \Crypt\GPG\Signature} objects for the
+ * @return array An array of {@link \Crypt\GPG\Signature} objects for the
* signed data. For each signature that is valid, the
* {@link \Crypt\GPG\Signature::isValid()} will return true.
*
@@ -1265,8 +1193,6 @@ public function signFile(
* @throws Exceptions\Exception if an unknown or unexpected error occurs.
* Use the debug option and file a bug report if these
* exceptions occur.
- *
- * @see \Crypt\GPG\Signature
*/
public function verify($signedData, $signature = '')
{
@@ -1286,7 +1212,7 @@ public function verify($signedData, $signature = '')
* signature data. The file that was signed is
* specified in $filename.
*
- * @return array an array of {@link \Crypt\GPG\Signature} objects for the
+ * @return array An array of {@link \Crypt\GPG\Signature} objects for the
* signed data. For each signature that is valid, the
* {@link \Crypt\GPG\Signature::isValid()} will return true.
*
@@ -1301,8 +1227,6 @@ public function verify($signedData, $signature = '')
* @throws Exceptions\Exception if an unknown or unexpected error occurs.
* Use the debug option and file a bug report if these
* exceptions occur.
- *
- * @see \Crypt\GPG\Signature
*/
public function verifyFile($filename, $signature = '')
{
@@ -1381,11 +1305,11 @@ public function addSignKey($key, $passphrase = null)
}
/**
- * Register a private key passphrase for import/export (GnuPG 2.1)
+ * Register a private key passphrase for import/export.
*
- * @param mixed $key The key to use. This must be a key identifier,
- * or fingerprint.
- * @param string $passphrase The passphrase of the key.
+ * @param string|Key $key The key to use. This must be a key identifier,
+ * or fingerprint or a Key object.
+ * @param string $passphrase The passphrase of the key.
*
* @return $this the current object, for fluent interface.
*
@@ -1524,22 +1448,21 @@ public function getWarnings()
* This handles resolving full key objects from the provided
* $key value.
*
- * @param array &$array The array to which the key should be added
- * @param bool $encrypt Whether or not the key must be able to
- * encrypt
- * @param bool $sign Whether or not the key must be able to sign
- * @param mixed $key The key to add. This may be a key identifier,
- * user id, fingerprint, {@link \Crypt\GPG\Key} or
- * {@link \Crypt\GPG\SubKey}
- * @param string $passphrase Optional passphrase associated with the key
+ * @param array &$array The array to which the key should be added
+ * @param bool $encrypt Whether or not the key must be able to
+ * encrypt
+ * @param bool $sign Whether or not the key must be able to sign
+ * @param string|Key|SubKey $key The key to add. This may be a key identifier,
+ * user id, fingerprint, {@link \Crypt\GPG\Key} or
+ * {@link \Crypt\GPG\SubKey}
+ * @param string $passphrase Optional passphrase associated with the key
*
* @return void
*
* @sensitive $passphrase
*/
- protected function _addKey(array &$array, $encrypt, $sign, $key,
- $passphrase = null
- ) {
+ protected function _addKey(array &$array, $encrypt, $sign, $key, $passphrase = null)
+ {
$subKeys = [];
if (is_scalar($key)) {
@@ -1554,7 +1477,7 @@ protected function _addKey(array &$array, $encrypt, $sign, $key,
$key = $keys[0];
}
- if ($key instanceof \Crypt\GPG\Key) {
+ if ($key instanceof Key) {
if ($encrypt && !$key->canEncrypt()) {
throw new \InvalidArgumentException('Key "' . $key . '" cannot encrypt.');
}
@@ -1595,7 +1518,7 @@ protected function _addKey(array &$array, $encrypt, $sign, $key,
$array[$subKey->getId()] = [
'fingerprint' => $subKey->getFingerprint(),
- 'passphrase' => $passphrase
+ 'passphrase' => $passphrase,
];
}
}
@@ -1730,9 +1653,7 @@ protected function _exportKey($keyId, $armor = true, $private = false)
protected function _encrypt($data, $isFile, $outputFile, $armor)
{
if (!$this->hasEncryptKeys()) {
- throw new Exceptions\KeyNotFoundException(
- 'No encryption keys specified.'
- );
+ throw new Exceptions\KeyNotFoundException('No encryption keys specified.');
}
$input = $this->_prepareInput($data, $isFile);
@@ -1763,7 +1684,7 @@ protected function _encrypt($data, $isFile, $outputFile, $armor)
* data should be written. If null, the decrypted
* data is returned as a string.
*
- * @return void|string if the $outputFile parameter is null, a
+ * @return string|null if the $outputFile parameter is null, a
* string containing the decrypted data is returned.
*
* @throws Exceptions\KeyNotFoundException if the private key needed to
@@ -1795,9 +1716,7 @@ protected function _decrypt($data, $isFile, $outputFile)
$this->engine->setOutput($output);
$this->engine->run();
- if ($outputFile === null) {
- return $output;
- }
+ return $outputFile === null ? $output : null;
}
/**
@@ -1825,10 +1744,9 @@ protected function _decrypt($data, $isFile, $outputFile)
* mode self::SIGN_MODE_CLEAR is
* used as clear-signing always uses textmode.
*
- * @return void|string if the $outputFile parameter is null, a
+ * @return string|null if the $outputFile parameter is null, a
* string containing the signed data (or the signature
- * data if a detached signature is requested) is
- * returned.
+ * data if a detached signature is requested) is returned.
*
* @throws Exceptions\KeyNotFoundException if no signing key is specified.
* See {@link self::addSignKey()}.
@@ -1843,29 +1761,26 @@ protected function _decrypt($data, $isFile, $outputFile)
* Use the debug option and file a bug report if these
* exceptions occur.
*/
- protected function _sign($data, $isFile, $outputFile, $mode, $armor,
- $textmode
- ) {
+ protected function _sign($data, $isFile, $outputFile, $mode, $armor, $textmode)
+ {
if (!$this->hasSignKeys()) {
- throw new Exceptions\KeyNotFoundException(
- 'No signing keys specified.'
- );
+ throw new Exceptions\KeyNotFoundException('No signing keys specified.');
}
$input = $this->_prepareInput($data, $isFile);
$output = $this->_prepareOutput($outputFile, $input);
switch ($mode) {
- case self::SIGN_MODE_DETACHED:
- $operation = '--detach-sign';
- break;
- case self::SIGN_MODE_CLEAR:
- $operation = '--clearsign';
- break;
- case self::SIGN_MODE_NORMAL:
- default:
- $operation = '--sign';
- break;
+ case self::SIGN_MODE_DETACHED:
+ $operation = '--detach-sign';
+ break;
+ case self::SIGN_MODE_CLEAR:
+ $operation = '--clearsign';
+ break;
+ case self::SIGN_MODE_NORMAL:
+ default:
+ $operation = '--sign';
+ break;
}
$arguments = [];
@@ -1878,8 +1793,7 @@ protected function _sign($data, $isFile, $outputFile, $mode, $armor,
}
foreach ($this->signKeys as $key) {
- $arguments[] = '--local-user ' .
- escapeshellarg($key['fingerprint']);
+ $arguments[] = '--local-user ' . escapeshellarg($key['fingerprint']);
}
$this->engine->reset();
@@ -1889,9 +1803,7 @@ protected function _sign($data, $isFile, $outputFile, $mode, $armor,
$this->engine->setOperation($operation, $arguments);
$this->engine->run();
- if ($outputFile === null) {
- return $output;
- }
+ return $outputFile === null ? $output : null;
}
/**
@@ -1906,9 +1818,8 @@ protected function _sign($data, $isFile, $outputFile, $mode, $armor,
* @param bool $armor If true, ASCII armored data is returned;
* otherwise, binary data is returned.
*
- * @return void|string if the $outputFile parameter is null, a
- * string containing the encrypted, signed data is
- * returned.
+ * @return string|null if the $outputFile parameter is null, a
+ * string containing the encrypted, signed data is returned.
*
* @throws Exceptions\KeyNotFoundException if no encryption key is specified
* or if no signing key is specified. See
@@ -1954,9 +1865,7 @@ protected function _encryptAndSign($data, $isFile, $outputFile, $armor)
$this->engine->setOperation('--encrypt --sign', $arguments);
$this->engine->run();
- if ($outputFile === null) {
- return $output;
- }
+ return $outputFile === null ? $output : null;
}
/**
@@ -1968,8 +1877,8 @@ protected function _encryptAndSign($data, $isFile, $outputFile, $armor)
* signature, this must be the detached signature
* data. Otherwise, specify ''.
*
- * @return array an array of {@link \Crypt\GPG\Signature} objects for the
- * signed data.
+ * @return array An array of {@link \Crypt\GPG\Signature} objects for the
+ * signed data.
*
* @throws Exceptions\KeyNotFoundException if the public key needed for
* signature verification is not in the user's keyring.
@@ -1982,8 +1891,6 @@ protected function _encryptAndSign($data, $isFile, $outputFile, $armor)
* @throws Exceptions\Exception if an unknown or unexpected error occurs.
* Use the debug option and file a bug report if these
* exceptions occur.
- *
- * @see \Crypt\GPG\Signature
*/
protected function _verify($data, $isFile, $signature)
{
@@ -1992,7 +1899,7 @@ protected function _verify($data, $isFile, $signature)
$arguments = [];
} else {
// Signed data goes in FD_MESSAGE, detached signature data goes in FD_INPUT.
- $operation = '--verify - "-&' . Engine::FD_MESSAGE. '"';
+ $operation = '--verify - "-&' . Engine::FD_MESSAGE . '"';
$arguments = ['--enable-special-filenames'];
}
@@ -2053,8 +1960,6 @@ protected function _verify($data, $isFile, $signature)
* @throws Exceptions\Exception if an unknown or unexpected error occurs.
* Use the debug option and file a bug report if these
* exceptions occur.
- *
- * @see \Crypt\GPG\Signature
*/
protected function _decryptAndVerify($data, $isFile, $outputFile, $ignoreVerifyErrors = false)
{
@@ -2069,16 +1974,10 @@ protected function _decryptAndVerify($data, $isFile, $outputFile, $ignoreVerifyE
$this->engine->setProcessData('IgnoreVerifyErrors', $ignoreVerifyErrors);
$this->engine->run();
- $return = [
- 'data' => null,
- 'signatures' => $this->engine->getProcessData('Signatures')
+ return [
+ 'data' => $outputFile === null ? $output : null,
+ 'signatures' => $this->engine->getProcessData('Signatures'),
];
-
- if ($outputFile === null) {
- $return['data'] = $output;
- }
-
- return $return;
}
/**
@@ -2094,15 +1993,13 @@ protected function _decryptAndVerify($data, $isFile, $outputFile, $ignoreVerifyE
* a user id, a key id or a key fingerprint. If not
* specified, all keys are returned.
*
- * @return array an array of {@link \Crypt\GPG\Key} objects. If no keys
- * match the specified $keyId an empty array is
- * returned.
+ * @return array An array of {@link \Crypt\GPG\Key} objects. If no keys
+ * match the specified $keyId an empty array is
+ * returned.
*
* @throws Exceptions\Exception if an unknown or unexpected error occurs.
* Use the debug option and file a bug report if these
* exceptions occur.
- *
- * @see \Crypt\GPG\Key
*/
protected function _getKeys($keyId = '')
{
@@ -2143,7 +2040,7 @@ protected static function _parseListOutput($output)
$userId = null; // current user-id
foreach (explode(PHP_EOL, $output) as $line) {
- list($type) = explode(':', $line, 2);
+ [$type] = explode(':', $line, 2);
if ($type == 'pub') {
// new primary key means last key should be added to the array
diff --git a/Crypt/GPG/Engine.php b/Crypt/GPG/Engine.php
index b595869..93de2fb 100644
--- a/Crypt/GPG/Engine.php
+++ b/Crypt/GPG/Engine.php
@@ -2,38 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Crypt_GPG is a package to use GPG from PHP
- *
- * This file contains an engine that handles GPG subprocess control and I/O.
- * PHP's process manipulation functions are used to handle the GPG subprocess.
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Nathan Fredrickson
- * @author Michael Gauthier
- * @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @link http://www.gnupg.org/
- */
-
namespace Crypt\GPG;
use Crypt\GPG;
@@ -59,9 +27,8 @@
* @author Nathan Fredrickson
* @author Michael Gauthier
* @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @link http://www.gnupg.org/
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class Engine
{
@@ -73,25 +40,25 @@ class Engine
*
* @see https://pear.php.net/bugs/bug.php?id=21077
*/
- const CHUNK_SIZE = 65536;
+ public const CHUNK_SIZE = 65536;
/**
* Standard input file descriptor. This is used to pass data to the GPG
* process.
*/
- const FD_INPUT = 0;
+ public const FD_INPUT = 0;
/**
* Standard output file descriptor. This is used to receive normal output
* from the GPG process.
*/
- const FD_OUTPUT = 1;
+ public const FD_OUTPUT = 1;
/**
* Standard output file descriptor. This is used to receive error output
* from the GPG process.
*/
- const FD_ERROR = 2;
+ public const FD_ERROR = 2;
/**
* GPG status output file descriptor. The status file descriptor outputs
@@ -100,24 +67,24 @@ class Engine
* {@link http://www.gnupg.org/download/ GPG package} for a detailed
* description of GPG's status output.
*/
- const FD_STATUS = 3;
+ public const FD_STATUS = 3;
/**
* Command input file descriptor. This is used for methods requiring
* passphrases.
*/
- const FD_COMMAND = 4;
+ public const FD_COMMAND = 4;
/**
* Extra message input file descriptor. This is used for passing signed
* data when verifying a detached signature.
*/
- const FD_MESSAGE = 5;
+ public const FD_MESSAGE = 5;
/**
* Minimum version of GnuPG that is supported.
*/
- const MIN_VERSION = '2.2.0';
+ public const MIN_VERSION = '2.2.0';
/**
* Whether or not to use strict mode
@@ -143,9 +110,7 @@ class Engine
* This can be set to a callable function where first argument is the
* debug line to process.
*
- * Debugging is off by default.
- *
- * @var mixed
+ * @var bool|callable
* @see self::__construct()
*/
private $_debug = false;
@@ -392,7 +357,7 @@ public function __construct(array $options = [])
// get homedir
if (array_key_exists('homedir', $options)) {
- $this->_homedir = (string)$options['homedir'];
+ $this->_homedir = (string) $options['homedir'];
} else {
if (extension_loaded('posix')) {
// note: this requires the package OS dep exclude 'windows'
@@ -408,26 +373,26 @@ public function __construct(array $options = [])
if ($this->_homedir === false) {
throw new Exceptions\FileException(
- 'Could not locate homedir. Please specify the homedir ' .
- 'to use with the \'homedir\' option when instantiating ' .
- 'the Crypt_GPG object.'
+ 'Could not locate homedir. Please specify the homedir '
+ . 'to use with the \'homedir\' option when instantiating '
+ . 'the Crypt\\GPG object.'
);
}
}
// attempt to create homedir if it does not exist
if (!is_dir($this->_homedir)) {
- if (@mkdir($this->_homedir, 0777, true)) {
+ if (@mkdir($this->_homedir, 0o777, true)) {
// Set permissions on homedir. Parent directories are created
// with 0777, homedir is set to 0700.
- chmod($this->_homedir, 0700);
+ chmod($this->_homedir, 0o700);
} else {
throw new Exceptions\FileException(
- 'The \'homedir\' "' . $this->_homedir . '" is not ' .
- 'readable or does not exist and cannot be created. This ' .
- 'can happen if \'homedir\' is not specified in the ' .
- 'Crypt_GPG options, Crypt_GPG is run as the web user, ' .
- 'and the web user has no home directory.',
+ 'The \'homedir\' "' . $this->_homedir . '" is not '
+ . 'readable or does not exist and cannot be created. This '
+ . 'can happen if \'homedir\' is not specified in the '
+ . 'Crypt\\GPG options, Crypt_GPG is run as the web user, '
+ . 'and the web user has no home directory.',
0,
$this->_homedir
);
@@ -437,20 +402,20 @@ public function __construct(array $options = [])
// check homedir permissions (See Bug #19833)
if (!is_executable($this->_homedir)) {
throw new Exceptions\FileException(
- 'The \'homedir\' "' . $this->_homedir . '" is not enterable ' .
- 'by the current user. Please check the permissions on your ' .
- 'homedir and make sure the current user can both enter and ' .
- 'write to the directory.',
+ 'The \'homedir\' "' . $this->_homedir . '" is not enterable '
+ . 'by the current user. Please check the permissions on your '
+ . 'homedir and make sure the current user can both enter and '
+ . 'write to the directory.',
0,
$this->_homedir
);
}
if (!is_writeable($this->_homedir)) {
throw new Exceptions\FileException(
- 'The \'homedir\' "' . $this->_homedir . '" is not writable ' .
- 'by the current user. Please check the permissions on your ' .
- 'homedir and make sure the current user can both enter and ' .
- 'write to the directory.',
+ 'The \'homedir\' "' . $this->_homedir . '" is not writable '
+ . 'by the current user. Please check the permissions on your '
+ . 'homedir and make sure the current user can both enter and '
+ . 'write to the directory.',
0,
$this->_homedir
);
@@ -458,19 +423,19 @@ public function __construct(array $options = [])
// get binary
if (array_key_exists('binary', $options)) {
- $this->_binary = (string)$options['binary'];
+ $this->_binary = (string) $options['binary'];
} elseif (array_key_exists('gpgBinary', $options)) {
// deprecated alias
- $this->_binary = (string)$options['gpgBinary'];
+ $this->_binary = (string) $options['gpgBinary'];
} else {
$this->_binary = $this->_getBinary();
}
if ($this->_binary == '' || !is_executable($this->_binary)) {
throw new Exceptions\Exception(
- 'GPG binary not found. If you are sure the GPG binary is ' .
- 'installed, please specify the location of the GPG binary ' .
- 'using the \'binary\' driver option.'
+ 'GPG binary not found. If you are sure the GPG binary is '
+ . 'installed, please specify the location of the GPG binary '
+ . 'using the \'binary\' driver option.'
);
}
@@ -489,39 +454,42 @@ public function __construct(array $options = [])
// get public keyring
if (array_key_exists('publicKeyring', $options)) {
- $this->_publicKeyring = (string)$options['publicKeyring'];
+ $this->_publicKeyring = (string) $options['publicKeyring'];
if (!is_readable($this->_publicKeyring)) {
throw new Exceptions\FileException(
- 'The \'publicKeyring\' "' . $this->_publicKeyring .
- '" does not exist or is not readable. Check the location ' .
- 'and ensure the file permissions are correct.',
- 0, $this->_publicKeyring
+ 'The \'publicKeyring\' "' . $this->_publicKeyring
+ . '" does not exist or is not readable. Check the location '
+ . 'and ensure the file permissions are correct.',
+ 0,
+ $this->_publicKeyring
);
}
}
// get private keyring
if (array_key_exists('privateKeyring', $options)) {
- $this->_privateKeyring = (string)$options['privateKeyring'];
+ $this->_privateKeyring = (string) $options['privateKeyring'];
if (!is_readable($this->_privateKeyring)) {
throw new Exceptions\FileException(
- 'The \'privateKeyring\' "' . $this->_privateKeyring .
- '" does not exist or is not readable. Check the location ' .
- 'and ensure the file permissions are correct.',
- 0, $this->_privateKeyring
+ 'The \'privateKeyring\' "' . $this->_privateKeyring
+ . '" does not exist or is not readable. Check the location '
+ . 'and ensure the file permissions are correct.',
+ 0,
+ $this->_privateKeyring
);
}
}
// get trust database
if (array_key_exists('trustDb', $options)) {
- $this->_trustDb = (string)$options['trustDb'];
+ $this->_trustDb = (string) $options['trustDb'];
if (!is_readable($this->_trustDb)) {
throw new Exceptions\FileException(
- 'The \'trustDb\' "' . $this->_trustDb .
- '" does not exist or is not readable. Check the location ' .
- 'and ensure the file permissions are correct.',
- 0, $this->_trustDb
+ 'The \'trustDb\' "' . $this->_trustDb
+ . '" does not exist or is not readable. Check the location '
+ . 'and ensure the file permissions are correct.',
+ 0,
+ $this->_trustDb
);
}
}
@@ -577,7 +545,7 @@ public function addErrorHandler($callback, array $args = [])
{
$this->_errorHandlers[] = [
'callback' => $callback,
- 'args' => $args
+ 'args' => $args,
];
}
@@ -598,7 +566,7 @@ public function addStatusHandler($callback, array $args = [])
{
$this->_statusHandlers[] = [
'callback' => $callback,
- 'args' => $args
+ 'args' => $args,
];
}
@@ -656,7 +624,7 @@ public function reset()
* This creates and manages the GPG subprocess.
* This will close input/output file handles.
*
- * The operation must be set with {@link Crypt_GPG_Engine::setOperation()}
+ * The operation must be set with {@link Crypt\GPG\Engine::setOperation()}
* before this method is called.
*
* @return void
@@ -671,8 +639,8 @@ public function run()
{
if ($this->_operation === '') {
throw new Exceptions\InvalidOperationException(
- 'No GPG operation specified. Use Crypt_GPG_Engine::setOperation() ' .
- 'before calling Crypt_GPG_Engine::run().'
+ 'No GPG operation specified. Use Crypt\\GPG\\Engine::setOperation() '
+ . 'before calling Crypt\\GPG\\Engine::run().'
);
}
@@ -692,7 +660,7 @@ public function run()
*/
public function setInput(&$input)
{
- $this->_input =& $input;
+ $this->_input = & $input;
}
/**
@@ -708,7 +676,7 @@ public function setInput(&$input)
*/
public function setMessage(&$message)
{
- $this->_message =& $message;
+ $this->_message = & $message;
}
/**
@@ -723,7 +691,7 @@ public function setMessage(&$message)
*/
public function setOutput(&$output)
{
- $this->_output =& $output;
+ $this->_output = & $output;
}
/**
@@ -763,8 +731,7 @@ public function setOperation($operation, array $arguments = [])
* Keys and passphrases are stored as an indexed array of passphrases
* in JSON encoded to a flat string.
*
- * For GnuPG 2.x this is how passphrases are passed. For GnuPG 1.x the
- * environment variable is set but not used.
+ * For GnuPG 2.x this is how passphrases are passed.
*
* @param array $keys the internal key array to use.
*
@@ -811,7 +778,7 @@ public function setOptions(array $options)
* exceptions occur.
*
* @throws Exceptions\Exception if the provided binary is not
- * GnuPG or if the GnuPG version is less than 1.0.2.
+ * GnuPG or if the GnuPG version is less than {@link self::MIN_VERSION }
*/
public function getVersion()
{
@@ -841,16 +808,16 @@ public function getVersion()
$this->_version = $matches[1];
} else {
throw new Exceptions\Exception(
- 'No GnuPG version information provided by the binary "' .
- $this->_binary . '". Are you sure it is GnuPG?'
+ 'No GnuPG version information provided by the binary "'
+ . $this->_binary . '". Are you sure it is GnuPG?'
);
}
if (version_compare($this->_version, self::MIN_VERSION, 'lt')) {
throw new Exceptions\Exception(
- 'The version of GnuPG being used (' . $this->_version .
- ') is not supported by Crypt_GPG. The minimum version ' .
- 'required by Crypt_GPG is ' . self::MIN_VERSION
+ 'The version of GnuPG being used (' . $this->_version
+ . ') is not supported by Crypt_GPG. The minimum version '
+ . 'required by Crypt_GPG is ' . self::MIN_VERSION
);
}
}
@@ -870,18 +837,18 @@ public function getProcessData($name)
{
if ($this->_processHandler) {
switch ($name) {
- case 'SignatureInfo':
- if ($data = $this->_processHandler->getData('SigCreated')) {
- return new SignatureCreationInfo($data);
- }
- break;
+ case 'SignatureInfo':
+ if ($data = $this->_processHandler->getData('SigCreated')) {
+ return new SignatureCreationInfo($data);
+ }
+ break;
- case 'Signatures':
- case 'Warnings':
- return (array) $this->_processHandler->getData($name);
+ case 'Signatures':
+ case 'Warnings':
+ return (array) $this->_processHandler->getData($name);
- default:
- return $this->_processHandler->getData($name);
+ default:
+ return $this->_processHandler->getData($name);
}
}
}
@@ -918,7 +885,9 @@ public function getKeyEditor()
}
if ($this->_debug) {
- $options['debug'] = function ($line) { $this->_debug($line); };
+ $options['debug'] = function ($line) {
+ $this->_debug($line);
+ };
}
return new KeyEditor($this, $options);
@@ -988,7 +957,7 @@ private function _process()
}
if (is_string($this->_output)) {
- $outputBuffer =& $this->_output;
+ $outputBuffer = & $this->_output;
}
// convenience variables
@@ -1002,8 +971,8 @@ private function _process()
// Ignore "Broken pipe" notice from fwrite() below, as gpg could close
// the command stream before we finished writing (e.g. in bad passphrase case).
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
- return str_contains($errfile, 'Engine.php') && str_contains($errstr, 'errno=32');
- }, E_NOTICE);
+ return str_contains($errfile, 'Engine.php') && str_contains($errstr, 'errno=32');
+ }, E_NOTICE);
// select loop delay in milliseconds
$delay = 0;
@@ -1080,28 +1049,21 @@ private function _process()
$this->_debug('selecting streams');
- $ready = stream_select(
- $inputStreams,
- $outputStreams,
- $exceptionStreams,
- null
- );
+ $ready = stream_select($inputStreams, $outputStreams, $exceptionStreams, null);
$this->_debug('=> got ' . $ready);
if ($ready === false) {
throw new Exceptions\Exception(
- 'Error selecting stream for communication with GPG ' .
- 'subprocess. Please file a bug report at: ' .
- 'http://pear.php.net/bugs/report.php?package=Crypt_GPG'
+ 'Error selecting stream for communication with GPG '
+ . 'subprocess. Please file a bug report at: ' . GPG::BUG_URI
);
}
if ($ready === 0) {
throw new Exceptions\Exception(
- 'stream_select() returned 0. This can not happen! Please ' .
- 'file a bug report at: ' .
- 'http://pear.php.net/bugs/report.php?package=Crypt_GPG'
+ 'stream_select() returned 0. This can not happen! Please '
+ . 'file a bug report at: ' . GPG::BUG_URI
);
}
@@ -1112,9 +1074,7 @@ private function _process()
$chunk = substr($inputBuffer, $inputPosition, self::CHUNK_SIZE);
$length = strlen($chunk);
- $this->_debug(
- '=> about to write ' . $length . ' bytes to GPG input'
- );
+ $this->_debug('=> about to write ' . $length . ' bytes to GPG input');
$length = fwrite($fdInput, $chunk, $length);
if ($length === 0 || $length === false) {
@@ -1143,8 +1103,8 @@ private function _process()
if (in_array($this->_input, $inputStreams, true) && strlen($inputBuffer) < self::CHUNK_SIZE) {
$this->_debug('input stream is ready for reading');
$this->_debug(
- '=> about to read ' . self::CHUNK_SIZE .
- ' bytes from input stream'
+ '=> about to read ' . self::CHUNK_SIZE
+ . ' bytes from input stream'
);
$chunk = fread($this->_input, self::CHUNK_SIZE);
@@ -1161,9 +1121,7 @@ private function _process()
$chunk = substr($messageBuffer, 0, self::CHUNK_SIZE);
$length = strlen($chunk);
- $this->_debug(
- '=> about to write ' . $length . ' bytes to GPG message'
- );
+ $this->_debug('=> about to write ' . $length . ' bytes to GPG message');
$length = fwrite($fdMessage, $chunk, $length);
@@ -1185,8 +1143,8 @@ private function _process()
if (in_array($this->_message, $inputStreams, true)) {
$this->_debug('message stream is ready for reading');
$this->_debug(
- '=> about to read ' . self::CHUNK_SIZE .
- ' bytes from message stream'
+ '=> about to read ' . self::CHUNK_SIZE
+ . ' bytes from message stream'
);
$chunk = fread($this->_message, self::CHUNK_SIZE);
@@ -1199,10 +1157,7 @@ private function _process()
// read output (from GPG)
if (in_array($fdOutput, $inputStreams, true)) {
$this->_debug('GPG output stream ready for reading');
- $this->_debug(
- '=> about to read ' . self::CHUNK_SIZE .
- ' bytes from GPG output'
- );
+ $this->_debug('=> about to read ' . self::CHUNK_SIZE . ' bytes from GPG output');
$chunk = fread($fdOutput, self::CHUNK_SIZE);
$length = strlen($chunk);
@@ -1218,9 +1173,7 @@ private function _process()
$chunk = substr($outputBuffer, 0, self::CHUNK_SIZE);
$length = strlen($chunk);
- $this->_debug(
- '=> about to write ' . $length . ' bytes to output stream'
- );
+ $this->_debug('=> about to write ' . $length . ' bytes to output stream');
$length = fwrite($this->_output, $chunk, $length);
@@ -1241,10 +1194,7 @@ private function _process()
// read error (from GPG)
if (in_array($fdError, $inputStreams, true)) {
$this->_debug('GPG error stream ready for reading');
- $this->_debug(
- '=> about to read ' . self::CHUNK_SIZE .
- ' bytes from GPG error'
- );
+ $this->_debug('=> about to read ' . self::CHUNK_SIZE . ' bytes from GPG error');
$chunk = fread($fdError, self::CHUNK_SIZE);
$length = strlen($chunk);
@@ -1257,11 +1207,7 @@ private function _process()
$line = substr($errorBuffer, 0, $pos);
foreach ($this->_errorHandlers as $handler) {
array_unshift($handler['args'], $line);
- call_user_func_array(
- $handler['callback'],
- $handler['args']
- );
-
+ call_user_func_array($handler['callback'], $handler['args']);
array_shift($handler['args']);
}
@@ -1272,10 +1218,7 @@ private function _process()
// read status (from GPG)
if (in_array($fdStatus, $inputStreams, true)) {
$this->_debug('GPG status stream ready for reading');
- $this->_debug(
- '=> about to read ' . self::CHUNK_SIZE .
- ' bytes from GPG status'
- );
+ $this->_debug('=> about to read ' . self::CHUNK_SIZE . ' bytes from GPG status');
$chunk = fread($fdStatus, self::CHUNK_SIZE);
$length = strlen($chunk);
@@ -1312,9 +1255,7 @@ private function _process()
$chunk = substr($this->_commandBuffer, 0, self::CHUNK_SIZE);
$length = strlen($chunk);
- $this->_debug(
- '=> about to write ' . $length . ' bytes to GPG command'
- );
+ $this->_debug('=> about to write ' . $length . ' bytes to GPG command');
$length = fwrite($fdCommand, $chunk, $length);
@@ -1357,7 +1298,7 @@ private function _process()
* Opens an internal GPG subprocess for the current operation
*
* Opens a GPG subprocess, then connects the subprocess to some pipes. Sets
- * the private class property {@link Crypt_GPG_Engine::$_process} to
+ * the private class property {@link Crypt\GPG\Engine::$_process} to
* the new subprocess.
*
* @return void
@@ -1451,7 +1392,7 @@ private function _openSubprocess()
self::FD_ERROR => ['pipe', 'wb'], // stderr
self::FD_STATUS => ['pipe', 'wb'], // status
self::FD_COMMAND => ['pipe', 'rb'], // command
- self::FD_MESSAGE => ['pipe', 'rb'] // message
+ self::FD_MESSAGE => ['pipe', 'rb'], // message
];
$this->_debug('OPENING GPG SUBPROCESS WITH THE FOLLOWING COMMAND:');
@@ -1468,7 +1409,9 @@ private function _openSubprocess()
if (!is_resource($this->_process)) {
throw new Exceptions\OpenSubprocessException(
- 'Unable to open GPG subprocess.', 0, $commandLine
+ 'Unable to open GPG subprocess.',
+ 0,
+ $commandLine
);
}
@@ -1517,10 +1460,7 @@ private function _closeSubprocess()
}
if ($exitCode > 0) {
- $this->_debug(
- '=> subprocess returned an unexpected exit code: ' .
- $exitCode
- );
+ $this->_debug('=> subprocess returned an unexpected exit code: ' . $exitCode);
}
$this->_process = null;
@@ -1589,31 +1529,28 @@ private function _getBinary()
*/
private function _findBinary($name)
{
- $binary = '';
-
if ($this->_isDarwin) {
$locations = [
'/opt/local/bin/', // MacPorts
'/usr/local/bin/', // Mac GPG
'/sw/bin/', // Fink
- '/usr/bin/'
+ '/usr/bin/',
];
} else {
$locations = [
'/usr/bin/',
'/usr/local/bin/',
- '/run/current-system/sw/bin/' // NixOS
+ '/run/current-system/sw/bin/', // NixOS
];
}
foreach ($locations as $location) {
if (is_executable($location . $name)) {
- $binary = $location . $name;
- break;
+ return $location . $name;
}
}
- return $binary;
+ return '';
}
/**
@@ -1637,8 +1574,7 @@ private function _debug($text)
} else {
// running on a web server, format debug output nicely
foreach (explode(PHP_EOL, $text) as $line) {
- echo "Crypt_GPG DEBUG: ", htmlspecialchars($line),
- '
', PHP_EOL;
+ echo "Crypt_GPG DEBUG: ", htmlspecialchars($line), '
', PHP_EOL;
}
}
}
diff --git a/Crypt/GPG/Exceptions/BadPassphraseException.php b/Crypt/GPG/Exceptions/BadPassphraseException.php
index acf86ea..3806c3f 100644
--- a/Crypt/GPG/Exceptions/BadPassphraseException.php
+++ b/Crypt/GPG/Exceptions/BadPassphraseException.php
@@ -7,6 +7,22 @@
/**
* An exception thrown when a required passphrase is incorrect or missing
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
@@ -44,7 +60,8 @@ class BadPassphraseException extends Exception
* @param array $missingPassphrases An array containing user ids of keys
* for which the passphrase is missing.
*/
- public function __construct($message, $code = 0, array $badPassphrases = [], array $missingPassphrases = []) {
+ public function __construct($message, $code = 0, array $badPassphrases = [], array $missingPassphrases = [])
+ {
$this->_badPassphrases = (array) $badPassphrases;
$this->_missingPassphrases = (array) $missingPassphrases;
@@ -63,7 +80,7 @@ public function getBadPassphrases()
}
/**
- * Gets keys for which the passhprase is missing
+ * Gets keys for which the passhprase is missing
*
* @return array an array of keys for which the passphrase is missing.
* The array contains primary user ids indexed by the sub-key id.
diff --git a/Crypt/GPG/Exceptions/DeletePrivateKeyException.php b/Crypt/GPG/Exceptions/DeletePrivateKeyException.php
index 7da1a2e..443ec50 100644
--- a/Crypt/GPG/Exceptions/DeletePrivateKeyException.php
+++ b/Crypt/GPG/Exceptions/DeletePrivateKeyException.php
@@ -8,6 +8,22 @@
* An exception thrown when an attempt is made to delete public key that has an
* associated private key on the keyring
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
@@ -25,7 +41,7 @@ class DeletePrivateKeyException extends Exception
private $_keyId = '';
/**
- * Creates a new Crypt_GPG_DeletePrivateKeyException
+ * Creates a new DeletePrivateKeyException
*
* @param string $message An error message.
* @param int $code A user defined error code.
diff --git a/Crypt/GPG/Exceptions/Exception.php b/Crypt/GPG/Exceptions/Exception.php
index 1da9bca..c9c5415 100644
--- a/Crypt/GPG/Exceptions/Exception.php
+++ b/Crypt/GPG/Exceptions/Exception.php
@@ -7,6 +7,22 @@
/**
* An exception thrown by the Crypt_GPG package
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
@@ -14,6 +30,4 @@
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear.php.net/package/Crypt_GPG
*/
-class Exception extends \Exception
-{
-}
+class Exception extends \Exception {}
diff --git a/Crypt/GPG/Exceptions/FileException.php b/Crypt/GPG/Exceptions/FileException.php
index 2b1412c..becfe5a 100644
--- a/Crypt/GPG/Exceptions/FileException.php
+++ b/Crypt/GPG/Exceptions/FileException.php
@@ -11,6 +11,22 @@
* if an input file is specified and the file is not readable, this exception
* is thrown.
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
diff --git a/Crypt/GPG/Exceptions/InvalidKeyParamsException.php b/Crypt/GPG/Exceptions/InvalidKeyParamsException.php
index 6d2c742..4b2864b 100644
--- a/Crypt/GPG/Exceptions/InvalidKeyParamsException.php
+++ b/Crypt/GPG/Exceptions/InvalidKeyParamsException.php
@@ -8,6 +8,22 @@
* An exception thrown when an attempt is made to generate a key and the
* key parameters set on the key generator are invalid
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
@@ -47,18 +63,13 @@ class InvalidKeyParamsException extends Exception
* @param int $size The key size.
* @param int $usage The key usage.
*/
- public function __construct(
- $message,
- $code = 0,
- $algorithm = 0,
- $size = 0,
- $usage = 0
- ) {
+ public function __construct($message, $code = 0, $algorithm = 0, $size = 0, $usage = 0)
+ {
parent::__construct($message, $code);
- $this->_algorithm = $algorithm;
- $this->_size = $size;
- $this->_usage = $usage;
+ $this->_algorithm = (int) $algorithm;
+ $this->_size = (int) $size;
+ $this->_usage = (int) $usage;
}
/**
diff --git a/Crypt/GPG/Exceptions/InvalidOperationException.php b/Crypt/GPG/Exceptions/InvalidOperationException.php
index 276252c..8e79b53 100644
--- a/Crypt/GPG/Exceptions/InvalidOperationException.php
+++ b/Crypt/GPG/Exceptions/InvalidOperationException.php
@@ -7,6 +7,22 @@
/**
* An exception thrown when an invalid GPG operation is attempted
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
diff --git a/Crypt/GPG/Exceptions/KeyNotCreatedException.php b/Crypt/GPG/Exceptions/KeyNotCreatedException.php
index 9ab4dce..275152a 100644
--- a/Crypt/GPG/Exceptions/KeyNotCreatedException.php
+++ b/Crypt/GPG/Exceptions/KeyNotCreatedException.php
@@ -8,6 +8,22 @@
* An exception thrown when an attempt is made to generate a key and the
* attempt fails
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
@@ -15,6 +31,4 @@
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear.php.net/package/Crypt_GPG
*/
-class KeyNotCreatedException extends Exception
-{
-}
+class KeyNotCreatedException extends Exception {}
diff --git a/Crypt/GPG/Exceptions/KeyNotFoundException.php b/Crypt/GPG/Exceptions/KeyNotFoundException.php
index 7204f27..63bb022 100644
--- a/Crypt/GPG/Exceptions/KeyNotFoundException.php
+++ b/Crypt/GPG/Exceptions/KeyNotFoundException.php
@@ -8,6 +8,22 @@
* An exception thrown when Crypt_GPG fails to find the key for various
* operations
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
@@ -31,7 +47,7 @@ class KeyNotFoundException extends Exception
* @param int $code A user defined error code.
* @param string $keyId The key identifier of the key.
*/
- public function __construct($message, $code = 0, $keyId= '')
+ public function __construct($message, $code = 0, $keyId = '')
{
$this->_keyId = $keyId;
parent::__construct($message, $code);
diff --git a/Crypt/GPG/Exceptions/NoDataException.php b/Crypt/GPG/Exceptions/NoDataException.php
index d80d047..27c4a71 100644
--- a/Crypt/GPG/Exceptions/NoDataException.php
+++ b/Crypt/GPG/Exceptions/NoDataException.php
@@ -8,6 +8,22 @@
* An exception thrown when Crypt_GPG cannot find valid data for various
* operations
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
@@ -15,6 +31,4 @@
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear.php.net/package/Crypt_GPG
*/
-class NoDataException extends Exception
-{
-}
+class NoDataException extends Exception {}
diff --git a/Crypt/GPG/Exceptions/OpenSubprocessException.php b/Crypt/GPG/Exceptions/OpenSubprocessException.php
index e3a6c8d..7a32d8c 100644
--- a/Crypt/GPG/Exceptions/OpenSubprocessException.php
+++ b/Crypt/GPG/Exceptions/OpenSubprocessException.php
@@ -10,6 +10,22 @@
* This exception is thrown when the {@link \Crypt\GPG\Engine} tries to open a
* new subprocess and fails.
*
+ * 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, see
+ *
+ *
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
diff --git a/Crypt/GPG/Key.php b/Crypt/GPG/Key.php
index 05d327e..fb11c6d 100644
--- a/Crypt/GPG/Key.php
+++ b/Crypt/GPG/Key.php
@@ -2,33 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Contains a class representing GPG keys
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG;
use Crypt\GPG\SubKey;
@@ -37,16 +10,14 @@
/**
* A data class for GPG key information
*
- * This class is used to store the results of the {@link Crypt_GPG::getKeys()}
- * method.
+ * This class is used to store the results of the {@link Crypt\GPG::getKeys()} method.
*
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @see \Crypt\GPG::getKeys()
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class Key
{
diff --git a/Crypt/GPG/KeyEditor.php b/Crypt/GPG/KeyEditor.php
index ebef162..b4fbe67 100644
--- a/Crypt/GPG/KeyEditor.php
+++ b/Crypt/GPG/KeyEditor.php
@@ -1,5 +1,8 @@
- *
* @category Encryption
* @package Crypt_GPG
* @author Aleksander Machniak
* @copyright Apheleia IT AG
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class KeyEditor
{
- const TRUST_UNKNOWN = 1;
- const TRUST_NONE = 2;
- const TRUST_MARGINAL = 3;
- const TRUST_FULL = 4;
- const TRUST_ULTIMATE = 5;
+ public const TRUST_UNKNOWN = 1;
+ public const TRUST_NONE = 2;
+ public const TRUST_MARGINAL = 3;
+ public const TRUST_FULL = 4;
+ public const TRUST_ULTIMATE = 5;
/** @var array The GnuPG engine/key editor options */
protected $options;
diff --git a/Crypt/GPG/KeyGenerator.php b/Crypt/GPG/KeyGenerator.php
index 138a509..1e789db 100644
--- a/Crypt/GPG/KeyGenerator.php
+++ b/Crypt/GPG/KeyGenerator.php
@@ -2,36 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Crypt_GPG is a package to use GPG from PHP
- *
- * This file contains an object that handles GnuPG key generation.
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2011-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @link http://www.gnupg.org/
- */
-
namespace Crypt\GPG;
use Crypt\GPG;
@@ -63,9 +33,8 @@
* @author Nathan Fredrickson
* @author Michael Gauthier
* @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @link http://www.gnupg.org/
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class KeyGenerator extends GPG
{
@@ -177,8 +146,8 @@ public function setExpirationDate($date)
if ($expirationDate === false) {
throw new \InvalidArgumentException(
sprintf(
- 'Invalid expiration date format: "%s". Please use a ' .
- 'format compatible with PHP\'s strtotime().',
+ 'Invalid expiration date format: "%s". Please use a '
+ . 'format compatible with PHP\'s strtotime().',
$date
)
);
@@ -244,8 +213,8 @@ public function setKeyParams($algorithm, $size = 0, $usage = 0)
if ($algorithm === SubKey::ALGORITHM_ELGAMAL_ENC) {
throw new Exceptions\InvalidKeyParamsException(
- 'Primary key algorithm must be capable of signing. The ' .
- 'Elgamal algorithm can only encrypt.',
+ 'Primary key algorithm must be capable of signing. The '
+ . 'Elgamal algorithm can only encrypt.',
0,
$algorithm,
$size,
@@ -267,9 +236,9 @@ public function setKeyParams($algorithm, $size = 0, $usage = 0)
&& ($usage & $usageEncrypt) === $usageEncrypt
) {
throw new Exceptions\InvalidKeyParamsException(
- 'The DSA algorithm is not capable of encrypting. Please ' .
- 'specify a different algorithm or do not include encryption ' .
- 'as a usage for the primary key.',
+ 'The DSA algorithm is not capable of encrypting. Please '
+ . 'specify a different algorithm or do not include encryption '
+ . 'as a usage for the primary key.',
0,
$algorithm,
$size,
@@ -326,9 +295,9 @@ public function setSubKeyParams($algorithm, $size = 0, $usage = 0)
if ($algorithm === SubKey::ALGORITHM_ELGAMAL_ENC && ($usage & $usageSign) === $usageSign) {
throw new Exceptions\InvalidKeyParamsException(
- 'The Elgamal algorithm is not capable of signing. Please ' .
- 'specify a different algorithm or do not include signing ' .
- 'as a usage for the sub-key.',
+ 'The Elgamal algorithm is not capable of signing. Please '
+ . 'specify a different algorithm or do not include signing '
+ . 'as a usage for the sub-key.',
0,
$algorithm,
$size,
@@ -340,9 +309,9 @@ public function setSubKeyParams($algorithm, $size = 0, $usage = 0)
if ($algorithm === SubKey::ALGORITHM_DSA && ($usage & $usageEncrypt) === $usageEncrypt) {
throw new Exceptions\InvalidKeyParamsException(
- 'The DSA algorithm is not capable of encrypting. Please ' .
- 'specify a different algorithm or do not include encryption ' .
- 'as a usage for the sub-key.',
+ 'The DSA algorithm is not capable of encrypting. Please '
+ . 'specify a different algorithm or do not include encryption '
+ . 'as a usage for the sub-key.',
0,
$algorithm,
$size,
@@ -459,24 +428,24 @@ public function generateKey($name, $email = '', $comment = '')
$this->engine->run();
} catch (Exceptions\InvalidKeyParamsException $e) {
switch ($this->engine->getProcessData('LineNumber')) {
- case 1:
- throw new Exceptions\InvalidKeyParamsException(
- 'Invalid primary key algorithm specified.',
- 0,
- $this->keyAlgorithm,
- $this->keySize,
- $this->keyUsage
- );
- case 4:
- throw new Exceptions\InvalidKeyParamsException(
- 'Invalid sub-key algorithm specified.',
- 0,
- $this->subKeyAlgorithm,
- $this->subKeySize,
- $this->subKeyUsage
- );
- default:
- throw $e;
+ case 1:
+ throw new Exceptions\InvalidKeyParamsException(
+ 'Invalid primary key algorithm specified.',
+ 0,
+ $this->keyAlgorithm,
+ $this->keySize,
+ $this->keyUsage
+ );
+ case 4:
+ throw new Exceptions\InvalidKeyParamsException(
+ 'Invalid sub-key algorithm specified.',
+ 0,
+ $this->subKeyAlgorithm,
+ $this->subKeySize,
+ $this->subKeyUsage
+ );
+ default:
+ throw $e;
}
}
diff --git a/Crypt/GPG/ProcessHandler.php b/Crypt/GPG/ProcessHandler.php
index bb6010b..c3ea0ac 100644
--- a/Crypt/GPG/ProcessHandler.php
+++ b/Crypt/GPG/ProcessHandler.php
@@ -2,38 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Crypt_GPG is a package to use GPG from PHP
- *
- * This file contains handler for status and error pipes of GPG process.
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Nathan Fredrickson
- * @author Michael Gauthier
- * @author Aleksander Machniak
- * @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @link http://www.gnupg.org/
- */
-
namespace Crypt\GPG;
use Crypt\GPG;
@@ -45,8 +13,8 @@
/**
* Status/Error handler for GPG process pipes.
*
- * This class is used internally by Crypt_GPG_Engine and does not need to be used
- * directly. See the {@link Crypt_GPG} class for end-user API.
+ * This class is used internally by {@link Crypt\GPG\Engine} and does not need
+ * to be used directly. See the {@link Crypt\GPG} class for end-user API.
*
* @category Encryption
* @package Crypt_GPG
@@ -54,9 +22,8 @@
* @author Michael Gauthier
* @author Aleksander Machniak
* @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @link http://www.gnupg.org/
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class ProcessHandler
{
@@ -140,7 +107,7 @@ public function setOperation($operation)
if (!str_contains($operation, ' ')) {
$op = trim($operation, '- ');
- } else if (preg_match($regexp, $operation, $matches, PREG_OFFSET_CAPTURE)) {
+ } elseif (preg_match($regexp, $operation, $matches, PREG_OFFSET_CAPTURE)) {
$op = trim($matches[0][0], '-');
$op_len = $matches[0][1] + strlen($op) + 3;
$command = substr($operation, $op_len, null);
@@ -173,268 +140,268 @@ public function handleStatus($line)
{
$tokens = explode(' ', $line);
switch ($tokens[0]) {
- case 'NODATA':
- $this->errorCode = GPG::ERROR_NO_DATA;
- break;
+ case 'NODATA':
+ $this->errorCode = GPG::ERROR_NO_DATA;
+ break;
- case 'DECRYPTION_OKAY':
- // If the message is encrypted, this is the all-clear signal.
- $this->data['DecryptionOkay'] = true;
- $this->errorCode = GPG::ERROR_NONE;
- break;
+ case 'DECRYPTION_OKAY':
+ // If the message is encrypted, this is the all-clear signal.
+ $this->data['DecryptionOkay'] = true;
+ $this->errorCode = GPG::ERROR_NONE;
+ break;
- case 'DELETE_PROBLEM':
- if ($tokens[1] == '1') {
- $this->errorCode = GPG::ERROR_KEY_NOT_FOUND;
+ case 'DELETE_PROBLEM':
+ if ($tokens[1] == '1') {
+ $this->errorCode = GPG::ERROR_KEY_NOT_FOUND;
+ break;
+ } elseif ($tokens[1] == '2') {
+ $this->errorCode = GPG::ERROR_DELETE_PRIVATE_KEY;
+ break;
+ }
break;
- } elseif ($tokens[1] == '2') {
- $this->errorCode = GPG::ERROR_DELETE_PRIVATE_KEY;
+
+ case 'IMPORT_OK':
+ $this->data['Import']['fingerprint'] = $tokens[2];
+
+ if (empty($this->data['Import']['fingerprints'])) {
+ $this->data['Import']['fingerprints'] = [$tokens[2]];
+ } elseif (!in_array($tokens[2], $this->data['Import']['fingerprints'])) {
+ $this->data['Import']['fingerprints'][] = $tokens[2];
+ }
+
break;
- }
- break;
- case 'IMPORT_OK':
- $this->data['Import']['fingerprint'] = $tokens[2];
+ case 'IMPORT_RES':
+ $this->data['Import']['public_imported'] = intval($tokens[3]);
+ $this->data['Import']['public_unchanged'] = intval($tokens[5]);
+ $this->data['Import']['private_imported'] = intval($tokens[11]);
+ $this->data['Import']['private_unchanged'] = intval($tokens[12]);
+ break;
- if (empty($this->data['Import']['fingerprints'])) {
- $this->data['Import']['fingerprints'] = [$tokens[2]];
- } else if (!in_array($tokens[2], $this->data['Import']['fingerprints'])) {
- $this->data['Import']['fingerprints'][] = $tokens[2];
- }
+ case 'NO_PUBKEY':
+ case 'NO_SECKEY':
+ $this->data['ErrorKeyId'] = $tokens[1];
+
+ if ($this->errorCode != GPG::ERROR_MISSING_PASSPHRASE
+ && $this->errorCode != GPG::ERROR_BAD_PASSPHRASE
+ && !(
+ $this->operation == 'decrypt'
+ && $tokens[0] == 'NO_PUBKEY'
+ && !empty($this->data['IgnoreVerifyErrors'])
+ )
+ ) {
+ $this->errorCode = GPG::ERROR_KEY_NOT_FOUND;
+ }
- break;
-
- case 'IMPORT_RES':
- $this->data['Import']['public_imported'] = intval($tokens[3]);
- $this->data['Import']['public_unchanged'] = intval($tokens[5]);
- $this->data['Import']['private_imported'] = intval($tokens[11]);
- $this->data['Import']['private_unchanged'] = intval($tokens[12]);
- break;
-
- case 'NO_PUBKEY':
- case 'NO_SECKEY':
- $this->data['ErrorKeyId'] = $tokens[1];
-
- if ($this->errorCode != GPG::ERROR_MISSING_PASSPHRASE
- && $this->errorCode != GPG::ERROR_BAD_PASSPHRASE
- && !(
- $this->operation == 'decrypt'
- && $tokens[0] == 'NO_PUBKEY'
- && !empty($this->data['IgnoreVerifyErrors'])
- )
- ) {
- $this->errorCode = GPG::ERROR_KEY_NOT_FOUND;
- }
+ // note: this message is also received if there are multiple
+ // recipients and a previous key had a correct passphrase.
+ $this->data['MissingKeys'][$tokens[1]] = $tokens[1];
- // note: this message is also received if there are multiple
- // recipients and a previous key had a correct passphrase.
- $this->data['MissingKeys'][$tokens[1]] = $tokens[1];
-
- // @FIXME: remove missing passphrase registered in ENC_TO handler
- // This is for GnuPG 2.1
- unset($this->data['MissingPassphrases'][$tokens[1]]);
- break;
-
- case 'KEY_CONSIDERED':
- // In GnuPG 2.1.x exporting/importing a secret key requires passphrase
- // However, no NEED_PASSPRASE is returned, https://bugs.gnupg.org/gnupg/issue2667
- // So, handling KEY_CONSIDERED and GET_HIDDEN is needed.
- if (!array_key_exists('KeyConsidered', $this->data)) {
- $this->data['KeyConsidered'] = $tokens[1];
- }
- break;
-
- case 'USERID_HINT':
- // remember the user id for pretty exception messages
- // GnuPG 2.1.15 gives me: "USERID_HINT 0000000000000000 [?]"
- $keyId = $tokens[1];
- if (preg_match('/[1-9A-F]/', $keyId)) {
- $username = implode(' ', array_splice($tokens, 2));
- $this->data['BadPassphrases'][$keyId] = $username;
- }
- break;
+ // @FIXME: remove missing passphrase registered in ENC_TO handler
+ // This is for GnuPG 2.1
+ unset($this->data['MissingPassphrases'][$tokens[1]]);
+ break;
- case 'ENC_TO':
- // Now we know the message is encrypted. Set flag to check if
- // decryption succeeded.
- $this->data['DecryptionOkay'] = false;
+ case 'KEY_CONSIDERED':
+ // In GnuPG 2.1.x exporting/importing a secret key requires passphrase
+ // However, no NEED_PASSPRASE is returned, https://bugs.gnupg.org/gnupg/issue2667
+ // So, handling KEY_CONSIDERED and GET_HIDDEN is needed.
+ if (!array_key_exists('KeyConsidered', $this->data)) {
+ $this->data['KeyConsidered'] = $tokens[1];
+ }
+ break;
- // this is the new key message
- $this->data['CurrentSubKeyId'] = $keyId = $tokens[1];
+ case 'USERID_HINT':
+ // remember the user id for pretty exception messages
+ // GnuPG 2.1.15 gives me: "USERID_HINT 0000000000000000 [?]"
+ $keyId = $tokens[1];
+ if (preg_match('/[1-9A-F]/', $keyId)) {
+ $username = implode(' ', array_splice($tokens, 2));
+ $this->data['BadPassphrases'][$keyId] = $username;
+ }
+ break;
- // For some reason in GnuPG 2.1.11 I get only ENC_TO and no
- // NEED_PASSPHRASE/MISSING_PASSPHRASE/USERID_HINT
- // This is not needed for GnuPG 2.1.15
- if (!empty($_ENV['PINENTRY_USER_DATA'])) {
- $passphrases = json_decode($_ENV['PINENTRY_USER_DATA'], true);
- } else {
- $passphrases = [];
- }
+ case 'ENC_TO':
+ // Now we know the message is encrypted. Set flag to check if
+ // decryption succeeded.
+ $this->data['DecryptionOkay'] = false;
- // @TODO: Get user name/email
- $this->data['BadPassphrases'][$keyId] = $keyId;
- if (empty($passphrases) || empty($passphrases[$keyId])) {
- $this->data['MissingPassphrases'][$keyId] = $keyId;
- }
- break;
-
- case 'GOOD_PASSPHRASE':
- // if we got a good passphrase, remove the key from the list of
- // bad passphrases.
- if (isset($this->data['CurrentSubKeyId'])) {
- unset($this->data['BadPassphrases'][$this->data['CurrentSubKeyId']]);
- unset($this->data['MissingPassphrases'][$this->data['CurrentSubKeyId']]);
- }
+ // this is the new key message
+ $this->data['CurrentSubKeyId'] = $keyId = $tokens[1];
- $this->needPassphrase--;
- break;
+ // For some reason in GnuPG 2.1.11 I get only ENC_TO and no
+ // NEED_PASSPHRASE/MISSING_PASSPHRASE/USERID_HINT
+ // This is not needed for GnuPG 2.1.15
+ if (!empty($_ENV['PINENTRY_USER_DATA'])) {
+ $passphrases = json_decode($_ENV['PINENTRY_USER_DATA'], true);
+ } else {
+ $passphrases = [];
+ }
- case 'BAD_PASSPHRASE':
- $this->errorCode = GPG::ERROR_BAD_PASSPHRASE;
- break;
+ // @TODO: Get user name/email
+ $this->data['BadPassphrases'][$keyId] = $keyId;
+ if (empty($passphrases) || empty($passphrases[$keyId])) {
+ $this->data['MissingPassphrases'][$keyId] = $keyId;
+ }
+ break;
- case 'MISSING_PASSPHRASE':
- if (isset($this->data['CurrentSubKeyId'])) {
- $this->data['MissingPassphrases'][$this->data['CurrentSubKeyId']]
- = $this->data['CurrentSubKeyId'];
- }
+ case 'GOOD_PASSPHRASE':
+ // if we got a good passphrase, remove the key from the list of
+ // bad passphrases.
+ if (isset($this->data['CurrentSubKeyId'])) {
+ unset($this->data['BadPassphrases'][$this->data['CurrentSubKeyId']]);
+ unset($this->data['MissingPassphrases'][$this->data['CurrentSubKeyId']]);
+ }
- $this->errorCode = GPG::ERROR_MISSING_PASSPHRASE;
- break;
+ $this->needPassphrase--;
+ break;
- case 'GET_HIDDEN':
- if ($tokens[1] == 'passphrase.enter' && isset($this->data['KeyConsidered'])) {
- $tokens[1] = $this->data['KeyConsidered'];
- } else {
+ case 'BAD_PASSPHRASE':
+ $this->errorCode = GPG::ERROR_BAD_PASSPHRASE;
break;
- }
- // no break
- case 'NEED_PASSPHRASE':
- $passphrase = $this->getPin($tokens[1]);
+ case 'MISSING_PASSPHRASE':
+ if (isset($this->data['CurrentSubKeyId'])) {
+ $this->data['MissingPassphrases'][$this->data['CurrentSubKeyId']]
+ = $this->data['CurrentSubKeyId'];
+ }
- $this->engine->sendCommand($passphrase);
+ $this->errorCode = GPG::ERROR_MISSING_PASSPHRASE;
+ break;
- if ($passphrase === '') {
- $this->needPassphrase++;
- }
- break;
-
- case 'SIG_CREATED':
- $this->data['SigCreated'] = $line;
- break;
-
- case 'SIG_ID':
- // note: signature id comes before new signature line and may not
- // exist for some signature types
- $this->data['SignatureId'] = $tokens[1];
- break;
-
- case 'EXPSIG':
- case 'EXPKEYSIG':
- case 'REVKEYSIG':
- case 'BADSIG':
- case 'ERRSIG':
- $this->errorCode = GPG::ERROR_BAD_SIGNATURE;
- // no break
- case 'GOODSIG':
- $signature = new Signature();
-
- // if there was a signature id, set it on the new signature
- if (!empty($this->data['SignatureId'])) {
- $signature->setId($this->data['SignatureId']);
- $this->data['SignatureId'] = '';
- }
+ case 'GET_HIDDEN':
+ if ($tokens[1] == 'passphrase.enter' && isset($this->data['KeyConsidered'])) {
+ $tokens[1] = $this->data['KeyConsidered'];
+ } else {
+ break;
+ }
+ // no break
- // Detect whether fingerprint or key id was returned and set
- // signature values appropriately. Key ids are strings of either
- // 16 or 8 hexadecimal characters. Fingerprints are strings of 40
- // hexadecimal characters. The key id is the last 16 characters of
- // the key fingerprint.
- if (strlen($tokens[1]) > 16) {
- $signature->setKeyFingerprint($tokens[1]);
- $signature->setKeyId(substr($tokens[1], -16));
- } else {
- $signature->setKeyId($tokens[1]);
- }
+ case 'NEED_PASSPHRASE':
+ $passphrase = $this->getPin($tokens[1]);
- // get user id string
- if ($tokens[0] != 'ERRSIG') {
- $string = implode(' ', array_splice($tokens, 2));
- $string = rawurldecode($string);
+ $this->engine->sendCommand($passphrase);
- $signature->setUserId(UserId::parse($string));
- }
+ if ($passphrase === '') {
+ $this->needPassphrase++;
+ }
+ break;
- $this->data['Signatures'][] = $signature;
- break;
+ case 'SIG_CREATED':
+ $this->data['SigCreated'] = $line;
+ break;
- case 'VALIDSIG':
- if (empty($this->data['Signatures'])) {
+ case 'SIG_ID':
+ // note: signature id comes before new signature line and may not
+ // exist for some signature types
+ $this->data['SignatureId'] = $tokens[1];
break;
- }
- $signature = end($this->data['Signatures']);
+ case 'EXPSIG':
+ case 'EXPKEYSIG':
+ case 'REVKEYSIG':
+ case 'BADSIG':
+ case 'ERRSIG':
+ $this->errorCode = GPG::ERROR_BAD_SIGNATURE;
+ // no break
+ case 'GOODSIG':
+ $signature = new Signature();
+
+ // if there was a signature id, set it on the new signature
+ if (!empty($this->data['SignatureId'])) {
+ $signature->setId($this->data['SignatureId']);
+ $this->data['SignatureId'] = '';
+ }
- $signature->setValid(true);
- $signature->setKeyFingerprint($tokens[1]);
+ // Detect whether fingerprint or key id was returned and set
+ // signature values appropriately. Key ids are strings of either
+ // 16 or 8 hexadecimal characters. Fingerprints are strings of 40
+ // hexadecimal characters. The key id is the last 16 characters of
+ // the key fingerprint.
+ if (strlen($tokens[1]) > 16) {
+ $signature->setKeyFingerprint($tokens[1]);
+ $signature->setKeyId(substr($tokens[1], -16));
+ } else {
+ $signature->setKeyId($tokens[1]);
+ }
- if (!str_contains($tokens[3], 'T')) {
- $signature->setCreationDate($tokens[3]);
- } else {
- $signature->setCreationDate(strtotime($tokens[3]));
- }
+ // get user id string
+ if ($tokens[0] != 'ERRSIG') {
+ $string = implode(' ', array_splice($tokens, 2));
+ $string = rawurldecode($string);
+
+ $signature->setUserId(UserId::parse($string));
+ }
+
+ $this->data['Signatures'][] = $signature;
+ break;
- if (array_key_exists(4, $tokens)) {
- if (!str_contains($tokens[4], 'T')) {
- $signature->setExpirationDate($tokens[4]);
+ case 'VALIDSIG':
+ if (empty($this->data['Signatures'])) {
+ break;
+ }
+
+ $signature = end($this->data['Signatures']);
+
+ $signature->setValid(true);
+ $signature->setKeyFingerprint($tokens[1]);
+
+ if (!str_contains($tokens[3], 'T')) {
+ $signature->setCreationDate($tokens[3]);
} else {
- $signature->setExpirationDate(strtotime($tokens[4]));
+ $signature->setCreationDate(strtotime($tokens[3]));
}
- }
- break;
+ if (array_key_exists(4, $tokens)) {
+ if (!str_contains($tokens[4], 'T')) {
+ $signature->setExpirationDate($tokens[4]);
+ } else {
+ $signature->setExpirationDate(strtotime($tokens[4]));
+ }
+ }
- case 'KEY_CREATED':
- if (isset($this->data['Handle']) && $tokens[3] == $this->data['Handle']) {
- $this->data['KeyCreated'] = $tokens[2];
- }
- break;
+ break;
- case 'KEY_NOT_CREATED':
- if (isset($this->data['Handle']) && $tokens[1] == $this->data['Handle']) {
- $this->errorCode = GPG::ERROR_KEY_NOT_CREATED;
- }
- break;
-
- case 'PROGRESS':
- // todo: at some point, support reporting status async
- break;
-
- // GnuPG 2.1 uses FAILURE and ERROR responses
- case 'FAILURE':
- case 'ERROR':
- $errnum = (int) $tokens[2];
- $source = $errnum >> 24;
- $errcode = $errnum & 0xFFFFFF;
-
- switch ($errcode) {
- case 11: // bad passphrase
- case 87: // bad PIN
- $this->errorCode = GPG::ERROR_BAD_PASSPHRASE;
+ case 'KEY_CREATED':
+ if (isset($this->data['Handle']) && $tokens[3] == $this->data['Handle']) {
+ $this->data['KeyCreated'] = $tokens[2];
+ }
break;
- case 177: // no passphrase
- case 178: // no PIN
- $this->errorCode = GPG::ERROR_MISSING_PASSPHRASE;
+ case 'KEY_NOT_CREATED':
+ if (isset($this->data['Handle']) && $tokens[1] == $this->data['Handle']) {
+ $this->errorCode = GPG::ERROR_KEY_NOT_CREATED;
+ }
break;
- case 58:
- $this->errorCode = GPG::ERROR_NO_DATA;
+ case 'PROGRESS':
+ // todo: at some point, support reporting status async
break;
- }
- break;
+ // GnuPG 2.1 uses FAILURE and ERROR responses
+ case 'FAILURE':
+ case 'ERROR':
+ $errnum = (int) $tokens[2];
+ $source = $errnum >> 24;
+ $errcode = $errnum & 0xFFFFFF;
+
+ switch ($errcode) {
+ case 11: // bad passphrase
+ case 87: // bad PIN
+ $this->errorCode = GPG::ERROR_BAD_PASSPHRASE;
+ break;
+
+ case 177: // no passphrase
+ case 178: // no PIN
+ $this->errorCode = GPG::ERROR_MISSING_PASSPHRASE;
+ break;
+
+ case 58:
+ $this->errorCode = GPG::ERROR_NO_DATA;
+ break;
+ }
+
+ break;
}
}
@@ -537,205 +504,213 @@ public function throwException($exitcode = 0)
}
$code = $this->errorCode;
- $note = "Please use the 'debug' option when creating the Crypt_GPG " .
- "object, and file a bug report at " . GPG::BUG_URI;
+ $note = "Please use the 'debug' option when creating the Crypt_GPG "
+ . "object, and file a bug report at " . GPG::BUG_URI;
switch ($this->operation) {
- case 'version':
- throw new Exceptions\Exception(
- 'Unknown error getting GnuPG version information. ' . $note,
- $code
- );
-
- case 'list-secret-keys':
- case 'list-public-keys':
- case 'list-keys':
- switch ($code) {
- case GPG::ERROR_KEY_NOT_FOUND:
- // ignore not found key errors
- break;
-
- case GPG::ERROR_FILE_PERMISSIONS:
- if (!empty($this->data['ErrorFilename'])) {
- throw new Exceptions\FileException(
- sprintf(
- 'Error reading GnuPG data file \'%s\'. Check to make ' .
- 'sure it is readable by the current user.',
- $this->data['ErrorFilename']
- ),
- $code,
- $this->data['ErrorFilename']
- );
- }
- throw new Exceptions\FileException(
- 'Error reading GnuPG data file. Check to make sure that ' .
- 'GnuPG data files are readable by the current user.',
- $code
- );
-
- default:
- throw new Exceptions\Exception(
- 'Unknown error getting keys. ' . $note, $code
- );
- }
- break;
-
- case 'delete-key':
- case 'delete-secret-key':
- switch ($code) {
- case GPG::ERROR_KEY_NOT_FOUND:
- throw new Exceptions\KeyNotFoundException(
- 'Key not found: ' . $this->operationArg,
- $code,
- $this->operationArg
- );
-
- case GPG::ERROR_DELETE_PRIVATE_KEY:
- throw new Exceptions\DeletePrivateKeyException(
- 'Private key must be deleted before public key can be ' .
- 'deleted.',
- $code,
- $this->operationArg
- );
-
- default:
+ case 'version':
throw new Exceptions\Exception(
- 'Unknown error deleting key. ' . $note, $code
+ 'Unknown error getting GnuPG version information. ' . $note,
+ $code
);
- }
- break; // @phpstan-ignore-line
- case 'import':
- switch ($code) {
- case GPG::ERROR_NO_DATA:
- throw new Exceptions\NoDataException('No valid GPG key data found.', $code);
-
- case GPG::ERROR_BAD_PASSPHRASE:
- case GPG::ERROR_MISSING_PASSPHRASE:
- throw $this->badPassException($code, 'Cannot import private key.');
-
- default:
- throw new Exceptions\Exception('Unknown error importing GPG key. ' . $note, $code);
- }
- break; // @phpstan-ignore-line
+ case 'list-secret-keys':
+ case 'list-public-keys':
+ case 'list-keys':
+ switch ($code) {
+ case GPG::ERROR_KEY_NOT_FOUND:
+ // ignore not found key errors
+ break;
+
+ case GPG::ERROR_FILE_PERMISSIONS:
+ if (!empty($this->data['ErrorFilename'])) {
+ throw new Exceptions\FileException(
+ sprintf(
+ 'Error reading GnuPG data file \'%s\'. Check to make '
+ . 'sure it is readable by the current user.',
+ $this->data['ErrorFilename']
+ ),
+ $code,
+ $this->data['ErrorFilename']
+ );
+ }
+ throw new Exceptions\FileException(
+ 'Error reading GnuPG data file. Check to make sure that '
+ . 'GnuPG data files are readable by the current user.',
+ $code
+ );
+
+ default:
+ throw new Exceptions\Exception(
+ 'Unknown error getting keys. ' . $note,
+ $code
+ );
+ }
+ break;
- case 'export':
- case 'export-secret-keys':
- switch ($code) {
- case GPG::ERROR_BAD_PASSPHRASE:
- case GPG::ERROR_MISSING_PASSPHRASE:
- throw $this->badPassException($code, 'Cannot export private key.');
+ case 'delete-key':
+ case 'delete-secret-key':
+ switch ($code) {
+ case GPG::ERROR_KEY_NOT_FOUND:
+ throw new Exceptions\KeyNotFoundException(
+ 'Key not found: ' . $this->operationArg,
+ $code,
+ $this->operationArg
+ );
+
+ case GPG::ERROR_DELETE_PRIVATE_KEY:
+ throw new Exceptions\DeletePrivateKeyException(
+ 'Private key must be deleted before public key can be '
+ . 'deleted.',
+ $code,
+ $this->operationArg
+ );
+
+ default:
+ throw new Exceptions\Exception(
+ 'Unknown error deleting key. ' . $note,
+ $code
+ );
+ }
+ break; // @phpstan-ignore-line
- default:
- throw new Exceptions\Exception('Unknown error exporting a key. ' . $note, $code);
- }
- break; // @phpstan-ignore-line
-
- case 'encrypt':
- case 'sign':
- case 'clearsign':
- case 'detach-sign':
- switch ($code) {
- case GPG::ERROR_KEY_NOT_FOUND:
- throw new Exceptions\KeyNotFoundException(
- 'Cannot sign data. Private key not found. Import the '.
- 'private key before trying to sign data.',
- $code,
- !empty($this->data['ErrorKeyId']) ? $this->data['ErrorKeyId'] : null
- );
+ case 'import':
+ switch ($code) {
+ case GPG::ERROR_NO_DATA:
+ throw new Exceptions\NoDataException('No valid GPG key data found.', $code);
- case GPG::ERROR_BAD_PASSPHRASE:
- throw new Exceptions\BadPassphraseException(
- 'Cannot sign data. Incorrect passphrase provided.', $code
- );
+ case GPG::ERROR_BAD_PASSPHRASE:
+ case GPG::ERROR_MISSING_PASSPHRASE:
+ throw $this->badPassException($code, 'Cannot import private key.');
- case GPG::ERROR_MISSING_PASSPHRASE:
- throw new Exceptions\BadPassphraseException(
- 'Cannot sign data. No passphrase provided.', $code
- );
+ default:
+ throw new Exceptions\Exception('Unknown error importing GPG key. ' . $note, $code);
+ }
+ break; // @phpstan-ignore-line
- default:
- throw new Exceptions\Exception(
- "Unknown error {$this->operation}ing data. $note", $code
- );
- }
- break; // @phpstan-ignore-line
+ case 'export':
+ case 'export-secret-keys':
+ switch ($code) {
+ case GPG::ERROR_BAD_PASSPHRASE:
+ case GPG::ERROR_MISSING_PASSPHRASE:
+ throw $this->badPassException($code, 'Cannot export private key.');
- case 'verify':
- switch ($code) {
- case GPG::ERROR_BAD_SIGNATURE:
- // ignore bad signature errors
+ default:
+ throw new Exceptions\Exception('Unknown error exporting a key. ' . $note, $code);
+ }
+ break; // @phpstan-ignore-line
+
+ case 'encrypt':
+ case 'sign':
+ case 'clearsign':
+ case 'detach-sign':
+ switch ($code) {
+ case GPG::ERROR_KEY_NOT_FOUND:
+ throw new Exceptions\KeyNotFoundException(
+ 'Cannot sign data. Private key not found. Import the '
+ . 'private key before trying to sign data.',
+ $code,
+ !empty($this->data['ErrorKeyId']) ? $this->data['ErrorKeyId'] : null
+ );
+
+ case GPG::ERROR_BAD_PASSPHRASE:
+ throw new Exceptions\BadPassphraseException(
+ 'Cannot sign data. Incorrect passphrase provided.',
+ $code
+ );
+
+ case GPG::ERROR_MISSING_PASSPHRASE:
+ throw new Exceptions\BadPassphraseException(
+ 'Cannot sign data. No passphrase provided.',
+ $code
+ );
+
+ default:
+ throw new Exceptions\Exception(
+ "Unknown error {$this->operation}ing data. $note",
+ $code
+ );
+ }
+ break; // @phpstan-ignore-line
+
+ case 'verify':
+ switch ($code) {
+ case GPG::ERROR_BAD_SIGNATURE:
+ // ignore bad signature errors
+ break;
+
+ case GPG::ERROR_NO_DATA:
+ throw new Exceptions\NoDataException(
+ 'No valid signature data found.',
+ $code
+ );
+
+ case GPG::ERROR_KEY_NOT_FOUND:
+ throw new Exceptions\KeyNotFoundException(
+ 'Public key required for data verification not in keyring.',
+ $code,
+ !empty($this->data['ErrorKeyId']) ? $this->data['ErrorKeyId'] : null
+ );
+
+ default:
+ throw new Exceptions\Exception(
+ 'Unknown error validating signature details. ' . $note,
+ $code
+ );
+ }
break;
- case GPG::ERROR_NO_DATA:
- throw new Exceptions\NoDataException(
- 'No valid signature data found.', $code
- );
-
- case GPG::ERROR_KEY_NOT_FOUND:
- throw new Exceptions\KeyNotFoundException(
- 'Public key required for data verification not in keyring.',
- $code,
- !empty($this->data['ErrorKeyId']) ? $this->data['ErrorKeyId'] : null
- );
-
- default:
- throw new Exceptions\Exception(
- 'Unknown error validating signature details. ' . $note,
- $code
- );
- }
- break;
-
- case 'decrypt':
- switch ($code) {
- case GPG::ERROR_BAD_SIGNATURE:
- // ignore bad signature errors
+ case 'decrypt':
+ switch ($code) {
+ case GPG::ERROR_BAD_SIGNATURE:
+ // ignore bad signature errors
+ break;
+
+ case GPG::ERROR_KEY_NOT_FOUND:
+ if (!empty($this->data['MissingKeys'])) {
+ $keyId = reset($this->data['MissingKeys']);
+ } else {
+ $keyId = '';
+ }
+
+ throw new Exceptions\KeyNotFoundException(
+ 'Cannot decrypt data. No suitable private key is in the '
+ . 'keyring. Import a suitable private key before trying to '
+ . 'decrypt this data.',
+ $code,
+ $keyId
+ );
+
+ case GPG::ERROR_BAD_PASSPHRASE:
+ case GPG::ERROR_MISSING_PASSPHRASE:
+ throw $this->badPassException($code, 'Cannot decrypt data.');
+
+ case GPG::ERROR_NO_DATA:
+ throw new Exceptions\NoDataException(
+ 'Cannot decrypt data. No PGP encrypted data was found in '
+ . 'the provided data.',
+ $code
+ );
+
+ default:
+ throw new Exceptions\Exception('Unknown error decrypting data.', $code);
+ }
break;
- case GPG::ERROR_KEY_NOT_FOUND:
- if (!empty($this->data['MissingKeys'])) {
- $keyId = reset($this->data['MissingKeys']);
- } else {
- $keyId = '';
+ case 'gen-key':
+ switch ($code) {
+ case GPG::ERROR_BAD_KEY_PARAMS:
+ throw new Exceptions\InvalidKeyParamsException(
+ 'Invalid key algorithm specified.',
+ $code
+ );
+
+ default:
+ throw new Exceptions\Exception(
+ 'Unknown error generating key-pair. ' . $note,
+ $code
+ );
}
-
- throw new Exceptions\KeyNotFoundException(
- 'Cannot decrypt data. No suitable private key is in the ' .
- 'keyring. Import a suitable private key before trying to ' .
- 'decrypt this data.',
- $code,
- $keyId
- );
-
- case GPG::ERROR_BAD_PASSPHRASE:
- case GPG::ERROR_MISSING_PASSPHRASE:
- throw $this->badPassException($code, 'Cannot decrypt data.');
-
- case GPG::ERROR_NO_DATA:
- throw new Exceptions\NoDataException(
- 'Cannot decrypt data. No PGP encrypted data was found in '.
- 'the provided data.',
- $code
- );
-
- default:
- throw new Exceptions\Exception('Unknown error decrypting data.', $code);
- }
- break;
-
- case 'gen-key':
- switch ($code) {
- case GPG::ERROR_BAD_KEY_PARAMS:
- throw new Exceptions\InvalidKeyParamsException(
- 'Invalid key algorithm specified.', $code
- );
-
- default:
- throw new Exceptions\Exception(
- 'Unknown error generating key-pair. ' . $note, $code
- );
- }
}
}
@@ -784,7 +759,7 @@ protected function setErrorCode($exitcode)
*/
public function getData($name)
{
- return isset($this->data[$name]) ? $this->data[$name] : null;
+ return $this->data[$name] ?? null;
}
/**
@@ -805,13 +780,13 @@ public function getData($name)
public function setData($name, $value)
{
switch ($name) {
- case 'Handle':
- $this->data[$name] = strval($value);
- break;
+ case 'Handle':
+ $this->data[$name] = strval($value);
+ break;
- case 'IgnoreVerifyErrors':
- $this->data[$name] = (bool) $value;
- break;
+ case 'IgnoreVerifyErrors':
+ $this->data[$name] = (bool) $value;
+ break;
}
}
@@ -826,22 +801,22 @@ public function setData($name, $value)
protected function badPassException($code, $message)
{
$badPassphrases = array_diff_key(
- isset($this->data['BadPassphrases']) ? $this->data['BadPassphrases'] : [],
- isset($this->data['MissingPassphrases']) ? $this->data['MissingPassphrases'] : []
+ $this->data['BadPassphrases'] ?? [],
+ $this->data['MissingPassphrases'] ?? []
);
$missingPassphrases = array_intersect_key(
- isset($this->data['BadPassphrases']) ? $this->data['BadPassphrases'] : [],
- isset($this->data['MissingPassphrases']) ? $this->data['MissingPassphrases'] : []
+ $this->data['BadPassphrases'] ?? [],
+ $this->data['MissingPassphrases'] ?? []
);
if (count($badPassphrases) > 0) {
- $message .= ' Incorrect passphrase provided for keys: "' .
- implode('", "', $badPassphrases) . '".';
+ $message .= ' Incorrect passphrase provided for keys: "'
+ . implode('", "', $badPassphrases) . '".';
}
if (count($missingPassphrases) > 0) {
- $message .= ' No passphrase provided for keys: "' .
- implode('", "', $missingPassphrases) . '".';
+ $message .= ' No passphrase provided for keys: "'
+ . implode('", "', $missingPassphrases) . '".';
}
return new Exceptions\BadPassphraseException(
@@ -873,7 +848,7 @@ protected function getPin($key)
// Get last X characters of key identifier to compare
if ($keyIdLength < $_keyIdLength) {
$_keyId = substr($_keyId, -$keyIdLength);
- } else if ($keyIdLength > $_keyIdLength) {
+ } elseif ($keyIdLength > $_keyIdLength) {
$keyId = substr($keyId, -$_keyIdLength);
}
diff --git a/Crypt/GPG/Signature.php b/Crypt/GPG/Signature.php
index 5b8a68f..a9a2eca 100644
--- a/Crypt/GPG/Signature.php
+++ b/Crypt/GPG/Signature.php
@@ -2,36 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * A class representing GPG signatures
- *
- * This file contains a data class representing a GPG signature.
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Nathan Fredrickson
- * @author Michael Gauthier
- * @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG;
use Crypt\GPG\UserId;
@@ -39,16 +9,15 @@
/**
* A class for GPG signature information
*
- * This class is used to store the results of the Crypt_GPG::verify() method.
+ * This class is used to store the results of the {@link Crypt\GPG::verify()} method.
*
* @category Encryption
* @package Crypt_GPG
* @author Nathan Fredrickson
* @author Michael Gauthier
* @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @see \Crypt\GPG::verify()
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class Signature
{
@@ -138,7 +107,7 @@ class Signature
*/
public function __construct($signature = null)
{
- if ($signature instanceof self) {
+ if ($signature instanceof self) {
$this->_id = $signature->_id;
$this->_keyFingerprint = $signature->_keyFingerprint;
$this->_keyId = $signature->_keyId;
diff --git a/Crypt/GPG/SignatureCreationInfo.php b/Crypt/GPG/SignatureCreationInfo.php
index 58042d7..367f1c5 100644
--- a/Crypt/GPG/SignatureCreationInfo.php
+++ b/Crypt/GPG/SignatureCreationInfo.php
@@ -11,10 +11,8 @@
* @package Crypt_GPG
* @author Christian Weiske
* @copyright 2015 PEAR
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @link http://pear.php.net/manual/en/package.encryption.crypt-gpg.php
- * @link http://www.gnupg.org/
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class SignatureCreationInfo
{
@@ -110,21 +108,21 @@ public function __construct($sigCreatedLine = null)
$this->valid = false;
return;
}
- list(
+ [
$title, $mode, $pkAlgorithm, $hashAlgorithm,
$class, $timestamp, $keyFingerprint
- ) = $parts;
+ ] = $parts;
switch (strtoupper($mode[0])) {
- case 'D':
- $this->mode = GPG::SIGN_MODE_DETACHED;
- break;
- case 'C':
- $this->mode = GPG::SIGN_MODE_CLEAR;
- break;
- case 'S':
- $this->mode = GPG::SIGN_MODE_NORMAL;
- break;
+ case 'D':
+ $this->mode = GPG::SIGN_MODE_DETACHED;
+ break;
+ case 'C':
+ $this->mode = GPG::SIGN_MODE_CLEAR;
+ break;
+ case 'S':
+ $this->mode = GPG::SIGN_MODE_NORMAL;
+ break;
}
$this->pkAlgorithm = (int) $pkAlgorithm;
diff --git a/Crypt/GPG/SubKey.php b/Crypt/GPG/SubKey.php
index 150768b..a53e307 100644
--- a/Crypt/GPG/SubKey.php
+++ b/Crypt/GPG/SubKey.php
@@ -2,94 +2,64 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Contains a class representing GPG sub-keys and constants for GPG algorithms
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @author Nathan Fredrickson
- * @copyright 2005-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG;
/**
* A class for GPG sub-key information
*
- * This class is used to store the results of the {@link Crypt_GPG::getKeys()}
- * method. Sub-key objects are members of a {@link Crypt_GPG_Key} object.
+ * This class is used to store the results of the {@link Crypt\GPG::getKeys()}
+ * method. Sub-key objects are members of a {@link Crypt\GPG\Key} object.
*
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
* @author Nathan Fredrickson
* @copyright 2005-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @see \Crypt\GPG::getKeys()
- * @see \Crypt\GPG\Key::getSubKeys()
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class SubKey
{
/**
* RSA encryption algorithm.
*/
- const ALGORITHM_RSA = 1;
+ public const ALGORITHM_RSA = 1;
/**
* Elgamal encryption algorithm (encryption only).
*/
- const ALGORITHM_ELGAMAL_ENC = 16;
+ public const ALGORITHM_ELGAMAL_ENC = 16;
/**
* DSA encryption algorithm (sometimes called DH, sign only).
*/
- const ALGORITHM_DSA = 17;
+ public const ALGORITHM_DSA = 17;
/**
* Elgamal encryption algorithm (signage and encryption - should not be
* used).
*/
- const ALGORITHM_ELGAMAL_ENC_SGN = 20;
+ public const ALGORITHM_ELGAMAL_ENC_SGN = 20;
/**
* Key can be used to encrypt
*/
- const USAGE_ENCRYPT = 1;
+ public const USAGE_ENCRYPT = 1;
/**
* Key can be used to sign
*/
- const USAGE_SIGN = 2;
+ public const USAGE_SIGN = 2;
/**
* Key can be used to certify other keys
*/
- const USAGE_CERTIFY = 4;
+ public const USAGE_CERTIFY = 4;
/**
* Key can be used for authentication
*/
- const USAGE_AUTHENTICATION = 8;
+ public const USAGE_AUTHENTICATION = 8;
/**
* The id of this sub-key
diff --git a/Crypt/GPG/UserId.php b/Crypt/GPG/UserId.php
index 594a700..00df068 100644
--- a/Crypt/GPG/UserId.php
+++ b/Crypt/GPG/UserId.php
@@ -2,33 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Contains a data class representing a GPG user id
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG;
use Crypt\GPG\Signature;
@@ -36,17 +9,15 @@
/**
* A class for GPG user id information
*
- * This class is used to store the results of the {@link Crypt_GPG::getKeys()}
- * method. User id objects are members of a {@link Crypt_GPG_Key} object.
+ * This class is used to store the results of the {@link \Crypt\GPG::getKeys()}
+ * method. User id objects are members of a {@link \Crypt\GPG\Key} object.
*
* @category Encryption
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- * @see \Crypt\GPG::getKeys()
- * @see \Crypt\GPG\Key::getUserIds()
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class UserId
{
@@ -242,7 +213,7 @@ public function __toString()
}
if (strlen($this->_email) > 0) {
- $components[] = '<' . $this->_email. '>';
+ $components[] = '<' . $this->_email . '>';
}
return implode(' ', $components);
@@ -296,7 +267,7 @@ public function setEmail($email)
*/
public function setRevoked($isRevoked)
{
- $this->_isRevoked = ($isRevoked) ? true : false;
+ $this->_isRevoked = $isRevoked ? true : false;
return $this;
}
@@ -309,7 +280,7 @@ public function setRevoked($isRevoked)
*/
public function setValid($isValid)
{
- $this->_isValid = ($isValid) ? true : false;
+ $this->_isValid = $isValid ? true : false;
return $this;
}
diff --git a/composer.json b/composer.json
index 9927aa4..07396c3 100644
--- a/composer.json
+++ b/composer.json
@@ -30,7 +30,8 @@
"require-dev": {
"ext-posix": "*",
"phpstan/phpstan": "^2.2",
- "phpunit/phpunit": "^10"
+ "phpunit/phpunit": "^10",
+ "friendsofphp/php-cs-fixer": "^3.95"
},
"suggest": {
"ext-posix": "May require the posix PHP extension"
@@ -51,10 +52,5 @@
},
"archive": {
"exclude": ["tools"]
- },
- "config": {
- "audit": {
- "block-insecure": false
- }
}
}
diff --git a/tests/DecryptAndVerifyTest.php b/tests/DecryptAndVerifyTest.php
index 3028d4d..6f0bcd7 100644
--- a/tests/DecryptAndVerifyTest.php
+++ b/tests/DecryptAndVerifyTest.php
@@ -2,44 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Decrypt verify tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit DecryptAndVefifyTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @version $Id$
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG;
@@ -54,8 +16,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class DecryptAndVerifyTest extends TestCase
{
@@ -68,7 +30,8 @@ public function testDecryptVerify()
$signature = new Signature();
$signature->setId('5dGf4//0CqBmlexYjyS7agt4Zn4');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258956392);
@@ -84,35 +47,35 @@ public function testDecryptVerify()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
// encrypted with first-keypair@example.com, signed with
// first-keypair@example.com
// {{{ encrypted data no passphrase
$encryptedData = <<gpg->addDecryptKey('first-keypair@example.com', 'test1');
@@ -129,7 +92,8 @@ public function testDecryptVerifyNoPassphrase()
$signature = new Signature();
$signature->setId('0YWPoUQhN5G4uTi45QLy3GG3RWg');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258956262);
@@ -145,35 +109,35 @@ public function testDecryptVerifyNoPassphrase()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
// encrypted with no-passphrase@example.com, signed with
// first-keypair@example.com
// {{{ encrypted data no passphrase
$encryptedData = <<gpg->decryptAndVerify($encryptedData);
@@ -191,28 +155,28 @@ public function testDecryptVerifyKeyNotFoundException_decrypt()
// first-keypair@example.com
// {{{ encrypted data
$encryptedData = <<gpg->decryptAndVerify($encryptedData);
@@ -229,33 +193,33 @@ public function testDecryptVerifyKeyNotFoundException_verify()
// missing-key@example.com
// {{{ encrypted data
$encryptedData = <<gpg->addDecryptKey('first-keypair@example.com', 'test1');
@@ -272,28 +236,28 @@ public function testDecryptVerifyKeyNotFoundException_both()
// was encrypted and signed with missing-key@example.com
// {{{ encrypted data
$encryptedData = <<gpg->decryptAndVerify($encryptedData);
@@ -309,40 +273,40 @@ public function testDecryptVerifyKeyNotFoundIgnoreVerifyErrors()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
// was encrypted with first-keypair@example.com, signed with
// missing-key@example.com
// {{{ encrypted data
$encryptedData = <<gpg = new GPG($this->getOptions());
@@ -386,28 +350,28 @@ public function testDecryptVerifyBadPassphraseException_missing()
// first-keypair@example.com
// {{{ encrypted data no passphrase
$encryptedData = <<gpg->decryptAndVerify($encryptedData);
@@ -424,28 +388,28 @@ public function testDecryptVerifyBadPassphraseException_bad()
// first-keypair@example.com
// {{{ encrypted data no passphrase
$encryptedData = <<gpg->addDecryptKey('first-keypair@example.com', 'incorrect');
@@ -461,7 +425,8 @@ public function testDecryptVerifyDual()
$signature = new Signature();
$signature->setId('TAsI7RYUgZAud0wMZu3Iab3bZXo');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258955651);
@@ -477,46 +442,46 @@ public function testDecryptVerifyDual()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
// encrypted with both first-keypair@example.com and
// second-keypair@example.com, signed with first-keypair@example.com
// {{{ dual encrypted, signed data
$encryptedData = <<setId('3OJnX+PqHI0YUCeFxICCxhPHY1Q');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258955916);
@@ -557,46 +523,46 @@ public function testDecryptVerifyDualOnePassphrase()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
// encrypted with both first-keypair@example.com and
// no-passhprase@example.com, signed with first-keypair@example.com
// {{{ dual encrypted, signed data
$encryptedData = <<setId('7PujVkx4qk28IejcD6BirrwBmRE');
$signature1->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature1->setKeyId('C097D9EC94C06363');
$signature1->setCreationDate(1258956025);
@@ -690,7 +657,8 @@ public function testDecryptVerifyDualSignatories()
$signature2 = new Signature();
$signature2->setId('AhrDdkdcBsEsOSQOYENhl5C7auc');
$signature2->setKeyFingerprint(
- '880922DBEA733E906693E4A903CC890AFA1DAD4B');
+ '880922DBEA733E906693E4A903CC890AFA1DAD4B'
+ );
$signature2->setKeyId('03CC890AFA1DAD4B');
$signature2->setCreationDate(1258956025);
@@ -706,36 +674,36 @@ public function testDecryptVerifyDualSignatories()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature1, $signature2]
+ 'signatures' => [$signature1, $signature2],
];
// encrypted with first-keypair@example.com and signed with
// first-keypair@example.com and second-keypair@example.com
// {{{ encrypted, dual signed data
$encryptedData = <<gpg->addDecryptKey('first-keypair@example.com', 'test1');
@@ -752,7 +720,8 @@ public function testDecryptVerifySignedOnly()
$signature = new Signature();
$signature->setId('LS9EdhGLaEUllGk3Snc0Bk+Cn3E');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258956761);
@@ -768,22 +737,22 @@ public function testDecryptVerifySignedOnly()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
// signed with first-keypair@example.com
// {{{ signed data
$signedData = <<gpg->decryptAndVerify($signedData);
@@ -799,7 +768,8 @@ public function testDecryptVerifyFirstSubKey()
$signature = new Signature();
$signature->setId('YUeHL9fEAK4hMokvXsNgUP5vaJ8');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1267228319);
@@ -815,30 +785,30 @@ public function testDecryptVerifyFirstSubKey()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
// encrypted with first subkey (ELG-E) of multiple-subkeys@example.com,
// signed with first-keypair@example.com
// {{{ encrypted data
$encryptedData = <<gpg->addDecryptKey('multiple-subkeys@example.com', 'test');
@@ -855,7 +825,8 @@ public function testDecryptVerifySecondSubKey()
$signature = new Signature();
$signature->setId('ZLZFDxxO+zdCEklUu6eppBCPCsA');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1267229043);
@@ -871,30 +842,30 @@ public function testDecryptVerifySecondSubKey()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
// encrypted with second subkey (RSA) of multiple-subkeys@example.com,
// signed with first-keypair@example.com
// {{{ encrypted data
$encryptedData = <<gpg->addDecryptKey('multiple-subkeys@example.com', 'test');
@@ -920,24 +891,24 @@ public function testDecryptVerifySignedOnlyBadSignature()
$expectedResults = [
'data' => "Hello, Bob! Goodbye, Alice!\n",
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
// {{{ clearsigned data
$clearsignedData = <<gpg->decryptAndVerify($clearsignedData);
@@ -953,7 +924,8 @@ public function testDecryptVerifyFile()
$signature = new Signature();
$signature->setId('kVwy2yYB0TlXyGd9FUvVYp5jCoI');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258220197);
@@ -970,7 +942,7 @@ public function testDecryptVerifyFile()
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$expectedResults = [
'data' => null,
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
$inputFilename = $this->getDataFilename('testDecryptVerifyFile.asc');
@@ -998,7 +970,8 @@ public function testDecryptVerifyFileToString()
$signature = new Signature();
$signature->setId('GTvYFmQ5yfMM/UOffkYCx21Se2M');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258221035);
@@ -1014,7 +987,7 @@ public function testDecryptVerifyFileToString()
$expectedResults = [
'data' => 'Hello, Alice! Goodbye, Bob!',
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
$inputFilename = $this->getDataFilename(
@@ -1037,7 +1010,8 @@ public function testDecryptVerifyFileNoPassphrase()
$signature = new Signature();
$signature->setId('unMY9l/f9sFaMvMV0H1ZuNJRY6Q');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258220226);
@@ -1054,7 +1028,7 @@ public function testDecryptVerifyFileNoPassphrase()
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$expectedResults = [
'data' => null,
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
$inputFilename = $this->getDataFilename(
@@ -1101,8 +1075,8 @@ public function testDecryptVerifyFileFileException_output()
// input file is encrypted with first-keypair@example.com
// output file does not exist
$inputFilename = $this->getDataFilename('testDecryptVerifyFile.asc');
- $outputFilename = './non-existent' .
- '/testDecryptVerifyFileFileException_output.plain';
+ $outputFilename = './non-existent'
+ . '/testDecryptVerifyFileFileException_output.plain';
$this->gpg->addDecryptKey('first-keypair@example.com', 'test1');
$this->gpg->decryptAndVerifyFile($inputFilename, $outputFilename);
@@ -1136,7 +1110,8 @@ public function testDecryptVerifyFileDual()
$signature = new Signature();
$signature->setId('7TYk0hpio90QZHHHb4UtgCWAEq4');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258220362);
@@ -1153,7 +1128,7 @@ public function testDecryptVerifyFileDual()
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$expectedResults = [
'data' => null,
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
$inputFilename = $this->getDataFilename(
@@ -1195,7 +1170,8 @@ public function testDecryptVerifyFileDualSignatories()
$signature1 = new Signature();
$signature1->setId('MF8xqL325bs7KiokMHTnHirF4go');
$signature1->setKeyFingerprint(
- '880922DBEA733E906693E4A903CC890AFA1DAD4B');
+ '880922DBEA733E906693E4A903CC890AFA1DAD4B'
+ );
$signature1->setKeyId('03CC890AFA1DAD4B');
$signature1->setCreationDate(1258220269);
@@ -1212,7 +1188,8 @@ public function testDecryptVerifyFileDualSignatories()
$signature2 = new Signature();
$signature2->setId('d0q7jibZpJSLpGAhNWhpSkZZeUg');
$signature2->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature2->setKeyId('C097D9EC94C06363');
$signature2->setCreationDate(1258220269);
@@ -1229,7 +1206,7 @@ public function testDecryptVerifyFileDualSignatories()
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$expectedResults = [
'data' => null,
- 'signatures' => [$signature1, $signature2]
+ 'signatures' => [$signature1, $signature2],
];
$inputFilename = $this->getDataFilename(
@@ -1258,7 +1235,8 @@ public function testDecryptVerifyFileDualOnePassphrase()
$signature = new Signature();
$signature->setId('kgyLjfFigxOrliyc8XlS6NaLJuw');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1258220334);
@@ -1275,7 +1253,7 @@ public function testDecryptVerifyFileDualOnePassphrase()
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$expectedResults = [
'data' => null,
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
$inputFilename = $this->getDataFilename(
@@ -1327,7 +1305,8 @@ public function testDecryptVerifyFileSignedOnly()
$signature = new Signature();
$signature->setId('vctnI/HnsRYmqcVwCJcJhS60lKU');
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$signature->setKeyId('C097D9EC94C06363');
$signature->setCreationDate(1221960707);
@@ -1344,7 +1323,7 @@ public function testDecryptVerifyFileSignedOnly()
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$expectedResults = [
'data' => null,
- 'signatures' => [$signature]
+ 'signatures' => [$signature],
];
$inputFilename = $this->getDataFilename(
diff --git a/tests/DecryptTest.php b/tests/DecryptTest.php
index 88be55f..695c13e 100644
--- a/tests/DecryptTest.php
+++ b/tests/DecryptTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Decryption tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit DecryptTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2009 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -50,8 +13,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class DecryptTest extends TestCase
{
@@ -65,26 +28,26 @@ public function testDecrypt()
// encrypted with first-keypair@example.com
// {{{ encrypted data
$encryptedData = <<gpg->addDecryptKey('first-keypair@example.com', 'test1');
@@ -103,26 +66,26 @@ public function testDecryptNoPassphrase()
// encrypted with no-passphrase@example.com
// {{{ encrypted data no passphrase
$encryptedData = <<gpg->decrypt($encryptedData);
@@ -139,26 +102,26 @@ public function testDecryptKeyNotFoundException()
// was encrypted with missing-key@example.com
// {{{ encrypted data
$encryptedData = <<gpg->decrypt($encryptedData);
@@ -196,26 +159,26 @@ public function testDecryptBadPassphraseException_missing()
// encrypted with first-keypair@example.com
// {{{ encrypted data
$encryptedData = <<gpg->decrypt($encryptedData);
@@ -229,33 +192,32 @@ public function testDecryptBadPassphraseException_bad()
// encrypted with first-keypair@example.com
// {{{ encrypted data
$encryptedData = <<gpg->addDecryptKey('first-keypair@example.com', 'incorrect');
$this->gpg->decrypt($encryptedData);
- }
- catch (Exceptions\BadPassphraseException $e) {
+ } catch (Exceptions\BadPassphraseException $e) {
$badKeys = $e->getBadPassphrases();
$missingKeys = $e->getMissingPassphrases();
@@ -279,37 +241,37 @@ public function testDecryptDual()
// second-keypair@example.com
// {{{ dual encrypted data
$encryptedData = <<gpg->decrypt($signedData);
@@ -470,26 +432,26 @@ public function testDecryptFirstSubKey()
// encrypted with first subkey (ELG-E) of multiple-subkeys@example.com
// {{{ encrypted data
$encryptedData = <<gpg->addDecryptKey('multiple-subkeys@example.com', 'test');
@@ -508,21 +470,21 @@ public function testDecryptSecondSubKey()
// encrypted with second subkey (RSA) of multiple-subkeys@example.com
// {{{ encrypted data
$encryptedData = <<gpg->addDecryptKey('multiple-subkeys@example.com', 'test');
@@ -570,11 +532,11 @@ public function testDecryptFileNoPassphrase()
{
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
- $inputFilename =
- $this->getDataFilename('testDecryptFileNoPassphrase.asc');
+ $inputFilename
+ = $this->getDataFilename('testDecryptFileNoPassphrase.asc');
- $outputFilename =
- $this->getTempFilename('testDecryptFileNoPassphrase.plain');
+ $outputFilename
+ = $this->getTempFilename('testDecryptFileNoPassphrase.plain');
// file is encrypted with no-passphrase@example.com
$this->gpg->decryptFile($inputFilename, $outputFilename);
@@ -591,8 +553,8 @@ public function testDecryptFileFileException_input()
$this->expectException(Exceptions\FileException::class);
// input file does not exist
- $inputFilename =
- $this->getDataFilename('testDecryptFileFileException_input.asc');
+ $inputFilename
+ = $this->getDataFilename('testDecryptFileFileException_input.asc');
$this->gpg->decryptFile($inputFilename);
}
@@ -607,8 +569,8 @@ public function testDecryptFileFileException_output()
// input file is encrypted with first-keypair@example.com
// output file does not exist
$inputFilename = $this->getDataFilename('testDecryptFile.asc');
- $outputFilename = './non-existent' .
- '/testDecryptFileFileException_output.plain';
+ $outputFilename = './non-existent'
+ . '/testDecryptFileFileException_output.plain';
$this->gpg->addDecryptKey('first-keypair@example.com', 'test1');
$this->gpg->decryptFile($inputFilename, $outputFilename);
@@ -622,11 +584,11 @@ public function testDecryptFileKeyNotFoundException()
$this->expectException(Exceptions\KeyNotFoundException::class);
// file is encrypted with missing-key@example.com
- $inputFilename =
- $this->getDataFilename('testDecryptFileKeyNotFoundException.asc');
+ $inputFilename
+ = $this->getDataFilename('testDecryptFileKeyNotFoundException.asc');
- $outputFilename =
- $this->getTempFilename('testDecryptFileKeyNotFoundException.plain');
+ $outputFilename
+ = $this->getTempFilename('testDecryptFileKeyNotFoundException.plain');
$this->gpg->decryptFile($inputFilename, $outputFilename);
}
@@ -662,11 +624,11 @@ public function testDecryptFileDualOnePassphrase()
{
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
- $inputFilename =
- $this->getDataFilename('testDecryptFileDualOnePassphrase.asc');
+ $inputFilename
+ = $this->getDataFilename('testDecryptFileDualOnePassphrase.asc');
- $outputFilename =
- $this->getTempFilename('testDecryptFileDualOnePassphrase.plain');
+ $outputFilename
+ = $this->getTempFilename('testDecryptFileDualOnePassphrase.plain');
// decrypt with no-passphrase
$this->gpg->decryptFile($inputFilename, $outputFilename);
@@ -699,11 +661,11 @@ public function testDecryptFileSignedData()
{
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
- $inputFilename =
- $this->getDataFilename('testVerifyFileNormalSignedData.asc');
+ $inputFilename
+ = $this->getDataFilename('testVerifyFileNormalSignedData.asc');
- $outputFilename =
- $this->getTempFilename('testDecryptFileSignedData.plain');
+ $outputFilename
+ = $this->getTempFilename('testDecryptFileSignedData.plain');
$this->gpg->decryptFile($inputFilename, $outputFilename);
diff --git a/tests/DeletePrivateKeyTest.php b/tests/DeletePrivateKeyTest.php
index 4e8a067..219adc9 100644
--- a/tests/DeletePrivateKeyTest.php
+++ b/tests/DeletePrivateKeyTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Private key deletion tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit DeletePrivateKeyTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG;
@@ -54,8 +17,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class DeletePrivateKeyTest extends TestCase
{
diff --git a/tests/DeletePublicKeyTest.php b/tests/DeletePublicKeyTest.php
index f3a715e..2b7ff01 100644
--- a/tests/DeletePublicKeyTest.php
+++ b/tests/DeletePublicKeyTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Public key deletion tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit DeletePublicKeyTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -50,8 +13,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class DeletePublicKeyTest extends TestCase
{
diff --git a/tests/EncryptAndSignTest.php b/tests/EncryptAndSignTest.php
index 3c7e696..a3639a6 100644
--- a/tests/EncryptAndSignTest.php
+++ b/tests/EncryptAndSignTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Encrypt and sign tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit EncryptSignTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2009 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -50,8 +13,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2009 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class EncryptAndSignTest extends TestCase
{
@@ -267,19 +230,21 @@ public function testEncryptAndSignFileNoPassphrase()
{
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$originalFilename = $this->getDataFilename('testFileMedium.plain');
- $encryptedFilename =
- $this->getTempFilename('testEncryptAndSignFileNoPassphrase.asc');
+ $encryptedFilename
+ = $this->getTempFilename('testEncryptAndSignFileNoPassphrase.asc');
- $decryptedFilename =
- $this->getTempFilename('testEncryptAndSignFileNoPassphrase.plain');
+ $decryptedFilename
+ = $this->getTempFilename('testEncryptAndSignFileNoPassphrase.plain');
$this->gpg->addSignKey('no-passphrase@example.com');
$this->gpg->addEncryptKey('first-keypair@example.com');
$this->gpg->encryptAndSignFile($originalFilename, $encryptedFilename);
$this->gpg->addDecryptKey('first-keypair@example.com', 'test1');
- $results = $this->gpg->decryptAndVerifyFile($encryptedFilename,
- $decryptedFilename);
+ $results = $this->gpg->decryptAndVerifyFile(
+ $encryptedFilename,
+ $decryptedFilename
+ );
$md5Sum = $this->getMd5Sum($decryptedFilename);
$this->assertEquals($expectedMd5Sum, $md5Sum);
@@ -297,19 +262,21 @@ public function testEncryptAndSignFile()
{
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$originalFilename = $this->getDataFilename('testFileMedium.plain');
- $encryptedFilename =
- $this->getTempFilename('testEncryptAndSignFileNoPassphrase.asc');
+ $encryptedFilename
+ = $this->getTempFilename('testEncryptAndSignFileNoPassphrase.asc');
- $decryptedFilename =
- $this->getTempFilename('testEncryptAndSignFileNoPassphrase.plain');
+ $decryptedFilename
+ = $this->getTempFilename('testEncryptAndSignFileNoPassphrase.plain');
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
$this->gpg->addEncryptKey('first-keypair@example.com');
$this->gpg->encryptAndSignFile($originalFilename, $encryptedFilename);
$this->gpg->addDecryptKey('first-keypair@example.com', 'test1');
- $results = $this->gpg->decryptAndVerifyFile($encryptedFilename,
- $decryptedFilename);
+ $results = $this->gpg->decryptAndVerifyFile(
+ $encryptedFilename,
+ $decryptedFilename
+ );
$md5Sum = $this->getMd5Sum($decryptedFilename);
$this->assertEquals($expectedMd5Sum, $md5Sum);
@@ -327,11 +294,11 @@ public function testEncryptAndSignFileDualOnePassphrase()
{
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$originalFilename = $this->getDataFilename('testFileMedium.plain');
- $encryptedFilename =
- $this->getTempFilename('testEncryptAndSignFileNoPassphrase.asc');
+ $encryptedFilename
+ = $this->getTempFilename('testEncryptAndSignFileNoPassphrase.asc');
- $decryptedFilename =
- $this->getTempFilename('testEncryptAndSignFileNoPassphrase.plain');
+ $decryptedFilename
+ = $this->getTempFilename('testEncryptAndSignFileNoPassphrase.plain');
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
$this->gpg->addSignKey('no-passphrase@example.com');
@@ -339,8 +306,10 @@ public function testEncryptAndSignFileDualOnePassphrase()
$this->gpg->encryptAndSignFile($originalFilename, $encryptedFilename);
$this->gpg->addDecryptKey('first-keypair@example.com', 'test1');
- $results = $this->gpg->decryptAndVerifyFile($encryptedFilename,
- $decryptedFilename);
+ $results = $this->gpg->decryptAndVerifyFile(
+ $encryptedFilename,
+ $decryptedFilename
+ );
$md5Sum = $this->getMd5Sum($decryptedFilename);
$this->assertEquals($expectedMd5Sum, $md5Sum);
@@ -358,11 +327,11 @@ public function testEncryptAndSignFileDual()
{
$expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
$originalFilename = $this->getDataFilename('testFileMedium.plain');
- $encryptedFilename =
- $this->getTempFilename('testEncryptAndSignFileNoPassphrase.asc');
+ $encryptedFilename
+ = $this->getTempFilename('testEncryptAndSignFileNoPassphrase.asc');
- $decryptedFilename =
- $this->getTempFilename('testEncryptAndSignFileNoPassphrase.plain');
+ $decryptedFilename
+ = $this->getTempFilename('testEncryptAndSignFileNoPassphrase.plain');
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
$this->gpg->addSignKey('second-keypair@example.com', 'test2');
@@ -370,8 +339,10 @@ public function testEncryptAndSignFileDual()
$this->gpg->encryptAndSignFile($originalFilename, $encryptedFilename);
$this->gpg->addDecryptKey('first-keypair@example.com', 'test1');
- $results = $this->gpg->decryptAndVerifyFile($encryptedFilename,
- $decryptedFilename);
+ $results = $this->gpg->decryptAndVerifyFile(
+ $encryptedFilename,
+ $decryptedFilename
+ );
$md5Sum = $this->getMd5Sum($decryptedFilename);
$this->assertEquals($expectedMd5Sum, $md5Sum);
@@ -391,7 +362,8 @@ public function testEncryptAndSignFileFileException_input()
// input file does not exist
$inputFilename = $this->getDataFilename(
- 'testEncryptAndSignFileFileFileException_input.plain');
+ 'testEncryptAndSignFileFileFileException_input.plain'
+ );
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
$this->gpg->addEncryptKey('first-keypair@example.com');
@@ -408,8 +380,8 @@ public function testEncryptAndSignFileFileException_output()
// input file is plaintext
// output file does not exist
$inputFilename = $this->getDataFilename('testFileMedium.plain');
- $outputFilename = './non-existent' .
- '/testEncryptAndSignFileFileException_output.plain';
+ $outputFilename = './non-existent'
+ . '/testEncryptAndSignFileFileException_output.plain';
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
$this->gpg->addEncryptKey('first-keypair@example.com');
@@ -422,8 +394,8 @@ public function testEncryptAndSignFileFileException_output()
public function testEncryptAndSignFileEmpty()
{
$originalFilename = $this->getDataFilename('testFileEmpty.plain');
- $encryptedFilename =
- $this->getTempFilename('testEncryptAndSignFileEmpty.asc');
+ $encryptedFilename
+ = $this->getTempFilename('testEncryptAndSignFileEmpty.asc');
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
$this->gpg->addEncryptKey('first-keypair@example.com');
diff --git a/tests/EncryptTest.php b/tests/EncryptTest.php
index 116d373..a8da65f 100644
--- a/tests/EncryptTest.php
+++ b/tests/EncryptTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Encryption tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit EncryptTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -50,8 +13,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class EncryptTest extends TestCase
{
@@ -217,8 +180,8 @@ public function testEncryptFileFileException_input()
$this->expectException(Exceptions\FileException::class);
// input file does not exist
- $filename =
- $this->getDataFilename('testEncryptFileFileException_input.plain');
+ $filename
+ = $this->getDataFilename('testEncryptFileFileException_input.plain');
$this->gpg->addEncryptKey('first-keypair@example.com');
$this->gpg->encryptFile($filename);
@@ -233,8 +196,8 @@ public function testEncryptFileFileException_output()
// output file does not exist
$inputFilename = $this->getDataFilename('testFileMedium.plain');
- $outputFilename = './non-existent' .
- '/testEncryptFileFileException_output.asc';
+ $outputFilename = './non-existent'
+ . '/testEncryptFileFileException_output.asc';
$this->gpg->addEncryptKey('first-keypair@example.com');
$this->gpg->encryptFile($inputFilename, $outputFilename);
diff --git a/tests/ExceptionsTest.php b/tests/ExceptionsTest.php
index 4eb06ee..e590c79 100644
--- a/tests/ExceptionsTest.php
+++ b/tests/ExceptionsTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Exception class test cases for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit ExceptionsTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2008-2011 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -50,8 +13,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2008-2011 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class ExceptionsTest extends TestCase
{
@@ -177,8 +140,11 @@ public function testBadPassphraseException()
*/
public function testBadPassphraseException_getBadPassphrases()
{
- $e = new Exceptions\BadPassphraseException('test exception', 0,
- ['C097D9EC94C06363', '9F93F9116728EF12']);
+ $e = new Exceptions\BadPassphraseException(
+ 'test exception',
+ 0,
+ ['C097D9EC94C06363', '9F93F9116728EF12']
+ );
$keyIds = $e->getBadPassphrases();
@@ -191,8 +157,12 @@ public function testBadPassphraseException_getBadPassphrases()
*/
public function testBadPassphraseException_getMissingPassphrase()
{
- $e = new Exceptions\BadPassphraseException('test exception', 0, [],
- ['C097D9EC94C06363', '9F93F9116728EF12']);
+ $e = new Exceptions\BadPassphraseException(
+ 'test exception',
+ 0,
+ [],
+ ['C097D9EC94C06363', '9F93F9116728EF12']
+ );
$keyIds = $e->getMissingPassphrases();
@@ -216,8 +186,11 @@ public function testDeletePrivateKeyException()
*/
public function testDeletePrivateKeyException_getKeyId()
{
- $e = new Exceptions\DeletePrivateKeyException('test exception', 0,
- '9F93F9116728EF12');
+ $e = new Exceptions\DeletePrivateKeyException(
+ 'test exception',
+ 0,
+ '9F93F9116728EF12'
+ );
$this->assertEquals('9F93F9116728EF12', $e->getKeyId());
}
diff --git a/tests/ExportPrivateKeyTest.php b/tests/ExportPrivateKeyTest.php
index af9bbbb..aba400d 100644
--- a/tests/ExportPrivateKeyTest.php
+++ b/tests/ExportPrivateKeyTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Private key export tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit ExportPrivateKeyTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -50,8 +13,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class ExportPrivateKeyTest extends TestCase
{
diff --git a/tests/ExportPublicKeyTest.php b/tests/ExportPublicKeyTest.php
index c093df8..c04a2f0 100644
--- a/tests/ExportPublicKeyTest.php
+++ b/tests/ExportPublicKeyTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Key export tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit ExportPublicKeyTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -50,8 +13,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class ExportPublicKeyTest extends TestCase
{
diff --git a/tests/GeneralTest.php b/tests/GeneralTest.php
index 66c984b..879b056 100644
--- a/tests/GeneralTest.php
+++ b/tests/GeneralTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * General test cases for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit GeneralTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG;
@@ -52,8 +15,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2008-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class GeneralTest extends TestCase
{
@@ -105,7 +68,7 @@ public function testHomedirFileException_NoExecute()
$nonExecutableDirectory = $this->getTempFilename('home-no-execute');
mkdir($nonExecutableDirectory);
- chmod($nonExecutableDirectory, 0600); // rw- --- ---
+ chmod($nonExecutableDirectory, 0o600); // rw- --- ---
new GPG(['homedir' => $nonExecutableDirectory]);
}
@@ -121,7 +84,7 @@ public function testHomedirFileException_NoWrite()
$nonWriteableDirectory = $this->getTempFilename('home-no-write');
mkdir($nonWriteableDirectory);
- chmod($nonWriteableDirectory, 0500); // r-x --- ---
+ chmod($nonWriteableDirectory, 0o500); // r-x --- ---
new GPG(['homedir' => $nonWriteableDirectory]);
}
@@ -168,8 +131,8 @@ public function testFluentInterface()
$this->assertEquals(
$this->gpg,
$returnedGpg,
- 'Failed asserting fluent interface works for addDecryptKey() ' .
- 'method.'
+ 'Failed asserting fluent interface works for addDecryptKey() '
+ . 'method.'
);
$returnedGpg = $this->gpg->addEncryptKey(
@@ -178,8 +141,8 @@ public function testFluentInterface()
$this->assertEquals(
$this->gpg,
$returnedGpg,
- 'Failed asserting fluent interface works for addEncryptKey() ' .
- 'method.'
+ 'Failed asserting fluent interface works for addEncryptKey() '
+ . 'method.'
);
$returnedGpg = $this->gpg->addSignKey(
@@ -189,32 +152,32 @@ public function testFluentInterface()
$this->assertEquals(
$this->gpg,
$returnedGpg,
- 'Failed asserting fluent interface works for addSignKey() ' .
- 'method.'
+ 'Failed asserting fluent interface works for addSignKey() '
+ . 'method.'
);
$returnedGpg = $this->gpg->clearDecryptKeys();
$this->assertEquals(
$this->gpg,
$returnedGpg,
- 'Failed asserting fluent interface works for clearDecryptKeys() ' .
- 'method.'
+ 'Failed asserting fluent interface works for clearDecryptKeys() '
+ . 'method.'
);
$returnedGpg = $this->gpg->clearEncryptKeys();
$this->assertEquals(
$this->gpg,
$returnedGpg,
- 'Failed asserting fluent interface works for clearEncryptKeys() ' .
- 'method.'
+ 'Failed asserting fluent interface works for clearEncryptKeys() '
+ . 'method.'
);
$returnedGpg = $this->gpg->clearSignKeys();
$this->assertEquals(
$this->gpg,
$returnedGpg,
- 'Failed asserting fluent interface works for clearSignKeys() ' .
- 'method.'
+ 'Failed asserting fluent interface works for clearSignKeys() '
+ . 'method.'
);
}
}
diff --git a/tests/GetFingerprintTest.php b/tests/GetFingerprintTest.php
index d40a160..e9adafb 100644
--- a/tests/GetFingerprintTest.php
+++ b/tests/GetFingerprintTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Fingerprint retrieval tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit GetFingerprintTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG;
@@ -50,8 +13,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class GetFingerprintTest extends TestCase
{
@@ -82,8 +45,8 @@ public function testGetFingerprintNull()
public function testGetFingerprintX509()
{
$keyId = 'public-only@example.com';
- $expectedFingerprint =
- 'F8:31:18:CB:6F:58:92:DC:1C:3E:93:6D:AB:A8:1E:F5:4E:8C:0D:EB';
+ $expectedFingerprint
+ = 'F8:31:18:CB:6F:58:92:DC:1C:3E:93:6D:AB:A8:1E:F5:4E:8C:0D:EB';
$fingerprint = $this->gpg->getFingerprint($keyId, GPG::FORMAT_X509);
@@ -96,8 +59,8 @@ public function testGetFingerprintX509()
public function testGetFingerprintCanonical()
{
$keyId = 'public-only@example.com';
- $expectedFingerprint =
- 'F831 18CB 6F58 92DC 1C3E 936D ABA8 1EF5 4E8C 0DEB';
+ $expectedFingerprint
+ = 'F831 18CB 6F58 92DC 1C3E 936D ABA8 1EF5 4E8C 0DEB';
$fingerprint = $this->gpg->getFingerprint($keyId, GPG::FORMAT_CANONICAL);
diff --git a/tests/GetKeysTest.php b/tests/GetKeysTest.php
index 674c691..08f278c 100644
--- a/tests/GetKeysTest.php
+++ b/tests/GetKeysTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Key retrieval tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit GetKeysTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG;
@@ -54,8 +17,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class GetKeysTest extends TestCase
{
diff --git a/tests/ImportKeyTest.php b/tests/ImportKeyTest.php
index d654436..13d35e6 100644
--- a/tests/ImportKeyTest.php
+++ b/tests/ImportKeyTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Key import tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit ImportKeyTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -50,8 +13,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class ImportKeyTest extends TestCase
{
@@ -79,47 +42,47 @@ public function testImportKey_private()
'public_imported' => 0,
'public_unchanged' => 1,
'private_imported' => 1,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
// {{{ private key data
$privateKeyData = <<gpg->importKey($privateKeyData);
@@ -137,44 +100,44 @@ public function testImportKey_public()
'public_imported' => 1,
'public_unchanged' => 0,
'private_imported' => 0,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
// {{{ public key data
$publicKeyData = <<gpg->importKey($publicKeyData);
@@ -188,42 +151,42 @@ public function testImportKeyAlreadyImported_private()
{
// {{{ private key data
$privateKeyData = <<gpg->importKey($privateKeyData);
@@ -234,7 +197,7 @@ public function testImportKeyAlreadyImported_private()
'public_imported' => 0,
'public_unchanged' => 1,
'private_imported' => 1,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
$this->assertEquals($expectedResult, $result);
@@ -260,39 +223,39 @@ public function testImportKeyAlreadyImported_public()
{
// {{{ public key data
$publicKeyData = <<gpg->importKey($publicKeyData);
@@ -303,7 +266,7 @@ public function testImportKeyAlreadyImported_public()
'public_imported' => 1,
'public_unchanged' => 0,
'private_imported' => 0,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
$this->assertEquals($expectedResult, $result);
@@ -316,7 +279,7 @@ public function testImportKeyAlreadyImported_public()
'public_imported' => 0,
'public_unchanged' => 1,
'private_imported' => 0,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
$this->assertEquals($expectedResult, $result);
@@ -355,7 +318,7 @@ public function testImportKeyFile_private()
'public_imported' => 0,
'public_unchanged' => 1,
'private_imported' => 1,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
$filename = $this->getDataFilename('testImportKeyFile_private.asc');
@@ -375,7 +338,7 @@ public function testImportKeyFile_public()
'public_imported' => 1,
'public_unchanged' => 0,
'private_imported' => 0,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
$filename = $this->getDataFilename('testImportKeyFile_public.asc');
@@ -398,7 +361,7 @@ public function testImportKeyFileAlreadyImported_private()
'public_imported' => 0,
'public_unchanged' => 1,
'private_imported' => 1,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
$this->assertEquals($expectedResult, $result);
@@ -431,7 +394,7 @@ public function testImportKeyFileAlreadyImported_public()
'public_imported' => 1,
'public_unchanged' => 0,
'private_imported' => 0,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
$this->assertEquals($expectedResult, $result);
@@ -444,7 +407,7 @@ public function testImportKeyFileAlreadyImported_public()
'public_imported' => 0,
'public_unchanged' => 1,
'private_imported' => 0,
- 'private_unchanged' => 0
+ 'private_unchanged' => 0,
];
$this->assertEquals($expectedResult, $result);
diff --git a/tests/KeyEditorTest.php b/tests/KeyEditorTest.php
index 9778d30..0609c5d 100644
--- a/tests/KeyEditorTest.php
+++ b/tests/KeyEditorTest.php
@@ -2,33 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * KeyEditor class test cases for the Crypt_GPG package.
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Aleksander Machniak
- * @copyright Apheleia IT AG
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG;
@@ -43,8 +16,8 @@
* @package Crypt_GPG
* @author Aleksander Machniak
* @copyright Apheleia IT AG
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class KeyEditorTest extends TestCase
{
@@ -70,7 +43,7 @@ public function testAddUserId()
$user = new UserId([
'name' => 'Alice',
'comment' => 'shipping',
- 'email' => 'alice@example.com'
+ 'email' => 'alice@example.com',
]);
$keyEditor->edit('first-keypair@example.com', 'test1')
@@ -82,7 +55,9 @@ public function testAddUserId()
$userIds = $keys[0]->getUserIds();
$this->assertCount(2, $userIds);
- $userIds = array_filter($userIds, function ($id) use ($user) { return $id->getName() == $user->getName(); });
+ $userIds = array_filter($userIds, function ($id) use ($user) {
+ return $id->getName() == $user->getName();
+ });
$this->assertCount(1, $userIds);
$userId = $userIds[key($userIds)];
@@ -93,7 +68,7 @@ public function testAddUserId()
$user = new UserId([
'name' => 'Alice2',
'comment' => '',
- 'email' => 'alice2@example.com'
+ 'email' => 'alice2@example.com',
]);
$keyEditor->edit('first-keypair@example.com', 'test1')
@@ -105,7 +80,9 @@ public function testAddUserId()
$userIds = $keys[0]->getUserIds();
$this->assertCount(2, $userIds);
- $userIds = array_filter($userIds, function ($id) use ($user) { return $id->getName() == $user->getName(); });
+ $userIds = array_filter($userIds, function ($id) use ($user) {
+ return $id->getName() == $user->getName();
+ });
$this->assertCount(0, $userIds);
// Test editing a key that has no secret key
@@ -128,19 +105,19 @@ public function testDeleteUserId()
$user1 = new UserId([
'name' => 'Alice',
'comment' => 'shipping',
- 'email' => 'alice@example.com'
+ 'email' => 'alice@example.com',
]);
$user2 = new UserId([
'name' => 'Jonathan',
'comment' => '',
- 'email' => 'john@example.com'
+ 'email' => 'john@example.com',
]);
$user3 = new UserId([
'name' => '',
'comment' => '',
- 'email' => 'john@example.com'
+ 'email' => 'john@example.com',
]);
$keyEditor->edit('second-keypair@example.com', 'test2')
@@ -155,7 +132,9 @@ public function testDeleteUserId()
$keys = $this->gpg->getKeys('second-keypair@example.com');
$userIds = $keys[0]->getUserIds();
$this->assertCount(3, $userIds);
- $userIds = array_filter($userIds, function ($id) use ($user1) { return $id->getEmail() != $user1->getEmail(); });
+ $userIds = array_filter($userIds, function ($id) use ($user1) {
+ return $id->getEmail() != $user1->getEmail();
+ });
$this->assertCount(3, $userIds);
// Test deleting users with no name or no comment
@@ -167,7 +146,9 @@ public function testDeleteUserId()
$keys = $this->gpg->getKeys('second-keypair@example.com');
$userIds = $keys[0]->getUserIds();
$this->assertCount(1, $userIds);
- $userIds = array_filter($userIds, function ($id) use ($user1) { return $id->getEmail() != $user1->getEmail(); });
+ $userIds = array_filter($userIds, function ($id) use ($user1) {
+ return $id->getEmail() != $user1->getEmail();
+ });
$this->assertCount(1, $userIds);
// Test deleting the last user
@@ -247,7 +228,9 @@ public function testRevokeUserId()
$keys = $this->gpg->getKeys('second-keypair@example.com');
$userIds = $keys[0]->getUserIds();
$this->assertCount(2, $userIds);
- $userIds = array_values(array_filter($userIds, function ($id) use ($user1) { return $id->getEmail() == $user1->getEmail(); }));
+ $userIds = array_values(array_filter($userIds, function ($id) use ($user1) {
+ return $id->getEmail() == $user1->getEmail();
+ }));
$this->assertCount(1, $userIds);
$this->assertTrue($userIds[0]->isRevoked());
diff --git a/tests/KeyGeneratorTest.php b/tests/KeyGeneratorTest.php
index 9f199a3..dee39bc 100644
--- a/tests/KeyGeneratorTest.php
+++ b/tests/KeyGeneratorTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Key generation tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit KeyGeneratorTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2011 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -54,8 +17,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2011 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class KeyGeneratorTest extends TestCase
{
diff --git a/tests/KeyTest.php b/tests/KeyTest.php
index 0a3496a..8a55852 100644
--- a/tests/KeyTest.php
+++ b/tests/KeyTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Key class test cases for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit KeyTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Key;
@@ -52,8 +15,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class KeyTest extends TestCase
{
@@ -73,7 +36,7 @@ public function testGetSubKeys()
'expiration' => 0,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$key->addSubKey($firstSubKey);
@@ -87,30 +50,43 @@ public function testGetSubKeys()
'expiration' => 0,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$key->addSubKey($secondSubKey);
$subKeys = $key->getSubKeys();
- $this->assertEquals(2, count($subKeys),
- 'Failed to assert number of returned sub-keys is the same as ' .
- 'the number of sub-keys added.');
+ $this->assertEquals(
+ 2,
+ count($subKeys),
+ 'Failed to assert number of returned sub-keys is the same as '
+ . 'the number of sub-keys added.'
+ );
- $this->assertContainsOnly(SubKey::class, $subKeys, false,
- 'Failed to assert all returned sub-keys are Crypt_GPG_SubKey ' .
- 'objects.');
+ $this->assertContainsOnly(
+ SubKey::class,
+ $subKeys,
+ false,
+ 'Failed to assert all returned sub-keys are Crypt_GPG_SubKey '
+ . 'objects.'
+ );
$this->assertArrayHasKey(0, $subKeys);
- $this->assertEquals($subKeys[0], $firstSubKey,
- 'Failed to assert the first sub-key is the same as the first ' .
- 'added sub-key.');
+ $this->assertEquals(
+ $subKeys[0],
+ $firstSubKey,
+ 'Failed to assert the first sub-key is the same as the first '
+ . 'added sub-key.'
+ );
$this->assertArrayHasKey(1, $subKeys);
- $this->assertEquals($subKeys[1], $secondSubKey,
- 'Failed to assert the second sub-key is the same as the second ' .
- 'added sub-key.');
+ $this->assertEquals(
+ $subKeys[1],
+ $secondSubKey,
+ 'Failed to assert the second sub-key is the same as the second '
+ . 'added sub-key.'
+ );
}
/**
@@ -123,7 +99,7 @@ public function testGetUserIds()
$firstUserId = new UserId([
'name' => 'Alice',
'comment' => 'shipping',
- 'email' => 'alice@example.com'
+ 'email' => 'alice@example.com',
]);
$key->addUserId($firstUserId);
@@ -131,30 +107,43 @@ public function testGetUserIds()
$secondUserId = new UserId([
'name' => 'Bob',
'comment' => 'receiving',
- 'email' => 'bob@example.com'
+ 'email' => 'bob@example.com',
]);
$key->addUserId($secondUserId);
$userIds = $key->getUserIds();
- $this->assertCount(2, $userIds,
- 'Failed to assert number of returned user ids is the same as ' .
- 'the number of user ids added.');
+ $this->assertCount(
+ 2,
+ $userIds,
+ 'Failed to assert number of returned user ids is the same as '
+ . 'the number of user ids added.'
+ );
- $this->assertContainsOnly(UserId::class, $userIds, false,
- 'Failed to assert all returned user ids are UserId ' .
- 'objects.');
+ $this->assertContainsOnly(
+ UserId::class,
+ $userIds,
+ false,
+ 'Failed to assert all returned user ids are UserId '
+ . 'objects.'
+ );
$this->assertArrayHasKey(0, $userIds);
- $this->assertEquals($userIds[0], $firstUserId,
- 'Failed to assert the first user id is the same as the first ' .
- 'added user id.');
+ $this->assertEquals(
+ $userIds[0],
+ $firstUserId,
+ 'Failed to assert the first user id is the same as the first '
+ . 'added user id.'
+ );
$this->assertArrayHasKey(1, $userIds);
- $this->assertEquals($userIds[1], $secondUserId,
- 'Failed to assert the second user id is the same as the second ' .
- 'added user id.');
+ $this->assertEquals(
+ $userIds[1],
+ $secondUserId,
+ 'Failed to assert the second user id is the same as the second '
+ . 'added user id.'
+ );
}
/**
@@ -173,7 +162,7 @@ public function testGetPrimaryKey()
'expiration' => 0,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$key->addSubKey($firstSubKey);
@@ -187,16 +176,19 @@ public function testGetPrimaryKey()
'expiration' => 0,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$key->addSubKey($secondSubKey);
$primaryKey = $key->getPrimaryKey();
- $this->assertEquals($firstSubKey, $primaryKey,
- 'Failed to assert the primary key is the same as the first added ' .
- 'sub-key.');
+ $this->assertEquals(
+ $firstSubKey,
+ $primaryKey,
+ 'Failed to assert the primary key is the same as the first added '
+ . 'sub-key.'
+ );
}
/**
@@ -329,7 +321,7 @@ public function test__toString()
'expiration' => 0,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertSame((string) $key, '');
@@ -348,8 +340,11 @@ public function testAddSubKey()
$subKeys = $key->getSubKeys();
- $this->assertCount(0, $subKeys,
- 'Failed to assert there are no sub-keys.');
+ $this->assertCount(
+ 0,
+ $subKeys,
+ 'Failed to assert there are no sub-keys.'
+ );
// add first sub-key
$firstSubKey = new SubKey([
@@ -361,25 +356,35 @@ public function testAddSubKey()
'expiration' => 0,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$key->addSubKey($firstSubKey);
$subKeys = $key->getSubKeys();
- $this->assertCount(1, $subKeys,
- 'Failed to assert number of returned sub-keys is the same as ' .
- 'the number of sub-keys added.');
+ $this->assertCount(
+ 1,
+ $subKeys,
+ 'Failed to assert number of returned sub-keys is the same as '
+ . 'the number of sub-keys added.'
+ );
- $this->assertContainsOnly(SubKey::class, $subKeys, false,
- 'Failed to assert all returned sub-keys are SubKey ' .
- 'objects.');
+ $this->assertContainsOnly(
+ SubKey::class,
+ $subKeys,
+ false,
+ 'Failed to assert all returned sub-keys are SubKey '
+ . 'objects.'
+ );
$this->assertArrayHasKey(0, $subKeys);
- $this->assertEquals($subKeys[0], $firstSubKey,
- 'Failed to assert the first sub-key is the same as the first ' .
- 'added sub-key.');
+ $this->assertEquals(
+ $subKeys[0],
+ $firstSubKey,
+ 'Failed to assert the first sub-key is the same as the first '
+ . 'added sub-key.'
+ );
// add second sub-key
$secondSubKey = new SubKey([
@@ -391,29 +396,42 @@ public function testAddSubKey()
'expiration' => 0,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$key->addSubKey($secondSubKey);
$subKeys = $key->getSubKeys();
- $this->assertCount(2, $subKeys,
- 'Failed to assert number of returned sub-keys is the same as ' .
- 'the number of sub-keys added.');
+ $this->assertCount(
+ 2,
+ $subKeys,
+ 'Failed to assert number of returned sub-keys is the same as '
+ . 'the number of sub-keys added.'
+ );
- $this->assertContainsOnly(SubKey::class, $subKeys, false,
- 'Failed to assert all returned sub-keys are SubKey objects.');
+ $this->assertContainsOnly(
+ SubKey::class,
+ $subKeys,
+ false,
+ 'Failed to assert all returned sub-keys are SubKey objects.'
+ );
$this->assertArrayHasKey(0, $subKeys);
- $this->assertEquals($subKeys[0], $firstSubKey,
- 'Failed to assert the first sub-key is the same as the first ' .
- 'added sub-key.');
+ $this->assertEquals(
+ $subKeys[0],
+ $firstSubKey,
+ 'Failed to assert the first sub-key is the same as the first '
+ . 'added sub-key.'
+ );
$this->assertArrayHasKey(1, $subKeys);
- $this->assertEquals($subKeys[1], $secondSubKey,
- 'Failed to assert the second sub-key is the same as the second ' .
- 'added sub-key.');
+ $this->assertEquals(
+ $subKeys[1],
+ $secondSubKey,
+ 'Failed to assert the second sub-key is the same as the second '
+ . 'added sub-key.'
+ );
}
/**
@@ -431,53 +449,76 @@ public function testAddUserId()
$firstUserId = new UserId([
'name' => 'Alice',
'comment' => 'shipping',
- 'email' => 'alice@example.com'
+ 'email' => 'alice@example.com',
]);
$key->addUserId($firstUserId);
$userIds = $key->getUserIds();
- $this->assertCount(1, $userIds,
- 'Failed to assert number of returned user ids is the same as ' .
- 'the number of user ids added.');
+ $this->assertCount(
+ 1,
+ $userIds,
+ 'Failed to assert number of returned user ids is the same as '
+ . 'the number of user ids added.'
+ );
- $this->assertContainsOnly(UserId::class, $userIds, false,
- 'Failed to assert all returned user ids are UserId objects.');
+ $this->assertContainsOnly(
+ UserId::class,
+ $userIds,
+ false,
+ 'Failed to assert all returned user ids are UserId objects.'
+ );
$this->assertArrayHasKey(0, $userIds);
- $this->assertEquals($userIds[0], $firstUserId,
- 'Failed to assert the first user id is the same as the first ' .
- 'added user id.');
+ $this->assertEquals(
+ $userIds[0],
+ $firstUserId,
+ 'Failed to assert the first user id is the same as the first '
+ . 'added user id.'
+ );
// add second user id
$secondUserId = new UserId([
'name' => 'Bob',
'comment' => 'receiving',
- 'email' => 'bob@example.com'
+ 'email' => 'bob@example.com',
]);
$key->addUserId($secondUserId);
$userIds = $key->getUserIds();
- $this->assertCount(2, $userIds,
- 'Failed to assert number of returned user ids is the same as ' .
- 'the number of user ids added.');
+ $this->assertCount(
+ 2,
+ $userIds,
+ 'Failed to assert number of returned user ids is the same as '
+ . 'the number of user ids added.'
+ );
- $this->assertContainsOnly(UserId::class, $userIds, false,
- 'Failed to assert all returned user ids are UserId ' .
- 'objects.');
+ $this->assertContainsOnly(
+ UserId::class,
+ $userIds,
+ false,
+ 'Failed to assert all returned user ids are UserId '
+ . 'objects.'
+ );
$this->assertArrayHasKey(0, $userIds);
- $this->assertEquals($userIds[0], $firstUserId,
- 'Failed to assert the first user id is the same as the first ' .
- 'added user id.');
+ $this->assertEquals(
+ $userIds[0],
+ $firstUserId,
+ 'Failed to assert the first user id is the same as the first '
+ . 'added user id.'
+ );
$this->assertArrayHasKey(1, $userIds);
- $this->assertEquals($userIds[1], $secondUserId,
- 'Failed to assert the second user id is the same as the second ' .
- 'added user id.');
+ $this->assertEquals(
+ $userIds[1],
+ $secondUserId,
+ 'Failed to assert the second user id is the same as the second '
+ . 'added user id.'
+ );
}
/**
@@ -497,7 +538,7 @@ public function testFluentInterface()
'expiration' => 0,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$returnedKey = $key->addSubKey($firstSubKey);
@@ -511,7 +552,7 @@ public function testFluentInterface()
$firstUserId = new UserId([
'name' => 'Alice',
'comment' => 'shipping',
- 'email' => 'alice@example.com'
+ 'email' => 'alice@example.com',
]);
$returnedKey = $key->addUserId($firstUserId);
diff --git a/tests/SignTest.php b/tests/SignTest.php
index 2ed4cc9..0255b3a 100644
--- a/tests/SignTest.php
+++ b/tests/SignTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Signing tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit SignTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG;
@@ -52,8 +15,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class SignTest extends TestCase
{
@@ -308,8 +271,8 @@ public function testSignDetachedTextmode()
public function testSignFileNoPassphrase()
{
$inputFilename = $this->getDataFilename('testFileMedium.plain');
- $outputFilename =
- $this->getTempFilename('testSignFileNoPassphrase.asc');
+ $outputFilename
+ = $this->getTempFilename('testSignFileNoPassphrase.asc');
$this->gpg->addSignKey('no-passphrase@example.com');
$this->gpg->signFile($inputFilename, $outputFilename);
@@ -399,8 +362,8 @@ public function testSignFileDetachedToString()
public function testSignFileDualOnePassphrase()
{
$inputFilename = $this->getDataFilename('testFileMedium.plain');
- $outputFilename =
- $this->getTempFilename('testSignFileDualOnePassphrase.asc');
+ $outputFilename
+ = $this->getTempFilename('testSignFileDualOnePassphrase.asc');
$this->gpg->addSignKey('no-passphrase@example.com');
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
@@ -457,8 +420,8 @@ public function testSignFileDualClear()
public function testSignFileDualDetached()
{
$inputFilename = $this->getDataFilename('testFileMedium.plain');
- $outputFilename =
- $this->getTempFilename('testSignFileDualDetached.asc');
+ $outputFilename
+ = $this->getTempFilename('testSignFileDualDetached.asc');
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
$this->gpg->addSignKey('second-keypair@example.com', 'test2');
@@ -481,8 +444,8 @@ public function testSignFileFileException_input()
$this->expectException(Exceptions\FileException::class);
// input file does not exist
- $inputFilename =
- $this->getDataFilename('testSignFileFileFileException_input.plain');
+ $inputFilename
+ = $this->getDataFilename('testSignFileFileFileException_input.plain');
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
$this->gpg->signFile($inputFilename);
@@ -498,8 +461,8 @@ public function testSignFileFileException_output()
// input file is encrypted with first-keypair@example.com
// output file does not exist
$inputFilename = $this->getDataFilename('testFileMedium.plain');
- $outputFilename = './non-existent' .
- '/testSignFileFileException_output.plain';
+ $outputFilename = './non-existent'
+ . '/testSignFileFileException_output.plain';
$this->gpg->addSignKey('first-keypair@example.com', 'test1');
$this->gpg->signFile($inputFilename, $outputFilename);
diff --git a/tests/SignatureCreationInfoTest.php b/tests/SignatureCreationInfoTest.php
index b5ad873..cd46131 100644
--- a/tests/SignatureCreationInfoTest.php
+++ b/tests/SignatureCreationInfoTest.php
@@ -1,32 +1,6 @@
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
namespace Crypt\GPG\Tests;
@@ -40,8 +14,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class SignatureCreationInfoTest extends TestCase
{
diff --git a/tests/SignatureTest.php b/tests/SignatureTest.php
index 7cacaee..52b2305 100644
--- a/tests/SignatureTest.php
+++ b/tests/SignatureTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Signature class test cases for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit SignatureTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2011 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Signature;
@@ -51,8 +14,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class SignatureTest extends TestCase
{
@@ -68,7 +31,7 @@ public function testConstructFromSignature()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => false,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature = new Signature($expectedSignature);
@@ -88,14 +51,18 @@ public function testConstructFromArray()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => false,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
- $this->assertEquals('KuhELanvhPRXozEjFWb2mam1q20',
- $signature->getId());
+ $this->assertEquals(
+ 'KuhELanvhPRXozEjFWb2mam1q20',
+ $signature->getId()
+ );
- $this->assertEquals('8D2299D9C5C211128B32BBB0C097D9EC94C06363',
- $signature->getKeyFingerprint());
+ $this->assertEquals(
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363',
+ $signature->getKeyFingerprint()
+ );
$this->assertEquals('0C097D9EC94C06363', $signature->getKeyId());
@@ -104,8 +71,10 @@ public function testConstructFromArray()
$this->assertFalse($signature->isValid());
- $this->assertEquals('Alice ',
- strval($signature->getUserId()));
+ $this->assertEquals(
+ 'Alice ',
+ strval($signature->getUserId())
+ );
}
/**
@@ -119,7 +88,7 @@ public function testGetId()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => false,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$this->assertEquals('KuhELanvhPRXozEjFWb2mam1q20', $signature->getId());
@@ -136,11 +105,13 @@ public function testGetKeyFingerprint()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => false,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
- $this->assertEquals('8D2299D9C5C211128B32BBB0C097D9EC94C06363',
- $signature->getKeyFingerprint());
+ $this->assertEquals(
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363',
+ $signature->getKeyFingerprint()
+ );
}
/**
@@ -155,7 +126,7 @@ public function testGetKeyId()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => false,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$this->assertEquals('0C097D9EC94C06363', $signature->getKeyId());
@@ -172,7 +143,7 @@ public function testGetCreationDate()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => false,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$this->assertEquals(1221785858, $signature->getCreationDate());
@@ -189,7 +160,7 @@ public function testGetExpirationDate()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => false,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$this->assertEquals(1421785858, $signature->getExpirationDate());
@@ -206,7 +177,7 @@ public function testIsValid()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$this->assertTrue($signature->isValid());
@@ -217,7 +188,7 @@ public function testIsValid()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => false,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$this->assertFalse($signature->isValid());
@@ -234,12 +205,12 @@ public function testGetUserId()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$expectedUserId = new UserId([
'name' => 'Alice',
- 'email' => 'alice@example.com'
+ 'email' => 'alice@example.com',
]);
$this->assertEquals($expectedUserId, $signature->getUserId());
@@ -256,7 +227,7 @@ public function testSetId()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature = new Signature([
@@ -265,7 +236,7 @@ public function testSetId()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature->setId('KuhELanvhPRXozEjFWb2mam1q20');
@@ -284,7 +255,7 @@ public function testSetKeyFingerprint()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature = new Signature([
@@ -293,11 +264,12 @@ public function testSetKeyFingerprint()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature->setKeyFingerprint(
- '8D2299D9C5C211128B32BBB0C097D9EC94C06363');
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363'
+ );
$this->assertEquals($expectedSignature, $signature);
}
@@ -314,7 +286,7 @@ public function testSetKeyId()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature = new Signature([
@@ -324,7 +296,7 @@ public function testSetKeyId()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature->setKeyId('0C097D9EC94C06363');
@@ -343,7 +315,7 @@ public function testSetCreationDate()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature = new Signature([
@@ -352,7 +324,7 @@ public function testSetCreationDate()
'creation' => 1111111111,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature->setCreationDate(1221785858);
@@ -371,7 +343,7 @@ public function testSetExpirationDate()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature = new Signature([
@@ -380,7 +352,7 @@ public function testSetExpirationDate()
'creation' => 1221785858,
'expiration' => 0,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature->setExpirationDate(1421785858);
@@ -399,7 +371,7 @@ public function testSetValid()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature = new Signature([
@@ -408,7 +380,7 @@ public function testSetValid()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => false,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature->setValid(true);
@@ -427,7 +399,7 @@ public function testSetUserId()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Alice '
+ 'userId' => 'Alice ',
]);
$signature = new Signature([
@@ -436,12 +408,12 @@ public function testSetUserId()
'creation' => 1221785858,
'expiration' => 1421785858,
'valid' => true,
- 'userId' => 'Bob '
+ 'userId' => 'Bob ',
]);
$userId = new UserId([
'name' => 'Alice',
- 'email' => 'alice@example.com'
+ 'email' => 'alice@example.com',
]);
$signature->setUserId($userId);
@@ -469,8 +441,8 @@ public function testFluentInterface()
$this->assertEquals(
$signature,
$returnedSignature,
- 'Failed asserting fluent interface works for setKeyFingerprint() ' .
- 'method.'
+ 'Failed asserting fluent interface works for setKeyFingerprint() '
+ . 'method.'
);
$signature = new Signature();
@@ -486,8 +458,8 @@ public function testFluentInterface()
$this->assertEquals(
$signature,
$returnedSignature,
- 'Failed asserting fluent interface works for setCreationDate() ' .
- 'method.'
+ 'Failed asserting fluent interface works for setCreationDate() '
+ . 'method.'
);
$signature = new Signature();
@@ -495,8 +467,8 @@ public function testFluentInterface()
$this->assertEquals(
$signature,
$returnedSignature,
- 'Failed asserting fluent interface works for setExpirationDate() ' .
- 'method.'
+ 'Failed asserting fluent interface works for setExpirationDate() '
+ . 'method.'
);
$signature = new Signature();
diff --git a/tests/SubKeyTest.php b/tests/SubKeyTest.php
index ef0a83d..6ae9f29 100644
--- a/tests/SubKeyTest.php
+++ b/tests/SubKeyTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Sub-key class test cases for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit SubKeyTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\SubKey;
@@ -51,8 +14,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class SubKeyTest extends TestCase
{
@@ -69,7 +32,7 @@ public function testConstructFromString()
'expiration' => 0,
'canSign' => false,
'canEncrypt' => true,
- 'isRevoked' => true
+ 'isRevoked' => true,
]);
$string = 'sub:r:2048:16:8C37DBD2A01B7976:1221528655::::::e:';
@@ -93,7 +56,7 @@ public function testConstructFromSubKey()
'canSign' => false,
'canEncrypt' => true,
'hasPrivate' => true,
- 'isRevoked' => true
+ 'isRevoked' => true,
]);
$subKey = new SubKey($expectedSubKey);
@@ -116,15 +79,19 @@ public function testConstructFromArray()
'canSign' => false,
'canEncrypt' => true,
'hasPrivate' => true,
- 'isRevoked' => true
+ 'isRevoked' => true,
]);
$this->assertEquals('8C37DBD2A01B7976', $subKey->getId());
- $this->assertEquals(SubKey::ALGORITHM_ELGAMAL_ENC,
- $subKey->getAlgorithm());
+ $this->assertEquals(
+ SubKey::ALGORITHM_ELGAMAL_ENC,
+ $subKey->getAlgorithm()
+ );
- $this->assertEquals('8D2299D9C5C211128B32BBB0C097D9EC94C06363',
- $subKey->getFingerprint());
+ $this->assertEquals(
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363',
+ $subKey->getFingerprint()
+ );
$this->assertEquals(2048, $subKey->getLength());
$this->assertFalse($subKey->canSign());
@@ -154,7 +121,7 @@ public function testParse()
'expiration' => 3321785858,
'canSign' => false,
'canEncrypt' => true,
- 'isRevoked' => true
+ 'isRevoked' => true,
]);
$string = 'sub:r:2048:16:8C37DBD2A01B7976:1221528655:3321785858:::::e:';
@@ -183,7 +150,7 @@ public function testParseCreationDateIso()
'creation' => 1221442255,
'expiration' => 0,
'canSign' => false,
- 'canEncrypt' => true
+ 'canEncrypt' => true,
]);
$string = 'sub:u:2048:16:8C37DBD2A01B7976:20080915T013055::::::e:';
@@ -206,7 +173,7 @@ public function testGetId()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertEquals('8C37DBD2A01B7976', $subKey->getId());
@@ -226,11 +193,13 @@ public function testGetAlgorithm()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
- $this->assertEquals(SubKey::ALGORITHM_ELGAMAL_ENC,
- $subKey->getAlgorithm());
+ $this->assertEquals(
+ SubKey::ALGORITHM_ELGAMAL_ENC,
+ $subKey->getAlgorithm()
+ );
}
/**
@@ -247,11 +216,13 @@ public function testGetFingerprint()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
- $this->assertEquals('8D2299D9C5C211128B32BBB0C097D9EC94C06363',
- $subKey->getFingerprint());
+ $this->assertEquals(
+ '8D2299D9C5C211128B32BBB0C097D9EC94C06363',
+ $subKey->getFingerprint()
+ );
}
/**
@@ -268,7 +239,7 @@ public function testGetLength()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertEquals(2048, $subKey->getLength());
@@ -288,7 +259,7 @@ public function testGetCreationDate()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertEquals(1221785858, $subKey->getCreationDate());
@@ -308,7 +279,7 @@ public function testGetCreationDateTime()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertSame('2008-09-19T00:57:38+00:00', $subKey->getCreationDateTime()->format('c'));
@@ -322,7 +293,7 @@ public function testGetCreationDateTime()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertSame(null, $subKey->getCreationDateTime());
@@ -342,7 +313,7 @@ public function testGetExpirationDate()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertEquals(1421785858, $subKey->getExpirationDate());
@@ -362,7 +333,7 @@ public function testGetExpirationDateTime()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertSame('2015-01-20T20:30:58+00:00', $subKey->getExpirationDateTime()->format('c'));
@@ -376,7 +347,7 @@ public function testGetExpirationDateTime()
'expiration' => 0,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertSame(null, $subKey->getExpirationDateTime());
@@ -396,7 +367,7 @@ public function testCanSign()
'expiration' => 1421785858,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertTrue($subKey->canSign());
@@ -410,7 +381,7 @@ public function testCanSign()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertFalse($subKey->canSign());
@@ -430,7 +401,7 @@ public function testCanEncrypt()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertTrue($subKey->canEncrypt());
@@ -444,7 +415,7 @@ public function testCanEncrypt()
'expiration' => 1421785858,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertFalse($subKey->canEncrypt());
@@ -465,7 +436,7 @@ public function testUsage()
'creation' => 1221785858,
'expiration' => 1421785858,
'usage' => $usage,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertSame($usage, $subKey->usage());
@@ -479,7 +450,7 @@ public function testUsage()
'expiration' => 1421785858,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertSame(SubKey::USAGE_SIGN, $subKey->usage());
@@ -499,7 +470,7 @@ public function testHasPrivate()
'expiration' => 1421785858,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$this->assertTrue($subKey->hasPrivate());
@@ -513,7 +484,7 @@ public function testHasPrivate()
'expiration' => 1421785858,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => false
+ 'hasPrivate' => false,
]);
$this->assertFalse($subKey->hasPrivate());
@@ -534,7 +505,7 @@ public function testIsRevoked()
'canSign' => true,
'canEncrypt' => false,
'hasPrivate' => true,
- 'isRevoked' => true
+ 'isRevoked' => true,
]);
$this->assertTrue($subKey->isRevoked());
@@ -549,7 +520,7 @@ public function testIsRevoked()
'canSign' => true,
'canEncrypt' => false,
'hasPrivate' => false,
- 'isRevoked' => false
+ 'isRevoked' => false,
]);
$this->assertFalse($subKey->isRevoked());
@@ -569,7 +540,7 @@ public function testSetId()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey = new SubKey([
@@ -581,7 +552,7 @@ public function testSetId()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey->setId('8C37DBD2A01B7976');
@@ -603,7 +574,7 @@ public function testSetAlgorithm()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey = new SubKey([
@@ -615,7 +586,7 @@ public function testSetAlgorithm()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey->setAlgorithm(SubKey::ALGORITHM_ELGAMAL_ENC);
@@ -637,7 +608,7 @@ public function testSetFingerprint()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey = new SubKey([
@@ -649,7 +620,7 @@ public function testSetFingerprint()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey->setFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
@@ -671,7 +642,7 @@ public function testSetLength()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey = new SubKey([
@@ -683,7 +654,7 @@ public function testSetLength()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey->setLength(2048);
@@ -705,7 +676,7 @@ public function testSetCreationDate()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey = new SubKey([
@@ -717,7 +688,7 @@ public function testSetCreationDate()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey->setCreationDate(1221785858);
@@ -739,7 +710,7 @@ public function testSetExpirationDate()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey = new SubKey([
@@ -751,7 +722,7 @@ public function testSetExpirationDate()
'expiration' => 1111111111,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey->setExpirationDate(1421785858);
@@ -773,7 +744,7 @@ public function testSetCanSign()
'expiration' => 1421785858,
'canSign' => true,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey = new SubKey([
@@ -785,7 +756,7 @@ public function testSetCanSign()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey->setCanSign(true);
@@ -807,7 +778,7 @@ public function testSetCanEncrypt()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => true,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey = new SubKey([
@@ -819,7 +790,7 @@ public function testSetCanEncrypt()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey->setCanEncrypt(true);
@@ -841,7 +812,7 @@ public function testSetHasPrivate()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => false,
- 'hasPrivate' => true
+ 'hasPrivate' => true,
]);
$subKey = new SubKey([
@@ -853,7 +824,7 @@ public function testSetHasPrivate()
'expiration' => 1421785858,
'canSign' => false,
'canEncrypt' => false,
- 'hasPrivate' => false
+ 'hasPrivate' => false,
]);
$subKey->setHasPrivate(true);
@@ -876,7 +847,7 @@ public function testSetRevoked()
'canSign' => false,
'canEncrypt' => false,
'hasPrivate' => false,
- 'isRevoked' => true
+ 'isRevoked' => true,
]);
$subKey = new SubKey([
@@ -889,7 +860,7 @@ public function testSetRevoked()
'canSign' => false,
'canEncrypt' => false,
'hasPrivate' => false,
- 'isRevoked' => false
+ 'isRevoked' => false,
]);
$subKey->setRevoked(true);
@@ -925,8 +896,8 @@ public function testFluentInterface()
$this->assertEquals(
$subKey,
$returnedSubKey,
- 'Failed asserting fluent interface works for setFingerprint() ' .
- 'method.'
+ 'Failed asserting fluent interface works for setFingerprint() '
+ . 'method.'
);
$subKey = new SubKey();
@@ -942,8 +913,8 @@ public function testFluentInterface()
$this->assertEquals(
$subKey,
$returnedSubKey,
- 'Failed asserting fluent interface works for setCreationDate() ' .
- 'method.'
+ 'Failed asserting fluent interface works for setCreationDate() '
+ . 'method.'
);
$subKey = new SubKey();
@@ -951,8 +922,8 @@ public function testFluentInterface()
$this->assertEquals(
$subKey,
$returnedSubKey,
- 'Failed asserting fluent interface works for setExpirationDate() ' .
- 'method.'
+ 'Failed asserting fluent interface works for setExpirationDate() '
+ . 'method.'
);
$subKey = new SubKey();
@@ -968,8 +939,8 @@ public function testFluentInterface()
$this->assertEquals(
$subKey,
$returnedSubKey,
- 'Failed asserting fluent interface works for setCanEncrypt() ' .
- 'method.'
+ 'Failed asserting fluent interface works for setCanEncrypt() '
+ . 'method.'
);
$subKey = new SubKey();
@@ -977,8 +948,8 @@ public function testFluentInterface()
$this->assertEquals(
$subKey,
$returnedSubKey,
- 'Failed asserting fluent interface works for setHasPrivate() ' .
- 'method.'
+ 'Failed asserting fluent interface works for setHasPrivate() '
+ . 'method.'
);
$subKey = new SubKey();
diff --git a/tests/TestCase.php b/tests/TestCase.php
index cfc5e63..b74c212 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -2,38 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * PHPUnit AllTests suite for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2013 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG;
@@ -64,12 +32,19 @@
* 6) multiple-subkeys@example.com - passphrases 'test1' and 'test2'
* A public-private key pair that has multiple encrypting subkeys. The
* first subkey is an ELG-E key. The second is an RSA key.
+ *
+ * @category Encryption
+ * @package Crypt_GPG
+ * @author Michael Gauthier
+ * @copyright 2005-2013 silverorange
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
- const HOMEDIR = 'test-keychain';
- const TEMPDIR = 'temp-files';
- const DATADIR = 'data-files';
+ public const HOMEDIR = 'test-keychain';
+ public const TEMPDIR = 'temp-files';
+ public const DATADIR = 'data-files';
protected $config;
protected $gpg;
@@ -137,373 +112,373 @@ private function _setUpKeyring()
{
// {{{ pubring data
$pubringData = <<getKeyringFilename('private-keys-v1.d'),
- $this->getKeyringFilename('openpgp-revocs.d')
+ $this->getKeyringFilename('openpgp-revocs.d'),
];
foreach ($dirnames as $dirname) {
@@ -611,12 +586,12 @@ protected function getMd5Sum($filename)
protected function getKeyringFilename($filename)
{
- return __DIR__ . '/'. self::HOMEDIR . '/' . $filename;
+ return __DIR__ . '/' . self::HOMEDIR . '/' . $filename;
}
protected function getDataFilename($filename)
{
- return __DIR__ . '/'. self::DATADIR . '/' . $filename;
+ return __DIR__ . '/' . self::DATADIR . '/' . $filename;
}
protected function getTempFilename($filename)
@@ -659,7 +634,7 @@ protected function assertDecryptAndVerifyResultsEquals(array $expected, array $a
if ($csf && (substr($actual['data'], -1) != "\n")) {
// see discussion around GnuPG's handling of trailing
// newlines in CSF messages at https://dev.gnupg.org/T7106
- $actual['data'] = $actual['data']."\n";
+ $actual['data'] = $actual['data'] . "\n";
}
$this->assertEquals(
$expected['data'],
@@ -691,7 +666,9 @@ protected function assertSignatureEquals(Signature $expected, Signature $actual)
$expectedUserId = $expected->getUserId();
$actualUserId = $actual->getUserId();
- $this->assertEquals($expectedUserId, $actualUserId,
+ $this->assertEquals(
+ $expectedUserId,
+ $actualUserId,
'Signature user ids do not match.'
);
diff --git a/tests/UserIdTest.php b/tests/UserIdTest.php
index 252d218..d6f627c 100644
--- a/tests/UserIdTest.php
+++ b/tests/UserIdTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * User id class test cases for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit UserIdTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -51,8 +14,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2008-2010 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class UserIdTest extends TestCase
{
@@ -62,9 +25,9 @@ class UserIdTest extends TestCase
public function testConstructFromString()
{
$expectedUserId = new UserId([
- 'name' => 'Example User',
- 'comment' => 'This is a test comment',
- 'email' => 'test@example.com'
+ 'name' => 'Example User',
+ 'comment' => 'This is a test comment',
+ 'email' => 'test@example.com',
]);
$string = 'Example User (This is a test comment) ';
@@ -79,11 +42,11 @@ public function testConstructFromString()
public function testConstructFromUserId()
{
$expectedUserId = new UserId([
- 'name' => 'Example User',
- 'comment' => 'This is a test comment',
- 'email' => 'test@example.com',
- 'revoked' => true,
- 'valid' => false
+ 'name' => 'Example User',
+ 'comment' => 'This is a test comment',
+ 'email' => 'test@example.com',
+ 'revoked' => true,
+ 'valid' => false,
]);
$userId = new UserId($expectedUserId);
@@ -102,7 +65,7 @@ public function testConstructFromArray()
'comment' => 'This is a test comment',
'email' => 'test@example.com',
'revoked' => true,
- 'valid' => false
+ 'valid' => false,
]
);
@@ -123,7 +86,7 @@ public function testParseFull()
[
'name' => 'Example User',
'comment' => 'This is a test comment',
- 'email' => 'test@example.com'
+ 'email' => 'test@example.com',
]
);
@@ -154,7 +117,7 @@ public function testParseNameComment()
$expectedUserId = new UserId(
[
'name' => 'Example User',
- 'comment' => 'This is a test comment'
+ 'comment' => 'This is a test comment',
]
);
@@ -172,7 +135,7 @@ public function testParseNameEmail()
$expectedUserId = new UserId(
[
'name' => 'Example User',
- 'email' => 'test@example.com'
+ 'email' => 'test@example.com',
]
);
@@ -190,7 +153,7 @@ public function testParseEmailOnly()
$expectedUserId = new UserId(
[
'name' => '',
- 'email' => 'test@example.com'
+ 'email' => 'test@example.com',
]
);
@@ -216,7 +179,7 @@ public function testToStringFull()
[
'name' => 'Example User',
'comment' => 'This is a test comment',
- 'email' => 'test@example.com'
+ 'email' => 'test@example.com',
]
);
@@ -262,7 +225,7 @@ public function testToStringNameEmail()
$userId = new UserId(
[
'name' => 'Example User',
- 'email' => 'test@example.com'
+ 'email' => 'test@example.com',
]
);
@@ -276,7 +239,7 @@ public function testGetName()
{
$userId = new UserId(
[
- 'name' => 'Example User'
+ 'name' => 'Example User',
]
);
@@ -291,7 +254,7 @@ public function testGetComment()
$userId = new UserId(
[
'name' => 'Example User',
- 'comment' => 'This is a test comment'
+ 'comment' => 'This is a test comment',
]
);
@@ -306,7 +269,7 @@ public function testGetEmail()
$userId = new UserId(
[
'name' => 'Example User',
- 'email' => 'test@example.com'
+ 'email' => 'test@example.com',
]
);
@@ -382,14 +345,14 @@ public function testSetComment()
$expectedUserId = new UserId(
[
'name' => 'Example User',
- 'comment' => 'Second comment text'
+ 'comment' => 'Second comment text',
]
);
$userId = new UserId(
[
'name' => 'Example User',
- 'comment' => 'First comment text'
+ 'comment' => 'First comment text',
]
);
@@ -406,14 +369,14 @@ public function testSetEmail()
$expectedUserId = new UserId(
[
'name' => 'Example User',
- 'email' => 'second@example.com'
+ 'email' => 'second@example.com',
]
);
$userId = new UserId(
[
'name' => 'Example User',
- 'email' => 'first@example.com'
+ 'email' => 'first@example.com',
]
);
diff --git a/tests/VerifyTest.php b/tests/VerifyTest.php
index 19c3c7d..4448bf2 100644
--- a/tests/VerifyTest.php
+++ b/tests/VerifyTest.php
@@ -2,43 +2,6 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-/**
- * Verify tests for the Crypt_GPG package.
- *
- * These tests require the PHPUnit 3.6 or greater package to be installed.
- * PHPUnit is installable using PEAR. See the
- * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual}
- * for detailed installation instructions.
- *
- * To run these tests, use:
- *
- * $ phpunit VerifyTestCase
- *
- *
- * 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, see
- *
- *
- * @category Encryption
- * @package Crypt_GPG
- * @author Michael Gauthier
- * @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
- */
-
namespace Crypt\GPG\Tests;
use Crypt\GPG\Exceptions;
@@ -52,8 +15,8 @@
* @package Crypt_GPG
* @author Michael Gauthier
* @copyright 2005-2008 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
class VerifyTest extends TestCase
{
@@ -89,15 +52,15 @@ public function testVerifyKeyNotFoundException()
$data = 'Hello, Alice! Goodbye, Bob!';
// {{{ detached signature
$detachedSignature = <<gpg->verify($data, $detachedSignature);
}
@@ -125,16 +88,16 @@ public function testVerifyNormalSignedData()
// }}}
// {{{ normal signed data
$normalSignedData = <<
* @copyright 2011 silverorange
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://pear.php.net/package/Crypt_GPG
+ * @license https://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @link https://github.com/pear/Crypt_GPG
*/
$GLOBALS['Crypt_GPG_Unittest_Config'] = [
diff --git a/tools/build-keyring.php b/tools/build-keyring.php
index e32fa62..10f383e 100644
--- a/tools/build-keyring.php
+++ b/tools/build-keyring.php
@@ -16,13 +16,13 @@
'pubring' => 'pubring.gpg',
'secring' => 'secring.gpg',
'trustdb' => 'trustdb.gpg',
- 'random_seed' => 'random_seed'
+ 'random_seed' => 'random_seed',
];
$keyFiles = [
'expectedKeyData' => 'public-only-pub.asc',
'privateKeyData' => 'public-only-sec.asc',
- 'publicKeyData' => 'external-public-pub.asc'
+ 'publicKeyData' => 'external-public-pub.asc',
];
$signatureFiles = [
@@ -31,7 +31,7 @@
'detachedSignature' => 'detached-signature.asc',
'dualNormalSignedData' => 'dual-normal-signed-data.asc',
'dualClearsignedData' => 'dual-clearsigned-data.asc',
- 'dualDetachedSignature' => 'dual-detached-signature.asc'
+ 'dualDetachedSignature' => 'dual-detached-signature.asc',
];
$encryptedFiles = [
@@ -39,7 +39,7 @@
'encryptedDataNoPassphrase' => 'encrypted-data-no-passphrase.asc',
'encryptedDataMissingKey' => 'encrypted-data-missing-key.asc',
'dualEncryptedData' => 'dual-encrypted-data.asc',
- 'dualEncryptedDataOnePassphrase' => 'dual-encrypted-data-one-passphrase.asc'
+ 'dualEncryptedDataOnePassphrase' => 'dual-encrypted-data-one-passphrase.asc',
];
echo "\n// For TestCase\n";
diff --git a/tools/dump-keyring.php b/tools/dump-keyring.php
index 7035147..fbb671d 100644
--- a/tools/dump-keyring.php
+++ b/tools/dump-keyring.php
@@ -16,7 +16,7 @@
'pubring' => 'pubring.gpg',
'secring' => 'secring.gpg',
'trustdb' => 'trustdb.gpg',
- 'random_seed' => 'random_seed'
+ 'random_seed' => 'random_seed',
];