Skip to content

Commit

Permalink
Merge 70c29f3 into 17c99de
Browse files Browse the repository at this point in the history
  • Loading branch information
svycka committed Oct 23, 2020
2 parents 17c99de + 70c29f3 commit 1a27b96
Show file tree
Hide file tree
Showing 45 changed files with 158 additions and 129 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/laminas-mkdoc-theme/
/phpunit.xml
/vendor/
.phpunit.result.cache
27 changes: 9 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,35 @@ cache:

env:
global:
- COMPOSER_ARGS="--no-interaction"
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"
- COVERAGE_DEPS="php-coveralls/php-coveralls"

matrix:
fast_finish: true
include:
- php: 5.6
- php: 7.3
env:
- DEPS=lowest
- REMOVE_DEV_DEPS="psr/http-factory"
- php: 5.6
- php: 7.3
env:
- DEPS=latest
- REMOVE_DEV_DEPS="psr/http-factory"
- php: 7
env:
- DEPS=lowest
- php: 7
env:
- DEPS=latest
- php: 7.1
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.4
env:
- DEPS=lowest
- php: 7.1
- php: 7.4
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
- php: nightly
env:
- DEPS=lowest
- php: 7.2
- php: nightly
env:
- DEPS=latest

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- if [[ $REMOVE_DEV_DEPS != '' ]]; then travis_retry composer remove $COMPOSER_ARGS --dev --no-update $REMOVE_DEV_DEPS ; fi

install:
- travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@
}
},
"require": {
"php": "^5.6 || ^7.0",
"laminas/laminas-stdlib": "^2.7.7 || ^3.1",
"php": "^7.3 || ~8.0.0",
"laminas/laminas-stdlib": "^3.3",
"laminas/laminas-zendframework-bridge": "^1.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "~1.0.0",
"laminas/laminas-crypt": "^3.2.1",
"laminas/laminas-servicemanager": "^2.7.8 || ^3.3",
"laminas/laminas-servicemanager": "^3.3",
"laminas/laminas-uri": "^2.6",
"pear/archive_tar": "^1.4.3",
"phpunit/phpunit": "^5.7.23 || ^6.4.3",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3",
"psr/http-factory": "^1.0"
},
"conflict": {
Expand Down
32 changes: 25 additions & 7 deletions src/Encrypt/Openssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected function _setKeys($keys)
throw new Exception\InvalidArgumentException("Public key '{$cert}' not valid");
}

openssl_free_key($test);
$this->freeKeyResource($test);
$this->keys['public'][$key] = $cert;
break;
case 'private':
Expand All @@ -140,7 +140,7 @@ protected function _setKeys($keys)
throw new Exception\InvalidArgumentException("Private key '{$cert}' not valid");
}

openssl_free_key($test);
$this->freeKeyResource($test);
$this->keys['private'][$key] = $cert;
break;
case 'envelope':
Expand Down Expand Up @@ -364,11 +364,17 @@ public function encrypt($value)
$value = $compress($value);
}

$crypt = openssl_seal($value, $encrypted, $encryptedkeys, $keys);
foreach ($keys as $key) {
openssl_free_key($key);
$crypt = openssl_seal($value, $encrypted, $encryptedkeys, $keys, 'RC4');


// PHP 8 automatically frees the key instance and deprecates the function
if (PHP_VERSION_ID < 80000) {
foreach ($keys as $key) {
openssl_free_key($key);
}
}


if ($crypt === false) {
throw new Exception\RuntimeException('Openssl was not able to encrypt your content with the given options');
}
Expand Down Expand Up @@ -439,8 +445,9 @@ public function decrypt($value)
$value = substr($value, $length);
}

$crypt = openssl_open($value, $decrypted, $envelope, $keys);
openssl_free_key($keys);
$crypt = openssl_open($value, $decrypted, $envelope, $keys, 'RC4');

$this->freeKeyResource($keys);

if ($crypt === false) {
throw new Exception\RuntimeException('Openssl was not able to decrypt you content with the given options');
Expand All @@ -464,4 +471,15 @@ public function toString()
{
return 'Openssl';
}

/**
* Free key resource if necessary.
* PHP 8 automatically frees the key instance and deprecates the function
*/
private function freeKeyResource($keys): void
{
if (PHP_VERSION_ID < 80000) {
openssl_free_key($keys);
}
}
}
4 changes: 2 additions & 2 deletions test/Compress/Bz2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Bz2Test extends TestCase
{
public $target;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('bz2')) {
$this->markTestSkipped('This adapter needs the bz2 extension');
Expand All @@ -25,7 +25,7 @@ public function setUp()
$this->target = sprintf('%s/%s.bz2', sys_get_temp_dir(), uniqid('laminasilter'));
}

public function tearDown()
public function tearDown(): void
{
if (file_exists($this->target)) {
unlink($this->target);
Expand Down
4 changes: 2 additions & 2 deletions test/Compress/GzTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GzTest extends TestCase
{
public $target;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('zlib')) {
$this->markTestSkipped('This adapter needs the zlib extension');
Expand All @@ -25,7 +25,7 @@ public function setUp()
$this->target = sprintf('%s/%s.gz', sys_get_temp_dir(), uniqid('laminasilter'));
}

public function tearDown()
public function tearDown(): void
{
if (file_exists($this->target)) {
unlink($this->target);
Expand Down
2 changes: 1 addition & 1 deletion test/Compress/LzfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class LlaminasTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('llaminas')) {
$this->markTestSkipped('This adapter needs the llaminas extension');
Expand Down
4 changes: 2 additions & 2 deletions test/Compress/RarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RarTest extends TestCase
{
public $tmp;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('rar')) {
$this->markTestSkipped('This adapter needs the rar extension');
Expand Down Expand Up @@ -48,7 +48,7 @@ public function setUp()
}
}

public function tearDown()
public function tearDown(): void
{
$files = [
$this->tmp . '/zipextracted.txt',
Expand Down
2 changes: 1 addition & 1 deletion test/Compress/SnappyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class SnappyTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('snappy')) {
$this->markTestSkipped('This adapter needs the snappy extension');
Expand Down
4 changes: 2 additions & 2 deletions test/Compress/TarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class TarTest extends TestCase
{
public $tmp;

public function setUp()
public function setUp(): void
{
$this->tmp = sprintf('%s/%s', sys_get_temp_dir(), uniqid('laminasilter'));
mkdir($this->tmp, 0775, true);
}

public function tearDown()
public function tearDown(): void
{
$files = [
$this->tmp . '/zipextracted.txt',
Expand Down
4 changes: 2 additions & 2 deletions test/Compress/ZipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class ZipTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('zip')) {
$this->markTestSkipped('This adapter needs the zip extension');
Expand Down Expand Up @@ -54,7 +54,7 @@ public function setUp()
}
}

public function tearDown()
public function tearDown(): void
{
$files = [
$this->tmp . '/compressed.zip',
Expand Down
4 changes: 2 additions & 2 deletions test/CompressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CompressTest extends TestCase
{
public $tmpDir;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('bz2')) {
$this->markTestSkipped('This filter is tested with the bz2 extension');
Expand All @@ -26,7 +26,7 @@ public function setUp()
mkdir($this->tmpDir, 0775, true);
}

public function tearDown()
public function tearDown(): void
{
if (is_dir($this->tmpDir)) {
if (file_exists($this->tmpDir . '/compressed.bz2')) {
Expand Down
4 changes: 1 addition & 3 deletions test/DateSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ public function provideFilter()
];
}

/**
* @expectedException \Laminas\Filter\Exception\RuntimeException
*/
public function testInvalidInput()
{
$this->expectException(\Laminas\Filter\Exception\RuntimeException::class);
$sut = new DateSelectFilter();
$sut->filter(['year' => '2120', 'month' => '07']);
}
Expand Down
4 changes: 2 additions & 2 deletions test/DateTimeFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class DateTimeFormatterTest extends TestCase
{
protected $defaultTimezone;

public function setUp()
public function setUp(): void
{
$this->defaultTimezone = date_default_timezone_get();
}

public function tearDown()
public function tearDown(): void
{
date_default_timezone_set($this->defaultTimezone);
}
Expand Down
4 changes: 1 addition & 3 deletions test/DateTimeSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ public function provideFilter()
];
}

/**
* @expectedException \Laminas\Filter\Exception\RuntimeException
*/
public function testInvalidInput()
{
$this->expectException(\Laminas\Filter\Exception\RuntimeException::class);
$sut = new DateTimeSelectFilter();
$sut->filter(['year' => '2120', 'month' => '10', 'day' => '26', 'hour' => '12']);
}
Expand Down
4 changes: 2 additions & 2 deletions test/DecompressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DecompressTest extends TestCase
{
public $tmpDir;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('bz2')) {
$this->markTestSkipped('This filter is tested with the bz2 extension');
Expand All @@ -25,7 +25,7 @@ public function setUp()
mkdir($this->tmpDir, 0775, true);
}

public function tearDown()
public function tearDown(): void
{
if (is_dir($this->tmpDir)) {
if (file_exists($this->tmpDir . '/compressed.bz2')) {
Expand Down
2 changes: 1 addition & 1 deletion test/DecryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class DecryptTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('mcrypt') && ! extension_loaded('openssl')) {
$this->markTestSkipped('This filter needs the mcrypt or openssl extension');
Expand Down
2 changes: 1 addition & 1 deletion test/DigitsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DigitsTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
if (null === static::$_unicodeEnabled) {
static::$_unicodeEnabled = (bool) @preg_match('/\pL/u', 'a');
Expand Down
8 changes: 4 additions & 4 deletions test/Encrypt/BlockCipherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class BlockCipherTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('mcrypt') && ! extension_loaded('openssl')) {
$this->markTestSkipped('This filter needs the mcrypt or openssl extension');
Expand Down Expand Up @@ -163,20 +163,20 @@ public function testSettingEncryptionOptions()
$filter->setEncryption(1234);
$filter->fail();
} catch (\Laminas\Filter\Exception\InvalidArgumentException $e) {
$this->assertContains('Invalid options argument', $e->getMessage());
$this->assertStringContainsString('Invalid options argument', $e->getMessage());
}

try {
$filter->setEncryption(['algorithm' => 'unknown']);
$filter->fail();
} catch (\Laminas\Filter\Exception\InvalidArgumentException $e) {
$this->assertContains('The algorithm', $e->getMessage());
$this->assertStringContainsString('The algorithm', $e->getMessage());
}

try {
$filter->setEncryption(['mode' => 'unknown']);
} catch (\Laminas\Filter\Exception\InvalidArgumentException $e) {
$this->assertContains('The mode', $e->getMessage());
$this->assertStringContainsString('The mode', $e->getMessage());
}
}

Expand Down

0 comments on commit 1a27b96

Please sign in to comment.