Skip to content

Commit

Permalink
Preparing for standalone component
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydiablo committed Apr 26, 2018
1 parent a4f6a2b commit 0cf4a8b
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
/composer.lock
/clover.xml
51 changes: 51 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Zend Framework 1 - Crypt
============================
[![Build Status](https://travis-ci.org/diablomedia/zf1-crypt.svg?branch=master)](https://travis-ci.org/diablomedia/zf1-crypt)
[![codecov](https://codecov.io/gh/diablomedia/zf1-crypt/branch/master/graph/badge.svg)](https://codecov.io/gh/diablomedia/zf1-crypt)
[![Latest Stable Version](https://poser.pugx.org/diablomedia/zendframework1-crypt/v/stable)](https://packagist.org/packages/diablomedia/zendframework1-crypt)
[![Total Downloads](https://poser.pugx.org/diablomedia/zendframework1-crypt/downloads)](https://packagist.org/packages/diablomedia/zendframework1-crypt)
[![License](https://poser.pugx.org/diablomedia/zendframework1-crypt/license)](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).
47 changes: 47 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
27 changes: 27 additions & 0 deletions phpstan-bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

if (!extension_loaded('gmp')) {
require_once __DIR__ . '/vendor/jetbrains/phpstorm-stubs/gmp/gmp.php';
}

if (!extension_loaded('mcrypt')) {
require_once __DIR__ . '/vendor/jetbrains/phpstorm-stubs/mcrypt/mcrypt.php';
}

if (!extension_loaded('hash')) {
require_once __DIR__ . '/vendor/jetbrains/phpstorm-stubs/hash/hash.php';
}
// The hash extension may emulate the mhash extension if PHP is configured with --with-mhash
// otherwise the mhash* functions/constants won't exist
if (!function_exists('mhash')) {
require_once __DIR__ . '/vendor/jetbrains/phpstorm-stubs/mhash/mhash.php';
}

if (!extension_loaded('openssl')) {
require_once __DIR__ . '/vendor/jetbrains/phpstorm-stubs/openssl/openssl.php';
} else {
// Only defined when php/openssl compiled with MD2 support
if (!defined('OPENSSL_ALGO_MD2')) {
define('OPENSSL_ALGO_MD2', 4);
}
}
23 changes: 23 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
parameters:
bootstrap: %rootDir%/../../../phpstan-bootstrap.php
ignoreErrors:
- '#Casting to .+ something that.s already .+\.#'
# This does only have one parameter, not sure intent here
- '#Class Zend_Crypt_Rsa_Key_Public constructor invoked with 2 parameters, 1 required\.#'
# This should probably be changed to a do/while loop instead of just while, Zend_Crypt_Math_BigInteger_Bcmath:215
- '#Variable \$hex might not be defined\.#'
# Possibly issues with stubs, haven't researched
- '#Parameter \#1 \$gmpnumber of function gmp_strval expects resource\|string, GMP given\.#'
- '#Parameter \#1 \$gmpnumber of function gmp_strval expects resource\|string, int given\.#'
- '#Parameter \#1 \$a of function gmp_sqrt expects resource\|string, object\|resource\|string given\.#'
- '#Parameter \#2 \$b of function gmp_mul expects resource\|string, int given\.#'
# These methods exist on Zend_Crypt_Math but $_math property is typehinted as Zend_Crypt_Math_BigInteger_Interface
- '#Call to an undefined method Zend_Crypt_Math_BigInteger::fromBinary\(\)\.#'
- '#Call to an undefined method Zend_Crypt_Math_BigInteger::toBinary\(\)\.#'
- '#Call to an undefined method Zend_Crypt_Math_BigInteger::btwoc\(\)\.#'
- '#Call to an undefined method Zend_Crypt_Math_BigInteger::rand\(\)\.#'
# Isset calls probably aren't necessary here, Zend_Crypt_Hmac:89|110
- '#Variable \$key in isset\(\) always exists and is not nullable\.#'
- '#Variable \$hash in isset\(\) always exists and is not nullable\.#'
# Probably unnecessary is_float check, Zend_Crypt_Math:121
- '#Call to function is_float\(\) will always evaluate to false\.#'
14 changes: 14 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<phpunit
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="true"
backupGlobals="true"
stderr="true"
colors="true">
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
2 changes: 2 additions & 0 deletions src/Zend/Crypt/Hmac.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/Zend/Crypt/Math/BigInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Zend/Crypt/DiffieHellmanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* @version $Id$
*/

require_once 'Zend/Crypt/DiffieHellman.php';
require_once 'Zend/Crypt/Math/BigInteger.php';

/**
* @category Zend
Expand Down
1 change: 0 additions & 1 deletion tests/Zend/Crypt/HmacTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/Zend/Crypt/Math/BigInteger/BcmathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* @version $Id$
*/

require_once 'Zend/Crypt/Math/BigInteger/Bcmath.php';

/**
* @category Zend
Expand Down
4 changes: 0 additions & 4 deletions tests/Zend/Crypt/Math/BigInteger/GmpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
* @version $Id$
*/

require_once 'Zend/Crypt/Math/BigInteger/Gmp.php';

require_once 'Zend/Crypt/Math/BigInteger/Bcmath.php';


/**
* @category Zend
Expand Down
2 changes: 0 additions & 2 deletions tests/Zend/Crypt/MathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* @version $Id$
*/

require_once 'Zend/Crypt/Math.php';
require_once 'Zend/Crypt/Exception.php';

/**
* @category Zend
Expand Down
31 changes: 17 additions & 14 deletions tests/Zend/Crypt/Rsa/RsaTest.php → tests/Zend/Crypt/RsaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* @version $Id$
*/

require_once 'Zend/Crypt/Rsa.php';


/**
* @category Zend
Expand All @@ -43,7 +41,7 @@ public function setUp()
if (!extension_loaded('openssl')) {
$this->markTestSkipped('Zend_Crypt_Rsa requires openssl extension to be loaded.');
}

$this->_testPemString = <<<RSAKEY
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBANDiE2+Xi/WnO+s120NiiJhNyIButVu6zxqlVzz0wy2j4kQVUC4Z
Expand Down Expand Up @@ -86,9 +84,9 @@ public function setUp()
CERT;

$this->_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()
Expand Down Expand Up @@ -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()
Expand All @@ -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'
Expand All @@ -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');
}
Expand All @@ -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);
}

}

0 comments on commit 0cf4a8b

Please sign in to comment.