diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5b9b4bf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/vendor
+/composer.lock
+/clover.xml
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..facecf3
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,51 @@
+language: php
+
+sudo: false
+
+php:
+ - 7
+ - 7.1
+ - 7.2
+ - nightly
+
+env: TMPDIR=/tmp USE_XDEBUG=false
+
+branches:
+ only:
+ master
+
+before_install:
+ - travis_retry composer self-update
+
+install:
+ - phpenv rehash
+ - travis_retry composer install --no-interaction --prefer-source
+
+stages:
+ - test
+ - phpstan analysis
+ - test with coverage
+
+before_script:
+ - if [[ "$USE_XDEBUG" == false ]]; then phpenv config-rm xdebug.ini || return 0; fi
+
+script:
+ - composer test
+
+jobs:
+ fast_finish: true
+ allow_failures:
+ - php: nightly
+ include:
+ - stage: phpstan analysis
+ php: 7.1
+ env: TMPDIR=/tmp USE_XDEBUG=false
+ script:
+ - composer phpstan
+ - stage: test with coverage
+ php: 7.1
+ env: TMPDIR=/tmp USE_XDEBUG=true
+ script:
+ - composer test-with-coverage
+ after_success:
+ - bash <(curl -s https://codecov.io/bash) -f ./clover.xml
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..6eab5aa
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,27 @@
+Copyright (c) 2005-2015, Zend Technologies USA, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name of Zend Technologies USA, Inc. nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1c12c36
--- /dev/null
+++ b/README.md
@@ -0,0 +1,9 @@
+Zend Framework 1 - Crypt
+============================
+[](https://travis-ci.org/diablomedia/zf1-crypt)
+[](https://codecov.io/gh/diablomedia/zf1-crypt)
+[](https://packagist.org/packages/diablomedia/zendframework1-crypt)
+[](https://packagist.org/packages/diablomedia/zendframework1-crypt)
+[](https://packagist.org/packages/diablomedia/zendframework1-crypt)
+
+This is just the Zend_Crypt component extracted from our fork of the Zend Framework 1 repo (https://github.com/diablomedia/zf1).
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..de656a8
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,47 @@
+{
+ "name": "diablomedia/zendframework1-crypt",
+ "description": "Zend Framework 1 Crypt component",
+ "type": "library",
+ "keywords": [
+ "framework",
+ "zf1"
+ ],
+ "homepage": "http://framework.zend.com/",
+ "license": "BSD-3-Clause",
+ "minimum-stability": "dev",
+ "prefer-stable": true,
+ "require": {
+ "php": ">=7.0.0",
+ "diablomedia/zendframework1-exception": "^1.0.0"
+ },
+ "autoload": {
+ "psr-0": {
+ "Zend_": "src/"
+ }
+ },
+ "autoload-dev": {
+ "psr-0": {
+ "Zend_": "tests/"
+ }
+ },
+ "repositories": [
+ {
+ "type": "vcs",
+ "no-api": true,
+ "url": "https://github.com/diablomedia/phpstorm-stubs"
+ }
+ ],
+ "require-dev": {
+ "phpunit/phpunit": "^6.0",
+ "phpstan/phpstan": "^0.9.2",
+ "jetbrains/phpstorm-stubs": "dev-phpstan"
+ },
+ "archive": {
+ "exclude": ["/tests"]
+ },
+ "scripts": {
+ "test": "phpunit ./tests",
+ "test-with-coverage": "phpunit --coverage-clover=clover.xml ./tests",
+ "phpstan": "phpstan analyze -l7 -c phpstan.neon --no-progress ./src --ansi"
+ }
+}
diff --git a/phpstan-bootstrap.php b/phpstan-bootstrap.php
new file mode 100644
index 0000000..b904fcb
--- /dev/null
+++ b/phpstan-bootstrap.php
@@ -0,0 +1,27 @@
+
+
+
+ ./src
+
+
+
diff --git a/src/Zend/Crypt/Hmac.php b/src/Zend/Crypt/Hmac.php
index 4a0cd19..332b7bd 100644
--- a/src/Zend/Crypt/Hmac.php
+++ b/src/Zend/Crypt/Hmac.php
@@ -164,6 +164,8 @@ protected static function _hash($data, $output = self::STRING, $internal = false
*/
protected static function _getMhashDefinition($hashAlgorithm)
{
+ $types = array();
+
for ($i = 0; $i <= mhash_count(); $i++)
{
$types[mhash_get_hash_name($i)] = $i;
diff --git a/src/Zend/Crypt/Math/BigInteger.php b/src/Zend/Crypt/Math/BigInteger.php
index 1117df7..d34c3ac 100644
--- a/src/Zend/Crypt/Math/BigInteger.php
+++ b/src/Zend/Crypt/Math/BigInteger.php
@@ -40,6 +40,21 @@
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
+ *
+ * From Zend_Crypt_Math_BigInteger_Interface
+ * @method mixed init($operand, $base = 10)
+ * @method mixed add($left_operand, $right_operand)
+ * @method mixed subtract($left_operand, $right_operand)
+ * @method mixed compare($left_operand, $right_operand)
+ * @method mixed divide($left_operand, $right_operand)
+ * @method mixed modulus($left_operand, $modulus)
+ * @method mixed multiply($left_operand, $right_operand)
+ * @method mixed pow($left_operand, $right_operand)
+ * @method mixed powmod($left_operand, $right_operand, $modulus)
+ * @method mixed sqrt($operand)
+ * @method mixed binaryToInteger($operand)
+ * @method mixed integerToBinary($operand)
+ * @method mixed hexToDecimal($operand)
*/
class Zend_Crypt_Math_BigInteger
{
diff --git a/tests/Zend/Crypt/DiffieHellmanTest.php b/tests/Zend/Crypt/DiffieHellmanTest.php
index 2f05e68..d1a0b6d 100644
--- a/tests/Zend/Crypt/DiffieHellmanTest.php
+++ b/tests/Zend/Crypt/DiffieHellmanTest.php
@@ -20,8 +20,6 @@
* @version $Id$
*/
-require_once 'Zend/Crypt/DiffieHellman.php';
-require_once 'Zend/Crypt/Math/BigInteger.php';
/**
* @category Zend
diff --git a/tests/Zend/Crypt/HmacTest.php b/tests/Zend/Crypt/HmacTest.php
index 0cbf87a..3c0bffb 100644
--- a/tests/Zend/Crypt/HmacTest.php
+++ b/tests/Zend/Crypt/HmacTest.php
@@ -20,7 +20,6 @@
* @version $Id$
*/
-require_once 'Zend/Crypt/Hmac.php';
/**
* Outside the Internal Function tests, tests do not distinguish between hash and mhash
diff --git a/tests/Zend/Crypt/Math/BigInteger/BcmathTest.php b/tests/Zend/Crypt/Math/BigInteger/BcmathTest.php
index d3ae1de..a798ae5 100644
--- a/tests/Zend/Crypt/Math/BigInteger/BcmathTest.php
+++ b/tests/Zend/Crypt/Math/BigInteger/BcmathTest.php
@@ -20,7 +20,6 @@
* @version $Id$
*/
-require_once 'Zend/Crypt/Math/BigInteger/Bcmath.php';
/**
* @category Zend
diff --git a/tests/Zend/Crypt/Math/BigInteger/GmpTest.php b/tests/Zend/Crypt/Math/BigInteger/GmpTest.php
index c95e74a..fb9b20d 100644
--- a/tests/Zend/Crypt/Math/BigInteger/GmpTest.php
+++ b/tests/Zend/Crypt/Math/BigInteger/GmpTest.php
@@ -20,10 +20,6 @@
* @version $Id$
*/
-require_once 'Zend/Crypt/Math/BigInteger/Gmp.php';
-
-require_once 'Zend/Crypt/Math/BigInteger/Bcmath.php';
-
/**
* @category Zend
diff --git a/tests/Zend/Crypt/MathTest.php b/tests/Zend/Crypt/MathTest.php
index aed1032..51ef9de 100644
--- a/tests/Zend/Crypt/MathTest.php
+++ b/tests/Zend/Crypt/MathTest.php
@@ -20,8 +20,6 @@
* @version $Id$
*/
-require_once 'Zend/Crypt/Math.php';
-require_once 'Zend/Crypt/Exception.php';
/**
* @category Zend
diff --git a/tests/Zend/Crypt/Rsa/RsaTest.php b/tests/Zend/Crypt/RsaTest.php
similarity index 95%
rename from tests/Zend/Crypt/Rsa/RsaTest.php
rename to tests/Zend/Crypt/RsaTest.php
index 3e85f0a..eea9672 100644
--- a/tests/Zend/Crypt/Rsa/RsaTest.php
+++ b/tests/Zend/Crypt/RsaTest.php
@@ -20,8 +20,6 @@
* @version $Id$
*/
-require_once 'Zend/Crypt/Rsa.php';
-
/**
* @category Zend
@@ -43,7 +41,7 @@ public function setUp()
if (!extension_loaded('openssl')) {
$this->markTestSkipped('Zend_Crypt_Rsa requires openssl extension to be loaded.');
}
-
+
$this->_testPemString = <<_testPemPath = dirname(__FILE__) . '/_files/test.pem';
+ $this->_testPemPath = dirname(__FILE__) . '/Rsa/_files/test.pem';
- $this->_testCertificatePath = dirname(__FILE__) . '/_files/test.cert';
+ $this->_testCertificatePath = dirname(__FILE__) . '/Rsa/_files/test.cert';
}
public function testConstructorSetsPemString()
@@ -317,14 +315,14 @@ public function testKeyGenerationCreatesPassphrasedPrivateKey()
'passPhrase' => '0987654321'
);
$keys = $rsa->generateKeys($config);
- try {
- $rsa = new Zend_Crypt_Rsa(array(
- 'passPhrase'=>'1234567890',
- 'pemString'=>$keys->privateKey->toString()
- ));
- $this->fail('Expected exception not thrown');
- } catch (Zend_Crypt_Exception $e) {
- }
+
+ $this->expectException(\Zend_Crypt_Exception::class);
+ $this->expectExceptionMessage('Unable to load public key');
+
+ $rsa = new Zend_Crypt_Rsa(array(
+ 'passPhrase'=>'1234567890',
+ 'pemString'=>$keys->privateKey->toString()
+ ));
}
public function testConstructorLoadsPassphrasedKeys()
@@ -335,7 +333,7 @@ public function testConstructorLoadsPassphrasedKeys()
if (!$test) {
$this->markTestSkipped('Cannot generate a private key with openssl_pkey_new()');
}
-
+
$config = array(
'privateKeyBits' => 512,
'passPhrase' => '0987654321'
@@ -346,6 +344,8 @@ public function testConstructorLoadsPassphrasedKeys()
'passPhrase'=>'0987654321',
'pemString'=>$keys->privateKey->toString()
));
+ // Confirming that an exception isn't thrown
+ $this->assertTrue(true);
} catch (Zend_Crypt_Exception $e) {
$this->fail('Passphrase loading failed of a private key');
}
@@ -358,6 +358,9 @@ public function testLoadsPublicKeyFromPEMWithoutPrivateKeyAndThrowsNoException()
{
$rsa = new Zend_Crypt_Rsa;
$rsa->setPemString($this->_testPemStringPublic);
+
+ // Confirming that an exception isn't thrown
+ $this->assertTrue(true);
}
}